test_find_bug1654683.html (1115B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <div class="before"> 6 mozilla before 7 </div> 8 <input value="mozilla"> 9 <div class="after"> 10 mozilla after 11 </div> 12 <script> 13 function selectionContainedWithin(selector) { 14 for (let node = getSelection().anchorNode; node; node = node.parentNode) { 15 if (node.matches && node.matches(selector)) 16 return true; 17 } 18 return false; 19 } 20 21 test(function () { 22 let input = document.querySelector("input"); 23 input.focus(); 24 assert_true(window.find("mozilla"), "Found the string, didn't throw"); 25 assert_true(selectionContainedWithin(".after"), "Should've found the following node"); 26 assert_true(!window.find("mozilla"), "No more matches forward"); 27 assert_true(window.find("mozilla", /* caseSensitive = */ false, /* backwards = */ true), "Should find stuff backwards"); 28 assert_true(selectionContainedWithin(".before"), "Should've found the node before the input (should not return the NAC range)"); 29 }, "window.find() doesn't throw if focused on an <input>"); 30 </script>