2 <script src=
"../../../resources/js-test.js"></script>
3 <script src=
"resources/elementsFromPoint.js"></script>
15 <div id=
"blockHost"></div>
16 <span id=
"inlineBlockHost" style=
"display:inline-block;"></span>
17 <input type=
"submit" id=
"submit">
18 <div id=
"console"></div>
20 if (window
.testRunner
)
21 testRunner
.dumpAsText();
23 function createBox() {
24 var div
= document
.createElement('div');
25 div
.style
.width
= '100px';
26 div
.style
.height
= '10px';
30 function centerX(element
) {
31 return element
.offsetLeft
+ element
.offsetWidth
/ 2;
34 function centerY(element
) {
35 return element
.offsetTop
+ element
.offsetHeight
/ 2;
38 var shadowRoot
= host
.createShadowRoot();
39 var box11
= createBox();
40 var box12
= createBox();
41 var box13
= createBox();
42 shadowRoot
.appendChild(box11
);
43 shadowRoot
.appendChild(box12
);
44 shadowRoot
.appendChild(box13
);
46 var nestedHost
= document
.createElement('div');
47 var nestedShadowRoot
= nestedHost
.createShadowRoot();
48 var box21
= createBox();
49 var box22
= createBox();
50 var box23
= createBox();
51 nestedShadowRoot
.appendChild(box21
);
52 nestedShadowRoot
.appendChild(box22
);
53 nestedShadowRoot
.appendChild(box23
);
55 shadowRoot
.appendChild(nestedHost
);
57 var x12
= centerX(box12
);
58 var y12
= centerY(box12
);
59 var x22
= centerX(box22
);
60 var y22
= centerY(box22
);
62 shouldThrow('shadowRoot.elementsFromPoint()');
63 shouldThrow('shadowRoot.elementsFromPoint(0)');
65 assertElementsFromPoint(
66 'shadowRoot.elementsFromPoint(x12, y12)', [box12
]);
67 assertElementsFromPoint(
68 'nestedShadowRoot.elementsFromPoint(x22, y22)', [box22
]);
70 assertElementsFromPoint(
71 'shadowRoot.elementsFromPoint(x22, y22)', [nestedHost
]);
72 assertElementsFromPoint(
73 'document.elementsFromPoint(x22, y22)',
74 [host
, document
.body
, document
.documentElement
]);
76 var root3
= blockHost
.createShadowRoot();
77 root3
.appendChild(document
.createTextNode('text1'));
78 var root4
= inlineBlockHost
.createShadowRoot();
79 root4
.appendChild(document
.createTextNode('text2'));
81 assertElementsFromPoint(
82 'root3.elementsFromPoint(centerX(blockHost), centerY(blockHost))',
84 assertElementsFromPoint(
85 'document.elementsFromPoint(centerX(blockHost), centerY(blockHost))',
86 [blockHost
, document
.body
, document
.documentElement
]);
87 assertElementsFromPoint(
88 'root4.elementsFromPoint(centerX(inlineBlockHost), centerY(inlineBlockHost))',
90 assertElementsFromPoint(
91 'document.elementsFromPoint(centerX(inlineBlockHost), centerY(inlineBlockHost))',
92 [inlineBlockHost
, document
.body
, document
.documentElement
]);
93 assertElementsFromPoint(
94 'document.elementsFromPoint(centerX(submit), centerY(submit))',
95 [submit
, document
.body
, document
.documentElement
]);