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
27 public class DOMRectTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 @Alerts({"100", "400", "100", "450", "50", "0"})
34 public void properties() throws Exception {
35 final String html = DOCTYPE_HTML
36 + "<html><head>\n"
37 + "<script>\n"
38 + LOG_TITLE_FUNCTION
39 + " function test() {\n"
40 + " try {\n"
41 + " var d1 = document.getElementById('div1');\n"
42 + " var pos = d1.getBoundingClientRect();\n"
43 + " log(pos.top);\n"
44 + " log(pos.left);\n"
45 + " log(pos.bottom);\n"
46 + " log(pos.right);\n"
47 + " log(pos.width);\n"
48 + " log(pos.height);\n"
49 + " } catch(e) { logEx(e);}\n"
50 + " }\n"
51 + "</script></head><body onload='test()'>\n"
52 + "<div id='outer' style='position: absolute; left: 400px; top: 100px; width: 50px; height: 80px;'>\n"
53 + "<div id='div1'></div></div>\n"
54 + "</body></html>";
55 loadPageVerifyTitle2(html);
56 }
57
58
59
60
61 @Test
62 @Alerts({"true", "true"})
63 public void getBoundingClientRect_WidthPercent() throws Exception {
64 final String html = DOCTYPE_HTML
65 + "<html>\n"
66 + "<head>\n"
67 + " <script>\n"
68 + LOG_TITLE_FUNCTION
69 + " function test() {\n"
70 + " var input = document.getElementById('myInput');\n"
71 + " log(input.getBoundingClientRect().height > 10);\n"
72 + " log(input.getBoundingClientRect().width > 100);\n"
73 + " }\n"
74 + " </script>\n"
75 + "</head>\n"
76 + "<body onload='test()'>\n"
77 + "<style>.full { width:100%; }</style>\n"
78 + "<div class='foo bar'>\n"
79 + " <form action='javascript:void(0)' method='post'>\n"
80 + " <div class='full'>\n"
81 + " <input class='full' type='text' id='myInput'>\n"
82 + " </div>\n"
83 + " </form>\n"
84 + "</div>\n"
85 + "</body></html>";
86 loadPageVerifyTitle2(html);
87 }
88 }