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