| <!doctype html> |
| <meta charset="utf-8"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <link rel="help" href="https://github.com/w3c/csswg-drafts/issues/3460"> |
| <title>Basic test for the user-find property</title> |
| <body> |
| <script> |
| const t = async_test("Basic test for the user-find property"); |
| |
| function testFindable(findCount, textToFind, buildDoc, description) { |
| if (typeof findCount == "boolean") |
| findCount = findCount ? 1 : 0; |
| try { |
| const iframe = document.querySelector("iframe") |
| iframe.contentDocument.documentElement.innerHTML = |
| (typeof buildDoc == "string") ? buildDoc : ""; |
| |
| if (typeof buildDoc == "function") |
| buildDoc(iframe.contentDocument); |
| |
| iframe.contentWindow.getSelection().removeAllRanges(); |
| for (let i = findCount; i >= 0; --i) { |
| const expectFindable = i != 0; |
| assert_equals( |
| iframe.contentWindow.find(textToFind), |
| expectFindable, |
| "Should be " + (expectFindable ? "" : "not ") + "findable: " + description + ", text: " + textToFind + ", iter: " + (findCount - i + 1) |
| ); |
| } |
| } catch (ex) { |
| assert_unreached(ex); |
| } |
| } |
| |
| let runTests = t.step_func_done(function() { |
| testFindable(true, "me", ` |
| Find me please |
| `, "sanity test"); |
| |
| testFindable(false, "me", ` |
| <div style="user-find: none">Do not find me please</div> |
| `, "Basic use case"); |
| |
| testFindable(true, "me", ` |
| <div style="user-find: none">Do not find me, but <span style="user-find: auto">find me please</span></div> |
| `, "nested"); |
| }); |
| |
| window.onload = function() { |
| let iframe = document.createElement("iframe"); |
| iframe.onload = runTests; |
| iframe.srcdoc = "<!doctype html><html></html>"; |
| document.body.appendChild(iframe); |
| }; |
| </script> |
| </body> |