OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <style> |
| 5 #container > div { |
| 6 border: green solid thin; |
| 7 } |
| 8 :lang(fr) { background:blue; color:white; } |
| 9 :lang(ja) { background:green; color:white; } |
| 10 </style> |
| 11 <div id="container"> |
| 12 <p>Test passes if "French" are all in blue and other text are all in green.<
/p> |
| 13 <div lang="ja"> |
| 14 <div id="normal"></div> |
| 15 <div id="distributed"><div>Distributed</div></div> |
| 16 <div id="multiple"><div>Distributed to the youngest</div></div> |
| 17 <div id="multilevel"><div>Multi-level Distributed</div></div> |
| 18 <div id="older"></div> |
| 19 <div id="redistributed"><div>Re-distributed</div></div> |
| 20 </div> |
| 21 </div> |
| 22 <script> |
| 23 setup({ explicit_done: true }); |
| 24 var fr = "rgb(0, 0, 255)"; |
| 25 var ja = "rgb(0, 128, 0)"; |
| 26 var style = "<style>:lang(fr) { background:blue; color:white; } :lang(ja) { back
ground:green; color:white; }</style>"; |
| 27 |
| 28 var host = document.getElementById("normal"); |
| 29 createShadowRootWithInnerHtml(host, style + "<div lang=fr>French</div><div>Inher
it Normally</div>"); |
| 30 testLangInShadow("lang inherits into the shadow tree", |
| 31 [[host.shadowRoot.querySelector("div"), fr], |
| 32 [host.shadowRoot.lastChild, ja]]); |
| 33 |
| 34 host = document.getElementById("distributed"); |
| 35 createShadowRootWithInnerHtml(host, style + "<div lang=fr><div>French</div><cont
ent></content></div>"); |
| 36 testLangInShadow("lang of the distributed content traverses the tree of trees", |
| 37 [[host.shadowRoot.querySelector("div"), fr], |
| 38 [host.shadowRoot.host.firstChild, ja]]); |
| 39 |
| 40 host = document.getElementById("multiple"); |
| 41 createShadowRootWithInnerHtml(host, style + "<content></content>"); |
| 42 createShadowRootWithInnerHtml(host, style + "<div lang=fr><div>French</div><cont
ent></content></div>"); |
| 43 testLangInShadow("lang of the distributed content traverses the tree of trees (m
ultiple shadow roots)", |
| 44 [[host.shadowRoot.querySelector("div"), fr], |
| 45 [host.shadowRoot.host.firstChild, ja]]); |
| 46 |
| 47 host = document.getElementById("multilevel"); |
| 48 var host2ndLevel = createShadowRootWithInnerHtml(host, "<div><content></content>
</div>").firstChild; |
| 49 createShadowRootWithInnerHtml(host2ndLevel, style + "<div lang=fr><div>French</d
iv><content></content></div>"); |
| 50 testLangInShadow("lang of the distributed content traverses the tree of trees (m
ultiple levels)", |
| 51 [[host2ndLevel.shadowRoot.querySelector("div"), fr], |
| 52 [host.firstChild, ja]]); |
| 53 |
| 54 host = document.getElementById("older"); |
| 55 createShadowRootWithInnerHtml(host, style + "<div>olderShadowRoot</div>"); |
| 56 createShadowRootWithInnerHtml(host, style + "<div lang=fr><div>French</div><shad
ow></shadow></div>"); |
| 57 testLangInShadow("lang of the older shadow root traverses the tree of trees", |
| 58 [[host.shadowRoot.querySelector("div"), fr], |
| 59 [host.shadowRoot.olderShadowRoot.querySelector("div"), ja]]); |
| 60 |
| 61 host = document.getElementById("redistributed"); |
| 62 createShadowRootWithInnerHtml(host, style + "<div lang=fr><div>French</div><cont
ent></content></div>"); |
| 63 createShadowRootWithInnerHtml(host, style + "<shadow></shadow>"); |
| 64 testLangInShadow("lang of the re-distributed content traverses the tree of trees
", |
| 65 [[host.shadowRoot.olderShadowRoot.querySelector("div"), fr], |
| 66 [host.firstChild, ja]]); |
| 67 |
| 68 function testLangInShadow(description, elementAndExpectedList) { |
| 69 test(function () { |
| 70 elementAndExpectedList.forEach(function (elementAndExpected) { |
| 71 var element = elementAndExpected[0]; |
| 72 var actual = getComputedStyle(element).backgroundColor; |
| 73 assert_equals(actual, elementAndExpected[1]); |
| 74 }); |
| 75 }, description); |
| 76 } |
| 77 |
| 78 function createShadowRootWithInnerHtml(host, shadowHtml) { |
| 79 var root = host.createShadowRoot(); |
| 80 root.innerHTML = shadowHtml; |
| 81 return root; |
| 82 } |
| 83 |
| 84 if (window.testRunner) |
| 85 container.style.display = "none"; |
| 86 done(); |
| 87 </script> |
OLD | NEW |