summaryrefslogtreecommitdiffstats
path: root/embedding/test/test_nsFind.html
blob: f180cda20f9b6b0871e63e5d62f587c23e2c73bd (plain)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=450048
-->
<head>
  <meta charset="UTF-8">
  <title>Test for nsFind::Find()</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<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&shy;t</b>o</p>
<p id="quotes">"straight" and &ldquo;curly&rdquo; and &lsquo;didn't&rsquo; and 'doesn&rsquo;t'</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 450048 **/

  // Check nsFind class and its nsIFind interface.

  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;

  // Check |null| detection on |aSearchRange| parameter.
  try {
    rf.Find("", null, startPt, endPt);

    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
  } catch (e) {
    e = SpecialPowers.wrap(e);
    if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
      ok(true, null);
    } else {
      throw e;
    }
  }

  // Check |null| detection on |aStartPoint| parameter.
  try {
    rf.Find("", searchRange, null, endPt);

    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
  } catch (e) {
    e = SpecialPowers.wrap(e);
    if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
      ok(true, null);
    } else {
      throw e;
    }
  }

  // Check |null| detection on |aEndPoint| parameter.
  try {
    rf.Find("", searchRange, startPt, null);

    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
  } catch (e) {
    e = SpecialPowers.wrap(e);
    if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
      ok(true, null);
    } else {
      throw e;
    }
  }

  var searchValue, retRange;

  rf.findBackwards = false;

  rf.caseSensitive = false;

  searchValue = "TexT";
  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
  ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");

  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&shy;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.caseSensitive = false;
  rf.findBackwards = false;

  function find(node, searchValue) {
    var range = document.createRange();
    range.setStart(node, 0);
    range.setEnd(node, node.childNodes.length);
    return rf.Find(searchValue, range, range, range);
  }

  function assertFound(node, searchValue) {
    ok(find(node, searchValue), "\"" + searchValue + "\" not found");
  }

  function assertNotFound(node, searchValue) {
    ok(!find(node, searchValue), "\"" + searchValue + "\" 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.caseSensitive = 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'");
</script>
</pre>
</body>
</html>