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
28 public class BoxObjectTest extends WebDriverTestCase {
29
30
31
32
33
34 @Test
35 @Alerts("TypeError")
36 public void elementAttributes() throws Exception {
37 final String html = DOCTYPE_HTML
38 + "<html>\n"
39 + " <body onload='test()'>\n"
40 + " <span id='foo'>foo</span><div id='d'><span id='a'>a</span><span id='b'>b</span></div><span id='bar'>bar</span>\n"
41 + " <script>\n"
42 + LOG_TITLE_FUNCTION
43 + " function test() {\n"
44 + " try {\n"
45 + " var div = document.getElementById('d');\n"
46 + " var spanFoo = document.getElementById('foo');\n"
47 + " var spanA = document.getElementById('a');\n"
48 + " var spanB = document.getElementById('b');\n"
49 + " var spanBar = document.getElementById('bar');\n"
50 + " var box = document.getBoxObjectFor(div);\n"
51 + " log(box.element == div);\n"
52 + " log(box.firstChild == spanA);\n"
53 + " log(box.lastChild == spanB);\n"
54 + " log(box.previousSibling == spanFoo);\n"
55 + " log(box.nextSibling == spanBar);\n"
56 + " } catch(e) { logEx(e) }\n"
57 + " }\n"
58 + " </script>\n"
59 + " </body>\n"
60 + "</html>";
61
62 loadPageVerifyTitle2(html);
63 }
64
65
66
67
68
69 @Test
70 @Alerts("TypeError")
71 public void positionAndSizeAttributes() throws Exception {
72 final String html = DOCTYPE_HTML
73 + "<html>\n"
74 + " <body onload='test()'>\n"
75 + " <style>#d { position:absolute; left:50px; top:100px; width:500px; height:400px; border:3px; padding: 5px; margin: 23px; }</style>\n"
76 + " <div id='d'>daniel</div>\n"
77 + " <script>\n"
78 + LOG_TITLE_FUNCTION
79 + " function test() {\n"
80 + " try {\n"
81 + " var div = document.getElementById('d');\n"
82 + " var box = document.getBoxObjectFor(div);\n"
83 + " log(box.x + '-' + box.y);\n"
84 + " log(box.screenX + '-' + box.screenY);\n"
85 + " log(box.width + '-' + box.height);\n"
86 + " } catch(e) { logEx(e) }\n"
87 + " }\n"
88 + " </script>\n"
89 + " </body>\n"
90 + "</html>";
91
92 loadPageVerifyTitle2(html);
93 }
94
95 }