Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=806506 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for ShadowRoot</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <div id="movedtoshadow" class="testclass"></div> |
michael@0 | 13 | <svg id="svgmovedtoshadow"></svg> |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=806506">Bug 806506</a> |
michael@0 | 15 | <script> |
michael@0 | 16 | // Create ShadowRoot. |
michael@0 | 17 | var element = document.createElement("div"); |
michael@0 | 18 | ok(!element.shadowRoot, "div element should not have a shadow root."); |
michael@0 | 19 | var shadow = element.createShadowRoot(); |
michael@0 | 20 | is(element.shadowRoot, shadow, "shadowRoot property should return the same shadow root that was just created."); |
michael@0 | 21 | |
michael@0 | 22 | // Move an element from the document to the ShadowRoot. |
michael@0 | 23 | var inShadowEl = document.getElementById("movedtoshadow"); |
michael@0 | 24 | var inShadowSVGEl = document.getElementById("svgmovedtoshadow"); |
michael@0 | 25 | |
michael@0 | 26 | // Test getElementById |
michael@0 | 27 | ok(!shadow.getElementById("movedtoshadow"), "Element not in ShadowRoot should not be accessible from ShadowRoot API."); |
michael@0 | 28 | ok(!shadow.getElementById("svgmovedtoshadow"), "SVG element not in ShadowRoot should not be accessible from ShadowRoot API."); |
michael@0 | 29 | shadow.appendChild(inShadowEl); |
michael@0 | 30 | shadow.appendChild(inShadowSVGEl); |
michael@0 | 31 | is(shadow.getElementById("movedtoshadow"), inShadowEl, "Element appended to a ShadowRoot should be accessible from ShadowRoot API."); |
michael@0 | 32 | ok(!document.getElementById("movedtoshadow"), "Element appended to a ShadowRoot should not be accessible from document."); |
michael@0 | 33 | is(shadow.getElementById("svgmovedtoshadow"), inShadowSVGEl, "SVG element appended to a ShadowRoot should be accessible from ShadowRoot API."); |
michael@0 | 34 | ok(!document.getElementById("svgmovedtoshadow"), "SVG element appended to a ShadowRoot should not be accessible from document."); |
michael@0 | 35 | |
michael@0 | 36 | // Test getElementsByClassName |
michael@0 | 37 | is(document.getElementsByClassName("testclass").length, 0, "Element removed from DOM should not be accessible by DOM accessors."); |
michael@0 | 38 | is(shadow.getElementsByClassName("testclass").length, 1, "Element added to ShadowRoot should be accessible by ShadowRoot API."); |
michael@0 | 39 | |
michael@0 | 40 | // Test getElementsByTagName{NS} |
michael@0 | 41 | is(document.getElementsByTagName("div").length, 0, "Element removed from DOM should not be accessible from DOM accessors."); |
michael@0 | 42 | is(shadow.getElementsByTagName("div").length, 1, "Elements in the ShadowRoot should be accessible from the ShadowRoot API."); |
michael@0 | 43 | is(document.getElementsByTagName("svg").length, 0, "SVG elements removed from DOM should not be accessible from DOM accessors."); |
michael@0 | 44 | is(shadow.getElementsByTagName("svg").length, 1, "SVG element in the ShadowRoot should be accessible from the ShadowRoot API."); |
michael@0 | 45 | is(shadow.getElementsByTagNameNS("http://www.w3.org/2000/svg", "svg").length, 1, "SVG element in the ShadowRoot should be accessible from the ShadowRoot API."); |
michael@0 | 46 | |
michael@0 | 47 | // Remove elements from ShadowRoot and make sure that they are no longer accessible via the ShadowRoot API. |
michael@0 | 48 | shadow.removeChild(inShadowEl); |
michael@0 | 49 | shadow.removeChild(inShadowSVGEl); |
michael@0 | 50 | ok(!shadow.getElementById("movedtoshadow"), "ShadowRoot API should not be able to access elements removed from ShadowRoot."); |
michael@0 | 51 | ok(!shadow.getElementById("svgmovedtoshadow"), "ShadowRoot API should not be able to access elements removed from ShadowRoot."); |
michael@0 | 52 | is(shadow.getElementsByClassName("testclass").length, 0, "ShadowRoot getElementsByClassName should not be able to access elements removed from ShadowRoot."); |
michael@0 | 53 | is(shadow.getElementsByTagName("svg").length, 0, "ShadowRoot getElementsByTagName should not be able to access elements removed from ShadowRoot."); |
michael@0 | 54 | is(shadow.getElementsByTagNameNS("http://www.w3.org/2000/svg", "svg").length, 0, "ShadowRoot getElementsByTagNameNS should not be able to access elements removed from ShadowRoot."); |
michael@0 | 55 | |
michael@0 | 56 | // Test querySelector on element in a ShadowRoot. |
michael@0 | 57 | element = document.createElement("div"); |
michael@0 | 58 | shadow = element.createShadowRoot(); |
michael@0 | 59 | var parentDiv = document.createElement("div"); |
michael@0 | 60 | var childSpan = document.createElement("span"); |
michael@0 | 61 | childSpan.id = "innerdiv"; |
michael@0 | 62 | parentDiv.appendChild(childSpan); |
michael@0 | 63 | is(parentDiv.querySelector("#innerdiv"), childSpan, "ID query selector should work on element in ShadowRoot."); |
michael@0 | 64 | is(parentDiv.querySelector("span"), childSpan, "Tag query selector should work on element in ShadowRoot."); |
michael@0 | 65 | |
michael@0 | 66 | // Test that exception is thrown when trying to create a cycle with host node. |
michael@0 | 67 | element = document.createElement("div"); |
michael@0 | 68 | shadow = element.createShadowRoot(); |
michael@0 | 69 | try { |
michael@0 | 70 | shadow.appendChild(element); |
michael@0 | 71 | ok(false, "Excpetion should be thrown when creating a cycle with host content."); |
michael@0 | 72 | } catch (ex) { |
michael@0 | 73 | ok(true, "Excpetion should be thrown when creating a cycle with host content."); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | // Basic innerHTML tests. |
michael@0 | 77 | shadow.innerHTML = '<span id="first"></span><div id="second"></div>'; |
michael@0 | 78 | is(shadow.childNodes.length, 2, "There should be two children in the ShadowRoot."); |
michael@0 | 79 | is(shadow.getElementById("second").tagName, "DIV", "Elements created by innerHTML should be accessible by ShadowRoot API."); |
michael@0 | 80 | |
michael@0 | 81 | </script> |
michael@0 | 82 | </body> |
michael@0 | 83 | </html> |