inert-and-find.html (1607B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <link rel="help" href="https://html.spec.whatwg.org/#inert-subtrees"> 6 <title>Basic test for inert and find</title> 7 <body> 8 <script> 9 const t = async_test("Basic test for inert and find"); 10 11 function testFindable(findCount, textToFind, buildDoc, description) { 12 if (typeof findCount == "boolean") 13 findCount = findCount ? 1 : 0; 14 try { 15 const iframe = document.querySelector("iframe") 16 iframe.contentDocument.documentElement.innerHTML = 17 (typeof buildDoc == "string") ? buildDoc : ""; 18 19 if (typeof buildDoc == "function") 20 buildDoc(iframe.contentDocument); 21 22 iframe.contentWindow.getSelection().removeAllRanges(); 23 for (let i = findCount; i >= 0; --i) { 24 const expectFindable = i != 0; 25 assert_equals( 26 iframe.contentWindow.find(textToFind), 27 expectFindable, 28 "Should be " + (expectFindable ? "" : "not ") + "findable: " + description + ", text: " + textToFind + ", iter: " + (findCount - i + 1) 29 ); 30 } 31 } catch (ex) { 32 assert_unreached(ex); 33 } 34 } 35 36 let runTests = t.step_func_done(function() { 37 testFindable(true, "me", ` 38 Find me please 39 `, "basic functionality test"); 40 41 testFindable(false, "me", ` 42 <div inert>Do not find me please</div> 43 `, "Basic use case"); 44 }); 45 46 window.onload = function() { 47 let iframe = document.createElement("iframe"); 48 iframe.onload = runTests; 49 iframe.srcdoc = "<!doctype html><html></html>"; 50 document.body.appendChild(iframe); 51 }; 52 </script> 53 </body>