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