1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=202251
https://bugzilla.mozilla.org/show_bug.cgi?id=450048
https://bugzilla.mozilla.org/show_bug.cgi?id=812837
https://bugzilla.mozilla.org/show_bug.cgi?id=969980
https://bugzilla.mozilla.org/show_bug.cgi?id=1589786
https://bugzilla.mozilla.org/show_bug.cgi?id=1611568
https://bugzilla.mozilla.org/show_bug.cgi?id=1649187
https://bugzilla.mozilla.org/show_bug.cgi?id=1699599
-->
<head>
<meta charset="UTF-8">
<title>Test for nsFind::Find()</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
async function runTests() {
// Check nsFind class and its nsIFind interface.
// Inject some text that we'll search for later.
const NULL_CHARACTER = "\0";
const INJECTED_NULL_TEXT = "injected null\0";
const nullcharsinjected = document.getElementById("nullcharsinjected");
const nulltextnode = document.createTextNode(INJECTED_NULL_TEXT);
nullcharsinjected.appendChild(nulltextnode);
// Take steps to ensure that the frame is created for the newly added
// nulltextnode. Our find code is dependent upon finding visible frames.
// One way to ensure the frame exists is to ask for its bounds.
const injectionBounds = nullcharsinjected.getBoundingClientRect();
ok(injectionBounds, "Got a bounding rect for the injected text container.");
var rf = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"]
.getService(SpecialPowers.Ci.nsIFind);
var display = window.document.getElementById("display");
var searchRange = window.document.createRange();
searchRange.setStart(display, 0);
searchRange.setEnd(display, display.childNodes.length);
var startPt = searchRange;
var endPt = searchRange;
var searchValue, retRange;
rf.findBackwards = false;
rf.caseSensitive = false;
rf.matchDiacritics = false;
rf.entireWord = false;
searchValue = "TexT";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "λογος";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "유";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (not caseSensitive)");
searchValue = "కె";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (not caseSensitive)");
searchValue = "𑂥";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "istanbul";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "wroclaw";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "goteborg";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "degrees k";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "≠";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (not caseSensitive)");
searchValue = "guahe";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "g̃uah̰e";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "𐐸𐐯𐑊𐐬";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
searchValue = "東京駅"
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found");
rf.matchDiacritics = true;
searchValue = "λογος";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (matchDiacritics on)");
searchValue = "g̃uahe";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (matchDiacritics on)");
searchValue = "guahe";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (matchDiacritics on)");
rf.caseSensitive = true;
searchValue = "TexT";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (caseSensitive)");
searchValue = "text";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found");
// Matches |i<b>n­t</b>o|.
searchValue = "into";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found");
// Matches inside |search|.
searchValue = "ear";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found");
// Set new start point (to end of last search).
startPt = retRange.endContainer.ownerDocument.createRange();
startPt.setStart(retRange.endContainer, retRange.endOffset);
startPt.setEnd(retRange.endContainer, retRange.endOffset);
searchValue = "t";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (forward)");
searchValue = "the";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(!retRange, "\"" + searchValue + "\" found (forward)");
rf.findBackwards = true;
// searchValue = "the";
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (backward)");
// Curly quotes and straight quotes should match.
rf.matchDiacritics = false;
rf.findBackwards = false;
function find(node, value) {
var range = document.createRange();
range.setStart(node, 0);
range.setEnd(node, node.childNodes.length);
return rf.Find(value, range, range, range);
}
function assertFound(node, value) {
ok(find(node, value), "\"" + value + "\" should be found");
}
function assertNotFound(node, value) {
ok(!find(node, value), "\"" + value + "\" should not be found");
}
var quotes = document.getElementById("quotes");
assertFound(quotes, "\"straight\"");
assertFound(quotes, "\u201Cstraight\u201D");
assertNotFound(quotes, "'straight'");
assertNotFound(quotes, "\u2018straight\u2019");
assertNotFound(quotes, "\u2019straight\u2018");
assertNotFound(quotes, ".straight.");
assertFound(quotes, "\"curly\"");
assertFound(quotes, "\u201Ccurly\u201D");
assertNotFound(quotes, "'curly'");
assertNotFound(quotes, "\u2018curly\u2019");
assertNotFound(quotes, ".curly.");
assertFound(quotes, "didn't");
assertFound(quotes, "didn\u2018t");
assertFound(quotes, "didn\u2019t");
assertNotFound(quotes, "didnt");
assertNotFound(quotes, "didn t");
assertNotFound(quotes, "didn.t");
assertFound(quotes, "'didn't'");
assertFound(quotes, "'didn\u2018t'");
assertFound(quotes, "'didn\u2019t'");
assertFound(quotes, "\u2018didn't\u2019");
assertFound(quotes, "\u2019didn't\u2018");
assertFound(quotes, "\u2018didn't\u2018");
assertFound(quotes, "\u2019didn't\u2019");
assertFound(quotes, "\u2018didn\u2019t\u2019");
assertFound(quotes, "\u2019didn\u2018t\u2019");
assertFound(quotes, "\u2018didn\u2019t\u2018");
assertNotFound(quotes, "\"didn't\"");
assertNotFound(quotes, "\u201Cdidn't\u201D");
assertFound(quotes, "doesn't");
assertFound(quotes, "doesn\u2018t");
assertFound(quotes, "doesn\u2019t");
assertNotFound(quotes, "doesnt");
assertNotFound(quotes, "doesn t");
assertNotFound(quotes, "doesn.t");
assertFound(quotes, "'doesn't'");
assertFound(quotes, "'doesn\u2018t'");
assertFound(quotes, "'doesn\u2019t'");
assertFound(quotes, "\u2018doesn't\u2019");
assertFound(quotes, "\u2019doesn't\u2018");
assertFound(quotes, "\u2018doesn't\u2018");
assertFound(quotes, "\u2019doesn't\u2019");
assertFound(quotes, "\u2018doesn\u2019t\u2019");
assertFound(quotes, "\u2019doesn\u2018t\u2019");
assertFound(quotes, "\u2018doesn\u2019t\u2018");
assertNotFound(quotes, "\"doesn't\"");
assertNotFound(quotes, "\u201Cdoesn't\u201D");
// Curly quotes and straight quotes should not match.
rf.matchDiacritics = true;
assertFound(quotes, "\"straight\"");
assertNotFound(quotes, "\u201Cstraight\u201D");
assertNotFound(quotes, "\"curly\"");
assertFound(quotes, "\u201Ccurly\u201D");
assertFound(quotes, "\u2018didn't\u2019");
assertNotFound(quotes, "'didn't'");
assertFound(quotes, "'doesn\u2019t'");
assertNotFound(quotes, "'doesn\u2018t'");
assertNotFound(quotes, "'doesn't'");
// Embedded strings containing null characters can't be found, because
// the HTML parser converts them to \ufffd, which is the replacement
// character.
const nullcharsnative = document.getElementById("nullcharsnative");
assertFound(nullcharsnative, "native null\ufffd");
// Injected strings containing null characters can be found.
assertFound(nullcharsinjected, NULL_CHARACTER);
assertFound(nullcharsinjected, INJECTED_NULL_TEXT);
// Content skipped via content-visibility can't be found.
assertNotFound(quotes, "Tardigrade");
assertNotFound(quotes, "Amoeba");
// Simple checks for behavior of the entireWord option.
var entireWord = document.getElementById("entireWord");
rf.entireWord = true;
assertFound(entireWord, "one");
assertNotFound(entireWord, "on");
assertFound(entireWord, "(one)");
assertFound(entireWord, "two");
assertFound(entireWord, "[two]");
assertFound(entireWord, "[three]");
assertFound(entireWord, "foo");
assertFound(entireWord, "-foo");
assertFound(entireWord, "bar");
assertFound(entireWord, "-bar");
assertNotFound(entireWord, "-fo");
assertNotFound(entireWord, "-ba");
rf.entireWord = false;
assertFound(entireWord, "on");
assertFound(entireWord, "-fo");
assertFound(entireWord, "-ba");
// Searching in elements with display: table-*, bug 1645990
var table = document.getElementById("tabular");
assertFound(table, "One");
assertFound(table, "TwoThree"); // across adjacent cells
assertNotFound(table, "wordsanother"); // not across rows
rf.entireWord = true;
assertNotFound(table, "One"); // because nothing separates it from next cell
assertFound(table, "several");
assertFound(table, "whole");
assertFound(table, "words");
rf.entireWord = false;
// Do these test at the end since they trigger failure screenshots in
// the test harness, and we want as much information as possible about
// any OTHER tests that may have already failed.
// Check |null| detection on |aSearchRange| parameter.
try {
rf.Find("", null, startPt, endPt);
ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
} catch (e) {
let wrappedError = SpecialPowers.wrap(e);
if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
ok(true, null);
} else {
throw wrappedError;
}
}
// Check |null| detection on |aStartPoint| parameter.
try {
rf.Find("", searchRange, null, endPt);
ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
} catch (e) {
let wrappedError = SpecialPowers.wrap(e);
if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
ok(true, null);
} else {
throw wrappedError;
}
}
// Check |null| detection on |aEndPoint| parameter.
try {
rf.Find("", searchRange, startPt, null);
ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
} catch (e) {
let wrappedError = SpecialPowers.wrap(e);
if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
ok(true, null);
} else {
throw wrappedError;
}
}
SimpleTest.finish();
}
</script>
<style>
#tabular { display: table; }
#tabular div { display: table-row; }
#tabular div div { display: table-cell; }
</style>
</head>
<body onload="runTests()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450048">Mozilla Bug 450048</a>
<p id="display">This is the text to search i<b>n­t</b>o</p>
<p id="quotes">"straight" and “curly” and ‘didn't’ and 'doesn’t'</p>
<p id="nullcharsnative">native null�</p>
<p id="nullcharsinjected"></p>
<p id="greek">ΛΌΓΟΣ</p>
<p id="korean">위</p>
<p id="telugu">కై</p>
<p id="kaithi">𑂫</p>
<p id="turkish">İstanbul</p>
<p id="polish">Wrocław</p>
<p id="norwegian">Gøteborg</p>
<p id="kelvin">degrees K</p>
<p id="math">=</p>
<p id="guarani">G̃uahe</p>
<p id="deseret">𐐐𐐯𐑊𐐬 𐐶𐐯𐑉𐑊𐐼!</p>
<p id="ruby"><ruby>東<rt>とう</rt></ruby><ruby>京<rt>きょう</ruby>駅</p>
<div id="content-visibility-hidden" style="content-visibility: hidden">
Tardigrade
<div>Amoeba</div>
</div>
<div id="entireWord"><p>(one)</p><p>[two] [three]</p><p>-foo -bar</p></div>
<div id="content" style="display: none">
</div>
<div id="tabular">
<div><div>One</div><div>Two</div><div>Three</div></div>
<div><div></div><div></div><div>several whole words</div></div>
<div><div>one</div><div>more</div><div>row</div></div>
</div>
<pre id="test">
</pre>
</body>
</html>
|