test_nsFind.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=450048
  5. -->
  6. <head>
  7. <meta charset="UTF-8">
  8. <title>Test for nsFind::Find()</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450048">Mozilla Bug 450048</a>
  14. <p id="display">This is the text to search i<b>n&shy;t</b>o</p>
  15. <p id="quotes">"straight" and &ldquo;curly&rdquo; and &lsquo;didn't&rsquo; and 'doesn&rsquo;t'</p>
  16. <div id="content" style="display: none">
  17. </div>
  18. <pre id="test">
  19. <script type="application/javascript">
  20. /** Test for Bug 450048 **/
  21. // Check nsFind class and its nsIFind interface.
  22. var rf = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"]
  23. .getService(SpecialPowers.Ci.nsIFind);
  24. var display = window.document.getElementById("display");
  25. var searchRange = window.document.createRange();
  26. searchRange.setStart(display, 0);
  27. searchRange.setEnd(display, display.childNodes.length);
  28. var startPt = searchRange;
  29. var endPt = searchRange;
  30. // Check |null| detection on |aSearchRange| parameter.
  31. try {
  32. rf.Find("", null, startPt, endPt);
  33. ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
  34. } catch (e) {
  35. e = SpecialPowers.wrap(e);
  36. if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
  37. ok(true, null);
  38. } else {
  39. throw e;
  40. }
  41. }
  42. // Check |null| detection on |aStartPoint| parameter.
  43. try {
  44. rf.Find("", searchRange, null, endPt);
  45. ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
  46. } catch (e) {
  47. e = SpecialPowers.wrap(e);
  48. if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
  49. ok(true, null);
  50. } else {
  51. throw e;
  52. }
  53. }
  54. // Check |null| detection on |aEndPoint| parameter.
  55. try {
  56. rf.Find("", searchRange, startPt, null);
  57. ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
  58. } catch (e) {
  59. e = SpecialPowers.wrap(e);
  60. if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
  61. ok(true, null);
  62. } else {
  63. throw e;
  64. }
  65. }
  66. var searchValue, retRange;
  67. rf.findBackwards = false;
  68. rf.caseSensitive = false;
  69. searchValue = "TexT";
  70. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  71. ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
  72. rf.caseSensitive = true;
  73. // searchValue = "TexT";
  74. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  75. ok(!retRange, "\"" + searchValue + "\" found (caseSensitive)");
  76. searchValue = "text";
  77. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  78. ok(retRange, "\"" + searchValue + "\" not found");
  79. // Matches |i<b>n&shy;t</b>o|.
  80. searchValue = "into";
  81. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  82. ok(retRange, "\"" + searchValue + "\" not found");
  83. // Matches inside |search|.
  84. searchValue = "ear";
  85. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  86. ok(retRange, "\"" + searchValue + "\" not found");
  87. // Set new start point (to end of last search).
  88. startPt = retRange.endContainer.ownerDocument.createRange();
  89. startPt.setStart(retRange.endContainer, retRange.endOffset);
  90. startPt.setEnd(retRange.endContainer, retRange.endOffset);
  91. searchValue = "t";
  92. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  93. ok(retRange, "\"" + searchValue + "\" not found (forward)");
  94. searchValue = "the";
  95. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  96. ok(!retRange, "\"" + searchValue + "\" found (forward)");
  97. rf.findBackwards = true;
  98. // searchValue = "the";
  99. retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  100. ok(retRange, "\"" + searchValue + "\" not found (backward)");
  101. // Curly quotes and straight quotes should match.
  102. rf.caseSensitive = false;
  103. rf.findBackwards = false;
  104. function find(node, searchValue) {
  105. var range = document.createRange();
  106. range.setStart(node, 0);
  107. range.setEnd(node, node.childNodes.length);
  108. return rf.Find(searchValue, range, range, range);
  109. }
  110. function assertFound(node, searchValue) {
  111. ok(find(node, searchValue), "\"" + searchValue + "\" not found");
  112. }
  113. function assertNotFound(node, searchValue) {
  114. ok(!find(node, searchValue), "\"" + searchValue + "\" found");
  115. }
  116. var quotes = document.getElementById("quotes");
  117. assertFound(quotes, "\"straight\"");
  118. assertFound(quotes, "\u201Cstraight\u201D");
  119. assertNotFound(quotes, "'straight'");
  120. assertNotFound(quotes, "\u2018straight\u2019");
  121. assertNotFound(quotes, "\u2019straight\u2018");
  122. assertNotFound(quotes, ".straight.");
  123. assertFound(quotes, "\"curly\"");
  124. assertFound(quotes, "\u201Ccurly\u201D");
  125. assertNotFound(quotes, "'curly'");
  126. assertNotFound(quotes, "\u2018curly\u2019");
  127. assertNotFound(quotes, ".curly.");
  128. assertFound(quotes, "didn't");
  129. assertFound(quotes, "didn\u2018t");
  130. assertFound(quotes, "didn\u2019t");
  131. assertNotFound(quotes, "didnt");
  132. assertNotFound(quotes, "didn t");
  133. assertNotFound(quotes, "didn.t");
  134. assertFound(quotes, "'didn't'");
  135. assertFound(quotes, "'didn\u2018t'");
  136. assertFound(quotes, "'didn\u2019t'");
  137. assertFound(quotes, "\u2018didn't\u2019");
  138. assertFound(quotes, "\u2019didn't\u2018");
  139. assertFound(quotes, "\u2018didn't\u2018");
  140. assertFound(quotes, "\u2019didn't\u2019");
  141. assertFound(quotes, "\u2018didn\u2019t\u2019");
  142. assertFound(quotes, "\u2019didn\u2018t\u2019");
  143. assertFound(quotes, "\u2018didn\u2019t\u2018");
  144. assertNotFound(quotes, "\"didn't\"");
  145. assertNotFound(quotes, "\u201Cdidn't\u201D");
  146. assertFound(quotes, "doesn't");
  147. assertFound(quotes, "doesn\u2018t");
  148. assertFound(quotes, "doesn\u2019t");
  149. assertNotFound(quotes, "doesnt");
  150. assertNotFound(quotes, "doesn t");
  151. assertNotFound(quotes, "doesn.t");
  152. assertFound(quotes, "'doesn't'");
  153. assertFound(quotes, "'doesn\u2018t'");
  154. assertFound(quotes, "'doesn\u2019t'");
  155. assertFound(quotes, "\u2018doesn't\u2019");
  156. assertFound(quotes, "\u2019doesn't\u2018");
  157. assertFound(quotes, "\u2018doesn't\u2018");
  158. assertFound(quotes, "\u2019doesn't\u2019");
  159. assertFound(quotes, "\u2018doesn\u2019t\u2019");
  160. assertFound(quotes, "\u2019doesn\u2018t\u2019");
  161. assertFound(quotes, "\u2018doesn\u2019t\u2018");
  162. assertNotFound(quotes, "\"doesn't\"");
  163. assertNotFound(quotes, "\u201Cdoesn't\u201D");
  164. // Curly quotes and straight quotes should not match.
  165. rf.caseSensitive = true;
  166. assertFound(quotes, "\"straight\"");
  167. assertNotFound(quotes, "\u201Cstraight\u201D");
  168. assertNotFound(quotes, "\"curly\"");
  169. assertFound(quotes, "\u201Ccurly\u201D");
  170. assertFound(quotes, "\u2018didn't\u2019");
  171. assertNotFound(quotes, "'didn't'");
  172. assertFound(quotes, "'doesn\u2019t'");
  173. assertNotFound(quotes, "'doesn\u2018t'");
  174. assertNotFound(quotes, "'doesn't'");
  175. </script>
  176. </pre>
  177. </body>
  178. </html>