Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: third_party/WebKit/Source/web/tests/TextFinderTest.cpp

Issue 2701413003: Range: node offsets should be unsigned. (Closed)
Patch Set: Resolve std::numeric_limits<int>::max() leftover Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/TextFinder.h" 5 #include "web/TextFinder.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/NodeList.h" 9 #include "core/dom/NodeList.h"
10 #include "core/dom/Range.h" 10 #include "core/dom/Range.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 int identifier = 0; 78 int identifier = 0;
79 WebString searchText(String("FindMe")); 79 WebString searchText(String("FindMe"));
80 WebFindOptions findOptions; // Default. 80 WebFindOptions findOptions; // Default.
81 bool wrapWithinFrame = true; 81 bool wrapWithinFrame = true;
82 82
83 ASSERT_TRUE( 83 ASSERT_TRUE(
84 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 84 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
85 Range* activeMatch = textFinder().activeMatch(); 85 Range* activeMatch = textFinder().activeMatch();
86 ASSERT_TRUE(activeMatch); 86 ASSERT_TRUE(activeMatch);
87 EXPECT_EQ(textNode, activeMatch->startContainer()); 87 EXPECT_EQ(textNode, activeMatch->startContainer());
88 EXPECT_EQ(4, activeMatch->startOffset()); 88 EXPECT_EQ(4u, activeMatch->startOffset());
89 EXPECT_EQ(textNode, activeMatch->endContainer()); 89 EXPECT_EQ(textNode, activeMatch->endContainer());
90 EXPECT_EQ(10, activeMatch->endOffset()); 90 EXPECT_EQ(10u, activeMatch->endOffset());
91 91
92 findOptions.findNext = true; 92 findOptions.findNext = true;
93 ASSERT_TRUE( 93 ASSERT_TRUE(
94 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 94 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
95 activeMatch = textFinder().activeMatch(); 95 activeMatch = textFinder().activeMatch();
96 ASSERT_TRUE(activeMatch); 96 ASSERT_TRUE(activeMatch);
97 EXPECT_EQ(textNode, activeMatch->startContainer()); 97 EXPECT_EQ(textNode, activeMatch->startContainer());
98 EXPECT_EQ(14, activeMatch->startOffset()); 98 EXPECT_EQ(14u, activeMatch->startOffset());
99 EXPECT_EQ(textNode, activeMatch->endContainer()); 99 EXPECT_EQ(textNode, activeMatch->endContainer());
100 EXPECT_EQ(20, activeMatch->endOffset()); 100 EXPECT_EQ(20u, activeMatch->endOffset());
101 101
102 // Should wrap to the first match. 102 // Should wrap to the first match.
103 ASSERT_TRUE( 103 ASSERT_TRUE(
104 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 104 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
105 activeMatch = textFinder().activeMatch(); 105 activeMatch = textFinder().activeMatch();
106 ASSERT_TRUE(activeMatch); 106 ASSERT_TRUE(activeMatch);
107 EXPECT_EQ(textNode, activeMatch->startContainer()); 107 EXPECT_EQ(textNode, activeMatch->startContainer());
108 EXPECT_EQ(4, activeMatch->startOffset()); 108 EXPECT_EQ(4u, activeMatch->startOffset());
109 EXPECT_EQ(textNode, activeMatch->endContainer()); 109 EXPECT_EQ(textNode, activeMatch->endContainer());
110 EXPECT_EQ(10, activeMatch->endOffset()); 110 EXPECT_EQ(10u, activeMatch->endOffset());
111 111
112 // Search in the reverse order. 112 // Search in the reverse order.
113 identifier = 1; 113 identifier = 1;
114 findOptions = WebFindOptions(); 114 findOptions = WebFindOptions();
115 findOptions.forward = false; 115 findOptions.forward = false;
116 116
117 ASSERT_TRUE( 117 ASSERT_TRUE(
118 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 118 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
119 activeMatch = textFinder().activeMatch(); 119 activeMatch = textFinder().activeMatch();
120 ASSERT_TRUE(activeMatch); 120 ASSERT_TRUE(activeMatch);
121 EXPECT_EQ(textNode, activeMatch->startContainer()); 121 EXPECT_EQ(textNode, activeMatch->startContainer());
122 EXPECT_EQ(14, activeMatch->startOffset()); 122 EXPECT_EQ(14u, activeMatch->startOffset());
123 EXPECT_EQ(textNode, activeMatch->endContainer()); 123 EXPECT_EQ(textNode, activeMatch->endContainer());
124 EXPECT_EQ(20, activeMatch->endOffset()); 124 EXPECT_EQ(20u, activeMatch->endOffset());
125 125
126 findOptions.findNext = true; 126 findOptions.findNext = true;
127 ASSERT_TRUE( 127 ASSERT_TRUE(
128 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 128 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
129 activeMatch = textFinder().activeMatch(); 129 activeMatch = textFinder().activeMatch();
130 ASSERT_TRUE(activeMatch); 130 ASSERT_TRUE(activeMatch);
131 EXPECT_EQ(textNode, activeMatch->startContainer()); 131 EXPECT_EQ(textNode, activeMatch->startContainer());
132 EXPECT_EQ(4, activeMatch->startOffset()); 132 EXPECT_EQ(4u, activeMatch->startOffset());
133 EXPECT_EQ(textNode, activeMatch->endContainer()); 133 EXPECT_EQ(textNode, activeMatch->endContainer());
134 EXPECT_EQ(10, activeMatch->endOffset()); 134 EXPECT_EQ(10u, activeMatch->endOffset());
135 135
136 // Wrap to the first match (last occurence in the document). 136 // Wrap to the first match (last occurence in the document).
137 ASSERT_TRUE( 137 ASSERT_TRUE(
138 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 138 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
139 activeMatch = textFinder().activeMatch(); 139 activeMatch = textFinder().activeMatch();
140 ASSERT_TRUE(activeMatch); 140 ASSERT_TRUE(activeMatch);
141 EXPECT_EQ(textNode, activeMatch->startContainer()); 141 EXPECT_EQ(textNode, activeMatch->startContainer());
142 EXPECT_EQ(14, activeMatch->startOffset()); 142 EXPECT_EQ(14u, activeMatch->startOffset());
143 EXPECT_EQ(textNode, activeMatch->endContainer()); 143 EXPECT_EQ(textNode, activeMatch->endContainer());
144 EXPECT_EQ(20, activeMatch->endOffset()); 144 EXPECT_EQ(20u, activeMatch->endOffset());
145 } 145 }
146 146
147 TEST_F(TextFinderTest, FindTextAutosizing) { 147 TEST_F(TextFinderTest, FindTextAutosizing) {
148 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ"); 148 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ");
149 document().updateStyleAndLayout(); 149 document().updateStyleAndLayout();
150 150
151 int identifier = 0; 151 int identifier = 0;
152 WebString searchText(String("FindMe")); 152 WebString searchText(String("FindMe"));
153 WebFindOptions findOptions; // Default. 153 WebFindOptions findOptions; // Default.
154 bool wrapWithinFrame = true; 154 bool wrapWithinFrame = true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 bool wrapWithinFrame = true; 213 bool wrapWithinFrame = true;
214 214
215 // TextIterator currently returns the matches in the flat treeorder, so 215 // TextIterator currently returns the matches in the flat treeorder, so
216 // in this case the matches will be returned in the order of 216 // in this case the matches will be returned in the order of
217 // <i> -> <u> -> <b>. 217 // <i> -> <u> -> <b>.
218 ASSERT_TRUE( 218 ASSERT_TRUE(
219 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 219 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
220 Range* activeMatch = textFinder().activeMatch(); 220 Range* activeMatch = textFinder().activeMatch();
221 ASSERT_TRUE(activeMatch); 221 ASSERT_TRUE(activeMatch);
222 EXPECT_EQ(textInIElement, activeMatch->startContainer()); 222 EXPECT_EQ(textInIElement, activeMatch->startContainer());
223 EXPECT_EQ(0, activeMatch->startOffset()); 223 EXPECT_EQ(0u, activeMatch->startOffset());
224 EXPECT_EQ(textInIElement, activeMatch->endContainer()); 224 EXPECT_EQ(textInIElement, activeMatch->endContainer());
225 EXPECT_EQ(3, activeMatch->endOffset()); 225 EXPECT_EQ(3u, activeMatch->endOffset());
226 226
227 findOptions.findNext = true; 227 findOptions.findNext = true;
228 ASSERT_TRUE( 228 ASSERT_TRUE(
229 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 229 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
230 activeMatch = textFinder().activeMatch(); 230 activeMatch = textFinder().activeMatch();
231 ASSERT_TRUE(activeMatch); 231 ASSERT_TRUE(activeMatch);
232 EXPECT_EQ(textInUElement, activeMatch->startContainer()); 232 EXPECT_EQ(textInUElement, activeMatch->startContainer());
233 EXPECT_EQ(0, activeMatch->startOffset()); 233 EXPECT_EQ(0u, activeMatch->startOffset());
234 EXPECT_EQ(textInUElement, activeMatch->endContainer()); 234 EXPECT_EQ(textInUElement, activeMatch->endContainer());
235 EXPECT_EQ(3, activeMatch->endOffset()); 235 EXPECT_EQ(3u, activeMatch->endOffset());
236 236
237 ASSERT_TRUE( 237 ASSERT_TRUE(
238 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 238 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
239 activeMatch = textFinder().activeMatch(); 239 activeMatch = textFinder().activeMatch();
240 ASSERT_TRUE(activeMatch); 240 ASSERT_TRUE(activeMatch);
241 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 241 EXPECT_EQ(textInBElement, activeMatch->startContainer());
242 EXPECT_EQ(0, activeMatch->startOffset()); 242 EXPECT_EQ(0u, activeMatch->startOffset());
243 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 243 EXPECT_EQ(textInBElement, activeMatch->endContainer());
244 EXPECT_EQ(3, activeMatch->endOffset()); 244 EXPECT_EQ(3u, activeMatch->endOffset());
245 245
246 // Should wrap to the first match. 246 // Should wrap to the first match.
247 ASSERT_TRUE( 247 ASSERT_TRUE(
248 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 248 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
249 activeMatch = textFinder().activeMatch(); 249 activeMatch = textFinder().activeMatch();
250 ASSERT_TRUE(activeMatch); 250 ASSERT_TRUE(activeMatch);
251 EXPECT_EQ(textInIElement, activeMatch->startContainer()); 251 EXPECT_EQ(textInIElement, activeMatch->startContainer());
252 EXPECT_EQ(0, activeMatch->startOffset()); 252 EXPECT_EQ(0u, activeMatch->startOffset());
253 EXPECT_EQ(textInIElement, activeMatch->endContainer()); 253 EXPECT_EQ(textInIElement, activeMatch->endContainer());
254 EXPECT_EQ(3, activeMatch->endOffset()); 254 EXPECT_EQ(3u, activeMatch->endOffset());
255 255
256 // Fresh search in the reverse order. 256 // Fresh search in the reverse order.
257 identifier = 1; 257 identifier = 1;
258 findOptions = WebFindOptions(); 258 findOptions = WebFindOptions();
259 findOptions.forward = false; 259 findOptions.forward = false;
260 260
261 ASSERT_TRUE( 261 ASSERT_TRUE(
262 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 262 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
263 activeMatch = textFinder().activeMatch(); 263 activeMatch = textFinder().activeMatch();
264 ASSERT_TRUE(activeMatch); 264 ASSERT_TRUE(activeMatch);
265 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 265 EXPECT_EQ(textInBElement, activeMatch->startContainer());
266 EXPECT_EQ(0, activeMatch->startOffset()); 266 EXPECT_EQ(0u, activeMatch->startOffset());
267 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 267 EXPECT_EQ(textInBElement, activeMatch->endContainer());
268 EXPECT_EQ(3, activeMatch->endOffset()); 268 EXPECT_EQ(3u, activeMatch->endOffset());
269 269
270 findOptions.findNext = true; 270 findOptions.findNext = true;
271 ASSERT_TRUE( 271 ASSERT_TRUE(
272 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 272 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
273 activeMatch = textFinder().activeMatch(); 273 activeMatch = textFinder().activeMatch();
274 ASSERT_TRUE(activeMatch); 274 ASSERT_TRUE(activeMatch);
275 EXPECT_EQ(textInUElement, activeMatch->startContainer()); 275 EXPECT_EQ(textInUElement, activeMatch->startContainer());
276 EXPECT_EQ(0, activeMatch->startOffset()); 276 EXPECT_EQ(0u, activeMatch->startOffset());
277 EXPECT_EQ(textInUElement, activeMatch->endContainer()); 277 EXPECT_EQ(textInUElement, activeMatch->endContainer());
278 EXPECT_EQ(3, activeMatch->endOffset()); 278 EXPECT_EQ(3u, activeMatch->endOffset());
279 279
280 ASSERT_TRUE( 280 ASSERT_TRUE(
281 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 281 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
282 activeMatch = textFinder().activeMatch(); 282 activeMatch = textFinder().activeMatch();
283 ASSERT_TRUE(activeMatch); 283 ASSERT_TRUE(activeMatch);
284 EXPECT_EQ(textInIElement, activeMatch->startContainer()); 284 EXPECT_EQ(textInIElement, activeMatch->startContainer());
285 EXPECT_EQ(0, activeMatch->startOffset()); 285 EXPECT_EQ(0u, activeMatch->startOffset());
286 EXPECT_EQ(textInIElement, activeMatch->endContainer()); 286 EXPECT_EQ(textInIElement, activeMatch->endContainer());
287 EXPECT_EQ(3, activeMatch->endOffset()); 287 EXPECT_EQ(3u, activeMatch->endOffset());
288 288
289 // And wrap. 289 // And wrap.
290 ASSERT_TRUE( 290 ASSERT_TRUE(
291 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame)); 291 textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
292 activeMatch = textFinder().activeMatch(); 292 activeMatch = textFinder().activeMatch();
293 ASSERT_TRUE(activeMatch); 293 ASSERT_TRUE(activeMatch);
294 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 294 EXPECT_EQ(textInBElement, activeMatch->startContainer());
295 EXPECT_EQ(0, activeMatch->startOffset()); 295 EXPECT_EQ(0u, activeMatch->startOffset());
296 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 296 EXPECT_EQ(textInBElement, activeMatch->endContainer());
297 EXPECT_EQ(3, activeMatch->endOffset()); 297 EXPECT_EQ(3u, activeMatch->endOffset());
298 } 298 }
299 299
300 TEST_F(TextFinderTest, ScopeTextMatchesSimple) { 300 TEST_F(TextFinderTest, ScopeTextMatchesSimple) {
301 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ"); 301 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ");
302 document().updateStyleAndLayout(); 302 document().updateStyleAndLayout();
303 303
304 Node* textNode = document().body()->firstChild(); 304 Node* textNode = document().body()->firstChild();
305 305
306 int identifier = 0; 306 int identifier = 0;
307 WebString searchText(String("FindMe")); 307 WebString searchText(String("FindMe"));
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 Element* iElement = toElement(document().body()->lastChild()); 478 Element* iElement = toElement(document().body()->lastChild());
479 ASSERT_TRUE(iElement); 479 ASSERT_TRUE(iElement);
480 iElement->setInnerHTML("ZZFindMe"); 480 iElement->setInnerHTML("ZZFindMe");
481 document().updateStyleAndLayout(); 481 document().updateStyleAndLayout();
482 482
483 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, 483 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions,
484 wrapWithinFrame, &activeNow)); 484 wrapWithinFrame, &activeNow));
485 Range* activeMatch = textFinder().activeMatch(); 485 Range* activeMatch = textFinder().activeMatch();
486 ASSERT_TRUE(activeMatch); 486 ASSERT_TRUE(activeMatch);
487 EXPECT_FALSE(activeNow); 487 EXPECT_FALSE(activeNow);
488 EXPECT_EQ(2, activeMatch->startOffset()); 488 EXPECT_EQ(2u, activeMatch->startOffset());
489 EXPECT_EQ(8, activeMatch->endOffset()); 489 EXPECT_EQ(8u, activeMatch->endOffset());
490 490
491 // Restart full search and check that added text is found. 491 // Restart full search and check that added text is found.
492 findOptions.findNext = false; 492 findOptions.findNext = false;
493 textFinder().resetMatchCount(); 493 textFinder().resetMatchCount();
494 textFinder().cancelPendingScopingEffort(); 494 textFinder().cancelPendingScopingEffort();
495 textFinder().startScopingStringMatches(identifier, searchText, findOptions); 495 textFinder().startScopingStringMatches(identifier, searchText, findOptions);
496 while (textFinder().scopingInProgress()) 496 while (textFinder().scopingInProgress())
497 runPendingTasks(); 497 runPendingTasks();
498 EXPECT_EQ(2, textFinder().totalMatchCount()); 498 EXPECT_EQ(2, textFinder().totalMatchCount());
499 499
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 Element* iElement = toElement(document().body()->lastChild()); 532 Element* iElement = toElement(document().body()->lastChild());
533 ASSERT_TRUE(iElement); 533 ASSERT_TRUE(iElement);
534 iElement->setInnerHTML("ZZFindMe"); 534 iElement->setInnerHTML("ZZFindMe");
535 document().updateStyleAndLayout(); 535 document().updateStyleAndLayout();
536 536
537 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, 537 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions,
538 wrapWithinFrame, &activeNow)); 538 wrapWithinFrame, &activeNow));
539 Range* activeMatch = textFinder().activeMatch(); 539 Range* activeMatch = textFinder().activeMatch();
540 ASSERT_TRUE(activeMatch); 540 ASSERT_TRUE(activeMatch);
541 EXPECT_FALSE(activeNow); 541 EXPECT_FALSE(activeNow);
542 EXPECT_EQ(2, activeMatch->startOffset()); 542 EXPECT_EQ(2u, activeMatch->startOffset());
543 EXPECT_EQ(8, activeMatch->endOffset()); 543 EXPECT_EQ(8u, activeMatch->endOffset());
544 544
545 // Restart full search and check that added text is found. 545 // Restart full search and check that added text is found.
546 findOptions.findNext = false; 546 findOptions.findNext = false;
547 textFinder().resetMatchCount(); 547 textFinder().resetMatchCount();
548 textFinder().cancelPendingScopingEffort(); 548 textFinder().cancelPendingScopingEffort();
549 textFinder().startScopingStringMatches(identifier, searchText, findOptions); 549 textFinder().startScopingStringMatches(identifier, searchText, findOptions);
550 while (textFinder().scopingInProgress()) 550 while (textFinder().scopingInProgress())
551 runPendingTasks(); 551 runPendingTasks();
552 EXPECT_EQ(1, textFinder().totalMatchCount()); 552 EXPECT_EQ(1, textFinder().totalMatchCount());
553 553
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 // of the TimeProxyPlatform timer is greater than timeout threshold. 605 // of the TimeProxyPlatform timer is greater than timeout threshold.
606 textFinder().startScopingStringMatches(identifier, searchPattern, 606 textFinder().startScopingStringMatches(identifier, searchPattern,
607 findOptions); 607 findOptions);
608 while (textFinder().scopingInProgress()) 608 while (textFinder().scopingInProgress())
609 runPendingTasks(); 609 runPendingTasks();
610 610
611 EXPECT_EQ(4, textFinder().totalMatchCount()); 611 EXPECT_EQ(4, textFinder().totalMatchCount());
612 } 612 }
613 613
614 } // namespace blink 614 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698