|
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­t</b>o</p> |
|
15 <p id="quotes">"straight" and “curly” and ‘didn't’ and 'doesn’t'</p> |
|
16 <div id="content" style="display: none"> |
|
17 |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script type="application/javascript"> |
|
21 |
|
22 /** Test for Bug 450048 **/ |
|
23 |
|
24 // Check nsFind class and its nsIFind interface. |
|
25 |
|
26 var rf = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"] |
|
27 .getService(SpecialPowers.Ci.nsIFind); |
|
28 |
|
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; |
|
35 |
|
36 // Check |null| detection on |aPatText| parameter. |
|
37 try { |
|
38 rf.Find(null, searchRange, startPt, endPt); |
|
39 |
|
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 } |
|
49 |
|
50 // Check |null| detection on |aSearchRange| parameter. |
|
51 try { |
|
52 rf.Find("", null, startPt, endPt); |
|
53 |
|
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 } |
|
63 |
|
64 // Check |null| detection on |aStartPoint| parameter. |
|
65 try { |
|
66 rf.Find("", searchRange, null, endPt); |
|
67 |
|
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 } |
|
77 |
|
78 // Check |null| detection on |aEndPoint| parameter. |
|
79 try { |
|
80 rf.Find("", searchRange, startPt, null); |
|
81 |
|
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 } |
|
91 |
|
92 var searchValue, retRange; |
|
93 |
|
94 rf.findBackwards = false; |
|
95 |
|
96 rf.caseSensitive = false; |
|
97 |
|
98 searchValue = "TexT"; |
|
99 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
100 ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)"); |
|
101 |
|
102 rf.caseSensitive = true; |
|
103 |
|
104 // searchValue = "TexT"; |
|
105 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
106 ok(!retRange, "\"" + searchValue + "\" found (caseSensitive)"); |
|
107 |
|
108 searchValue = "text"; |
|
109 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
110 ok(retRange, "\"" + searchValue + "\" not found"); |
|
111 |
|
112 // Matches |i<b>n­t</b>o|. |
|
113 searchValue = "into"; |
|
114 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
115 ok(retRange, "\"" + searchValue + "\" not found"); |
|
116 |
|
117 // Matches inside |search|. |
|
118 searchValue = "ear"; |
|
119 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
120 ok(retRange, "\"" + searchValue + "\" not found"); |
|
121 |
|
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); |
|
126 |
|
127 searchValue = "t"; |
|
128 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
129 ok(retRange, "\"" + searchValue + "\" not found (forward)"); |
|
130 |
|
131 searchValue = "the"; |
|
132 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
133 ok(!retRange, "\"" + searchValue + "\" found (forward)"); |
|
134 |
|
135 rf.findBackwards = true; |
|
136 |
|
137 // searchValue = "the"; |
|
138 retRange = rf.Find(searchValue, searchRange, startPt, endPt); |
|
139 ok(retRange, "\"" + searchValue + "\" not found (backward)"); |
|
140 |
|
141 |
|
142 // Curly quotes and straight quotes should match. |
|
143 |
|
144 rf.caseSensitive = false; |
|
145 rf.findBackwards = false; |
|
146 |
|
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 } |
|
153 |
|
154 function assertFound(node, searchValue) { |
|
155 ok(find(node, searchValue), "\"" + searchValue + "\" not found"); |
|
156 } |
|
157 |
|
158 function assertNotFound(node, searchValue) { |
|
159 ok(!find(node, searchValue), "\"" + searchValue + "\" found"); |
|
160 } |
|
161 |
|
162 var quotes = document.getElementById("quotes"); |
|
163 |
|
164 assertFound(quotes, "\"straight\""); |
|
165 assertFound(quotes, "\u201Cstraight\u201D"); |
|
166 |
|
167 assertNotFound(quotes, "'straight'"); |
|
168 assertNotFound(quotes, "\u2018straight\u2019"); |
|
169 assertNotFound(quotes, "\u2019straight\u2018"); |
|
170 assertNotFound(quotes, ".straight."); |
|
171 |
|
172 assertFound(quotes, "\"curly\""); |
|
173 assertFound(quotes, "\u201Ccurly\u201D"); |
|
174 |
|
175 assertNotFound(quotes, "'curly'"); |
|
176 assertNotFound(quotes, "\u2018curly\u2019"); |
|
177 assertNotFound(quotes, ".curly."); |
|
178 |
|
179 assertFound(quotes, "didn't"); |
|
180 assertFound(quotes, "didn\u2018t"); |
|
181 assertFound(quotes, "didn\u2019t"); |
|
182 |
|
183 assertNotFound(quotes, "didnt"); |
|
184 assertNotFound(quotes, "didn t"); |
|
185 assertNotFound(quotes, "didn.t"); |
|
186 |
|
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"); |
|
197 |
|
198 assertNotFound(quotes, "\"didn't\""); |
|
199 assertNotFound(quotes, "\u201Cdidn't\u201D"); |
|
200 |
|
201 assertFound(quotes, "doesn't"); |
|
202 assertFound(quotes, "doesn\u2018t"); |
|
203 assertFound(quotes, "doesn\u2019t"); |
|
204 |
|
205 assertNotFound(quotes, "doesnt"); |
|
206 assertNotFound(quotes, "doesn t"); |
|
207 assertNotFound(quotes, "doesn.t"); |
|
208 |
|
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"); |
|
219 |
|
220 assertNotFound(quotes, "\"doesn't\""); |
|
221 assertNotFound(quotes, "\u201Cdoesn't\u201D"); |
|
222 </script> |
|
223 </pre> |
|
224 </body> |
|
225 </html> |