embedding/test/test_nsFind.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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">
    18 </div>
    19 <pre id="test">
    20 <script type="application/javascript">
    22 /** Test for Bug 450048 **/
    24   // Check nsFind class and its nsIFind interface.
    26   var rf = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"]
    27                         .getService(SpecialPowers.Ci.nsIFind);
    29   var display = window.document.getElementById("display");
    30   var searchRange = window.document.createRange();
    31   searchRange.setStart(display, 0);
    32   searchRange.setEnd(display, display.childNodes.length);
    33   var startPt = searchRange;
    34   var endPt = searchRange;
    36   // Check |null| detection on |aPatText| parameter.
    37   try {
    38     rf.Find(null, searchRange, startPt, endPt);
    40     ok(false, "Missing NS_ERROR_NULL_POINTER exception");
    41   } catch (e) {
    42     e = SpecialPowers.wrap(e);
    43     if (e.result == SpecialPowers.Cr.NS_ERROR_NULL_POINTER) {
    44       ok(true, null);
    45     } else {
    46       throw e;
    47     }
    48   }
    50   // Check |null| detection on |aSearchRange| parameter.
    51   try {
    52     rf.Find("", null, startPt, endPt);
    54     ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
    55   } catch (e) {
    56     e = SpecialPowers.wrap(e);
    57     if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
    58       ok(true, null);
    59     } else {
    60       throw e;
    61     }
    62   }
    64   // Check |null| detection on |aStartPoint| parameter.
    65   try {
    66     rf.Find("", searchRange, null, endPt);
    68     ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
    69   } catch (e) {
    70     e = SpecialPowers.wrap(e);
    71     if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
    72       ok(true, null);
    73     } else {
    74       throw e;
    75     }
    76   }
    78   // Check |null| detection on |aEndPoint| parameter.
    79   try {
    80     rf.Find("", searchRange, startPt, null);
    82     ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
    83   } catch (e) {
    84     e = SpecialPowers.wrap(e);
    85     if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
    86       ok(true, null);
    87     } else {
    88       throw e;
    89     }
    90   }
    92   var searchValue, retRange;
    94   rf.findBackwards = false;
    96   rf.caseSensitive = false;
    98   searchValue = "TexT";
    99   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   100   ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
   102   rf.caseSensitive = true;
   104   // searchValue = "TexT";
   105   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   106   ok(!retRange, "\"" + searchValue + "\" found (caseSensitive)");
   108   searchValue = "text";
   109   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   110   ok(retRange, "\"" + searchValue + "\" not found");
   112   // Matches |i<b>n&shy;t</b>o|.
   113   searchValue = "into";
   114   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   115   ok(retRange, "\"" + searchValue + "\" not found");
   117   // Matches inside |search|.
   118   searchValue = "ear";
   119   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   120   ok(retRange, "\"" + searchValue + "\" not found");
   122   // Set new start point (to end of last search).
   123   startPt = retRange.endContainer.ownerDocument.createRange();
   124   startPt.setStart(retRange.endContainer, retRange.endOffset);
   125   startPt.setEnd(retRange.endContainer, retRange.endOffset);
   127   searchValue = "t";
   128   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   129   ok(retRange, "\"" + searchValue + "\" not found (forward)");
   131   searchValue = "the";
   132   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   133   ok(!retRange, "\"" + searchValue + "\" found (forward)");
   135   rf.findBackwards = true;
   137   // searchValue = "the";
   138   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   139   ok(retRange, "\"" + searchValue + "\" not found (backward)");
   142   // Curly quotes and straight quotes should match.
   144   rf.caseSensitive = false;
   145   rf.findBackwards = false;
   147   function find(node, searchValue) {
   148     var range = document.createRange();
   149     range.setStart(node, 0);
   150     range.setEnd(node, node.childNodes.length);
   151     return rf.Find(searchValue, range, range, range);
   152   }
   154   function assertFound(node, searchValue) {
   155     ok(find(node, searchValue), "\"" + searchValue + "\" not found");
   156   }
   158   function assertNotFound(node, searchValue) {
   159     ok(!find(node, searchValue), "\"" + searchValue + "\" found");
   160   }
   162   var quotes = document.getElementById("quotes");
   164   assertFound(quotes, "\"straight\"");
   165   assertFound(quotes, "\u201Cstraight\u201D");
   167   assertNotFound(quotes, "'straight'");
   168   assertNotFound(quotes, "\u2018straight\u2019");
   169   assertNotFound(quotes, "\u2019straight\u2018");
   170   assertNotFound(quotes, ".straight.");
   172   assertFound(quotes, "\"curly\"");
   173   assertFound(quotes, "\u201Ccurly\u201D");
   175   assertNotFound(quotes, "'curly'");
   176   assertNotFound(quotes, "\u2018curly\u2019");
   177   assertNotFound(quotes, ".curly.");
   179   assertFound(quotes, "didn't");
   180   assertFound(quotes, "didn\u2018t");
   181   assertFound(quotes, "didn\u2019t");
   183   assertNotFound(quotes, "didnt");
   184   assertNotFound(quotes, "didn t");
   185   assertNotFound(quotes, "didn.t");
   187   assertFound(quotes, "'didn't'");
   188   assertFound(quotes, "'didn\u2018t'");
   189   assertFound(quotes, "'didn\u2019t'");
   190   assertFound(quotes, "\u2018didn't\u2019");
   191   assertFound(quotes, "\u2019didn't\u2018");
   192   assertFound(quotes, "\u2018didn't\u2018");
   193   assertFound(quotes, "\u2019didn't\u2019");
   194   assertFound(quotes, "\u2018didn\u2019t\u2019");
   195   assertFound(quotes, "\u2019didn\u2018t\u2019");
   196   assertFound(quotes, "\u2018didn\u2019t\u2018");
   198   assertNotFound(quotes, "\"didn't\"");
   199   assertNotFound(quotes, "\u201Cdidn't\u201D");
   201   assertFound(quotes, "doesn't");
   202   assertFound(quotes, "doesn\u2018t");
   203   assertFound(quotes, "doesn\u2019t");
   205   assertNotFound(quotes, "doesnt");
   206   assertNotFound(quotes, "doesn t");
   207   assertNotFound(quotes, "doesn.t");
   209   assertFound(quotes, "'doesn't'");
   210   assertFound(quotes, "'doesn\u2018t'");
   211   assertFound(quotes, "'doesn\u2019t'");
   212   assertFound(quotes, "\u2018doesn't\u2019");
   213   assertFound(quotes, "\u2019doesn't\u2018");
   214   assertFound(quotes, "\u2018doesn't\u2018");
   215   assertFound(quotes, "\u2019doesn't\u2019");
   216   assertFound(quotes, "\u2018doesn\u2019t\u2019");
   217   assertFound(quotes, "\u2019doesn\u2018t\u2019");
   218   assertFound(quotes, "\u2018doesn\u2019t\u2018");
   220   assertNotFound(quotes, "\"doesn't\"");
   221   assertNotFound(quotes, "\u201Cdoesn't\u201D");
   222 </script>
   223 </pre>
   224 </body>
   225 </html>

mercurial