test_bug499115.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!DOCTYPE HTML>
  2. <!-- This Source Code Form is subject to the terms of the Mozilla Public
  3. - License, v. 2.0. If a copy of the MPL was not distributed with this
  4. - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
  5. <html>
  6. <!--
  7. https://bugzilla.mozilla.org/show_bug.cgi?id=499115
  8. -->
  9. <head>
  10. <title>Test for Bug 499115</title>
  11. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  12. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  13. </head>
  14. <body onload="onLoad();">
  15. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=499115">Mozilla Bug 499115</a>
  16. <p id="display"></p>
  17. <div id="content" style="display: none">
  18. </div>
  19. <pre id="test">
  20. <script type="application/javascript">
  21. /** Test for Bug 499115 **/
  22. SimpleTest.waitForExplicitFinish();
  23. const SEARCH_TEXT="minefield";
  24. function getMatches() {
  25. var numMatches = 0;
  26. var searchRange = document.createRange();
  27. searchRange.selectNodeContents(document.body);
  28. var startPoint = searchRange.cloneRange();
  29. startPoint.collapse(true);
  30. var endPoint = searchRange.cloneRange();
  31. endPoint.collapse(false);
  32. var retRange = null;
  33. var finder = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"]
  34. .createInstance(SpecialPowers.Ci.nsIFind);
  35. finder.caseSensitive = false;
  36. while ((retRange = finder.Find(SEARCH_TEXT, searchRange,
  37. startPoint, endPoint))) {
  38. numMatches++;
  39. // Start next search from end of current match
  40. startPoint = retRange.cloneRange();
  41. startPoint.collapse(false);
  42. }
  43. return numMatches;
  44. }
  45. function onLoad() {
  46. var matches = getMatches();
  47. is(matches, 2, "found second match in anonymous content");
  48. SimpleTest.finish();
  49. }
  50. </script>
  51. </pre>
  52. <input type="text" value="minefield minefield"></body>
  53. </html>