Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / shadow / resources / shadow-dom-util.js
1 // ----------------------------------------------------------------------
2 // shadow-dom-util.js is a set of utility to test Shadow DOM.
3
4 function getElementByIdConsideringShadowDOM(root, id) {
5     function iter(root, id) {
6         if (!root)
7             return null;
8
9         if (root.id == id)
10             return root;
11
12         // We don't collect div having a shadow root, since we cannot point it correctly.
13         // Such div should have an inner div to be pointed correctly.
14         for (var child = root.firstChild; child; child = child.nextSibling) {
15             var node = iter(child, id);
16             if (node != null)
17                 return node;
18         }
19
20         if (root.nodeType != 1)
21             return null;
22
23         for (var shadowRoot = internals.youngestShadowRoot(root); shadowRoot; shadowRoot = shadowRoot.olderShadowRoot) {
24             var node = iter(shadowRoot, id);
25             if (node != null)
26                 return node;
27         }
28
29         return null;
30     };
31
32     if (!window.internals)
33         return null;
34     return iter(root, id);
35 }