Add support for getting an element in shadow root by its id into a window.internals...
[WebKit-https.git] / LayoutTests / fast / dom / shadow / get-element-by-id-in-shadow-root.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../js/resources/js-test-pre.js"></script>
5 <script src="resources/create-dom.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10 <script>
11 description("Tests to ensure that internals.getElementByIdInTreeScope can get an element in TreeScope by its id. Can only run within DRT");
12
13 function getElementInShadow(path)
14 {
15     var ids = path.split('/');
16     var element = document.getElementById(ids[0]);
17     for (var i = 1; element != null && i < ids.length; ++i) {
18         var shadowRoot = internals.shadowRoot(element);
19         element = internals.getElementByIdInShadowRoot(shadowRoot, ids[i]);
20     }
21     return element;
22 }
23
24 function prepareDomTree(parent)
25 {
26     parent.appendChild(
27         createShadow('div', {'id': 'divA'},
28                      createDom('input', {'id': 'inputB'}),
29                      createShadow('div', {'id': 'divC'},
30                                   createDom('input', {'id': 'inputD'}))));
31 }
32
33 function test()
34 {
35     if (window.layoutTestController)
36         layoutTestController.dumpAsText();
37     prepareDomTree(document.body);
38     shouldBeEqualToString("getElementInShadow('divA/inputB').id", 'inputB');
39     shouldBeEqualToString("getElementInShadow('divA/divC').id", 'divC');
40     shouldBeEqualToString("getElementInShadow('divA/divC/inputD').id", 'inputD');
41 }
42
43 test();
44
45 var successfullyParsed = true;
46 </script>
47 <script src="../../js/resources/js-test-post.js"></script>
48 </body>
49 </html>