1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20
21
22
23
24
25
26 public class DOMRectListTest extends WebDriverTestCase {
27
28
29
30
31 @Test
32 @Alerts({"[object DOMRectList]", "1", "[object DOMRect]", "[object DOMRect]"})
33 public void getClientRects() throws Exception {
34 final String html = DOCTYPE_HTML
35 + "<html><head>\n"
36 + "<script>\n"
37 + LOG_TITLE_FUNCTION
38 + " function test() {\n"
39 + " var d1 = document.getElementById('div1');\n"
40 + " var rects = d1.getClientRects();\n"
41 + " log(rects);\n"
42 + " log(rects.length);\n"
43 + " log(rects[0]);\n"
44 + " log(rects.item(0));\n"
45 + " }\n"
46 + "</script></head>\n"
47 + "<body onload='test()'>\n"
48 + " <div id='div1'/>\n"
49 + "</body></html>";
50 loadPageVerifyTitle2(html);
51 }
52
53
54
55
56 @Test
57 @Alerts({"[object DOMRectList]", "1", "null", "null"})
58 public void itemOutside() throws Exception {
59 final String html = DOCTYPE_HTML
60 + "<html><head>\n"
61 + "<script>\n"
62 + LOG_TITLE_FUNCTION
63 + " function test() {\n"
64 + " var d1 = document.getElementById('div1');\n"
65 + " var rects = d1.getClientRects();\n"
66
67 + " log(rects);\n"
68 + " log(rects.length);\n"
69
70 + " try {\n"
71 + " log(rects.item(1));\n"
72 + " } catch(e) { logEx(e); }\n"
73
74 + " try {\n"
75 + " log(rects.item(-1));\n"
76 + " } catch(e) { logEx(e); }\n"
77 + " }\n"
78 + "</script></head>\n"
79 + "<body onload='test()'>\n"
80 + " <div id='div1'/>\n"
81 + "</body></html>";
82 loadPageVerifyTitle2(html);
83 }
84
85
86
87
88 @Test
89 @Alerts({"[object DOMRectList]", "1", "undefined", "undefined"})
90 public void indexOutside() throws Exception {
91 final String html = DOCTYPE_HTML
92 + "<html><head>\n"
93 + "<script>\n"
94 + LOG_TITLE_FUNCTION
95 + " function test() {\n"
96 + " var d1 = document.getElementById('div1');\n"
97 + " var rects = d1.getClientRects();\n"
98
99 + " log(rects);\n"
100 + " log(rects.length);\n"
101
102 + " try {\n"
103 + " log(rects[1]);\n"
104 + " } catch(e) { logEx(e); }\n"
105
106 + " try {\n"
107 + " log(rects[-1]);\n"
108 + " } catch(e) { logEx(e); }\n"
109 + " }\n"
110 + "</script></head>\n"
111 + "<body onload='test()'>\n"
112 + " <div id='div1'/>\n"
113 + "</body></html>";
114 loadPageVerifyTitle2(html);
115 }
116
117
118
119
120 @Test
121 @Alerts({"[object DOMRectList]", "0", "undefined", "undefined"})
122 public void empty() throws Exception {
123 final String html = DOCTYPE_HTML
124 + "<html><head>\n"
125 + "<script>\n"
126 + LOG_TITLE_FUNCTION
127 + " function test() {\n"
128 + " var d1 = document.createElement('div');\n"
129 + " var rects = d1.getClientRects();\n"
130
131 + " log(rects);\n"
132 + " log(rects.length);\n"
133
134 + " try {\n"
135 + " log(rects[1]);\n"
136 + " } catch(e) { logEx(e); }\n"
137
138 + " try {\n"
139 + " log(rects[-1]);\n"
140 + " } catch(e) { logEx(e); }\n"
141 + " }\n"
142 + "</script></head>\n"
143 + "<body onload='test()'>\n"
144 + " <div id='div1'/>\n"
145 + "</body></html>";
146 loadPageVerifyTitle2(html);
147 }
148 }