Bug 1455891: Add a test of finding text in Shadow DOM. r?mats
MozReview-Commit-ID: 70oZd58CEFs
--- 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>