[Shadow DOM] Make createDOM() function used in testing Shadow DOM more flexible.
[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 <script>
9 description("Tests to ensure that internals.getElementByIdInTreeScope can get an element in TreeScope by its id. Can only run within DRT");
10
11 function getElementInShadow(path)
12 {
13     var ids = path.split('/');
14     var element = document.getElementById(ids[0]);
15     for (var i = 1; element != null && i < ids.length; ++i) {
16         var shadowRoot = internals.shadowRoot(element);
17         element = internals.getElementByIdInShadowRoot(shadowRoot, ids[i]);
18     }
19     return element;
20 }
21
22 function prepareDomTree(parent)
23 {
24     parent.appendChild(
25         createDOM('div', {'id': 'divA'},
26                   createShadowRoot(
27                       createDOM('input', {'id': 'inputB'}),
28                       createDOM('div', {'id': 'divC'},
29                                 createShadowRoot(
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 </script>
45 <script src="../../js/resources/js-test-post.js"></script>
46 </body>
47 </html>