Bug 1455891: Add a test of finding text in Shadow DOM. r?mats draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 03 Jul 2018 09:35:17 +0200
changeset 813922 f12211aac0db2aef9c76c9fc6a316b0495dcafb3
parent 813921 35ae348b47a2423ddd96ec34f67a1e5b8018a680
child 813923 38cbbe6110f33dbc43371b6466e04a56c24b56c4
child 813925 18ad098549be01906fcf590a9bbe2524c030686e
child 814722 22b1f49d92e789be4534e15c3503119fdd9e494c
push id115046
push userbmo:emilio@crisal.io
push dateWed, 04 Jul 2018 05:02:13 +0000
reviewersmats
bugs1455891
milestone63.0a1
Bug 1455891: Add a test of finding text in Shadow DOM. r?mats MozReview-Commit-ID: 70oZd58CEFs
dom/base/test/test_find.html
--- a/dom/base/test/test_find.html
+++ b/dom/base/test/test_find.html
@@ -1,19 +1,25 @@
 <!doctype html>
 <meta charset="utf-8">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<body>
 <script>
 const t = async_test("Test window.find / nsFind");
 
-function testFindable(isFindable, textToFind, docText, description) {
+function testFindable(isFindable, textToFind, buildDoc, description) {
   try{
     const iframe = document.querySelector("iframe")
-    iframe.contentDocument.documentElement.innerHTML = docText;
+    iframe.contentDocument.documentElement.innerHTML =
+      (typeof buildDoc == "string") ? buildDoc : "";
+
+    if (typeof buildDoc == "function")
+      buildDoc(iframe.contentDocument);
+
     iframe.contentWindow.getSelection().removeAllRanges();
     assert_equals(
       isFindable,
       iframe.contentWindow.find(textToFind),
       "Should be " + (isFindable ? "" : "not ") + "findable: " + description + ", text: " + textToFind
     );
   } catch (ex) {
     assert_unreached(ex);
@@ -30,17 +36,17 @@ const INLINE_LIKE_DISPLAY_VALUES = [
 const BLOCK_LIKE_DISPLAY_VALUES = [
   "block",
   "table",
   "list-item",
   "grid",
   "flex",
 ];
 
-window.runTests = t.step_func_done(function() {
+let runTests = t.step_func_done(function() {
   testFindable(true, "me and me", `
     me <div style="display: contents">and</div> me
   `, "display: contents");
 
   testFindable(true, "me me", `
     me <div style="display: none">and</div> me
   `, "display: none");
 
@@ -72,11 +78,37 @@ window.runTests = t.step_func_done(funct
 
   testFindable(true, "This text should be visible", `
     <div style="visibility: hidden">
       <div style="visibility: visible">
         This text should be visible
       </div>
     </div>
   `);
+
+  testFindable(true, "Shadow text", function(document) {
+    let div = document.createElement("div");
+    div.attachShadow({ mode: "open" }).innerHTML = `
+      Wohoo, this is Shadow text, yay!
+    `;
+    document.documentElement.appendChild(div);
+  }, "In Shadow DOM");
+
+  testFindable(true, "Shadow text", function(document) {
+    let div = document.createElement("div");
+    div.appendChild(document.createTextNode(
+      "Wohoo, this is Shadow text, yay!"
+    ));
+    div.attachShadow({ mode: "open" }).innerHTML = `<slot></slot>`;
+    document.documentElement.appendChild(div);
+  }, "Slotted content in Shadow DOM");
 });
+
+SpecialPowers.pushPrefEnv(
+  {"set":[['dom.webcomponents.shadowdom.enabled', true]]},
+  t.step_func(function() {
+    let iframe = document.createElement("iframe");
+    iframe.onload = runTests;
+    iframe.srcdoc = "<!doctype html><html></html>";
+    document.body.appendChild(iframe);
+  }));
 </script>
-<iframe onload="runTests()" srcdoc="<!doctype html><html></html>"></iframe>
+</body>