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

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

Issue 2144673003: Audit the use of updateStyleAndLayoutIgnorePendingStylesheets in SearchBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make sure the tests correctly flush the pipeline. Created 4 years, 5 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/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.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"
11 #include "core/dom/shadow/ShadowRoot.h" 11 #include "core/dom/shadow/ShadowRoot.h"
12 #include "core/frame/FrameHost.h" 12 #include "core/frame/FrameHost.h"
13 #include "core/frame/FrameView.h"
13 #include "core/frame/VisualViewport.h" 14 #include "core/frame/VisualViewport.h"
14 #include "core/html/HTMLElement.h" 15 #include "core/html/HTMLElement.h"
15 #include "core/layout/TextAutosizer.h" 16 #include "core/layout/TextAutosizer.h"
16 #include "core/page/Page.h" 17 #include "core/page/Page.h"
17 #include "platform/testing/TestingPlatformSupport.h" 18 #include "platform/testing/TestingPlatformSupport.h"
18 #include "platform/testing/UnitTestHelpers.h" 19 #include "platform/testing/UnitTestHelpers.h"
19 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
20 #include "public/web/WebDocument.h" 21 #include "public/web/WebDocument.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "web/FindInPageCoordinates.h" 23 #include "web/FindInPageCoordinates.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffse t, Node* endContainer, int endOffset) 64 WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffse t, Node* endContainer, int endOffset)
64 { 65 {
65 Range* range = Range::create(startContainer->document(), startContainer, sta rtOffset, endContainer, endOffset); 66 Range* range = Range::create(startContainer->document(), startContainer, sta rtOffset, endContainer, endOffset);
66 return WebFloatRect(findInPageRectFromRange(range)); 67 return WebFloatRect(findInPageRectFromRange(range));
67 } 68 }
68 69
69 TEST_F(TextFinderTest, FindTextSimple) 70 TEST_F(TextFinderTest, FindTextSimple)
70 { 71 {
71 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 72 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
73 document().view()->updateAllLifecyclePhases();
72 Node* textNode = document().body()->firstChild(); 74 Node* textNode = document().body()->firstChild();
73 75
74 int identifier = 0; 76 int identifier = 0;
75 WebString searchText(String("FindMe")); 77 WebString searchText(String("FindMe"));
76 WebFindOptions findOptions; // Default. 78 WebFindOptions findOptions; // Default.
77 bool wrapWithinFrame = true; 79 bool wrapWithinFrame = true;
78 WebRect* selectionRect = nullptr; 80 WebRect* selectionRect = nullptr;
79 81
80 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 82 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect));
81 Range* activeMatch = textFinder().activeMatch(); 83 Range* activeMatch = textFinder().activeMatch();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ASSERT_TRUE(activeMatch); 133 ASSERT_TRUE(activeMatch);
132 EXPECT_EQ(textNode, activeMatch->startContainer()); 134 EXPECT_EQ(textNode, activeMatch->startContainer());
133 EXPECT_EQ(14, activeMatch->startOffset()); 135 EXPECT_EQ(14, activeMatch->startOffset());
134 EXPECT_EQ(textNode, activeMatch->endContainer()); 136 EXPECT_EQ(textNode, activeMatch->endContainer());
135 EXPECT_EQ(20, activeMatch->endOffset()); 137 EXPECT_EQ(20, activeMatch->endOffset());
136 } 138 }
137 139
138 TEST_F(TextFinderTest, FindTextAutosizing) 140 TEST_F(TextFinderTest, FindTextAutosizing)
139 { 141 {
140 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 142 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
143 document().view()->updateAllLifecyclePhases();
141 144
142 int identifier = 0; 145 int identifier = 0;
143 WebString searchText(String("FindMe")); 146 WebString searchText(String("FindMe"));
144 WebFindOptions findOptions; // Default. 147 WebFindOptions findOptions; // Default.
145 bool wrapWithinFrame = true; 148 bool wrapWithinFrame = true;
146 WebRect* selectionRect = nullptr; 149 WebRect* selectionRect = nullptr;
147 150
148 // Set viewport scale to 20 in order to simulate zoom-in 151 // Set viewport scale to 20 in order to simulate zoom-in
149 VisualViewport& visualViewport = document().page()->frameHost().visualViewpo rt(); 152 VisualViewport& visualViewport = document().page()->frameHost().visualViewpo rt();
150 visualViewport.setScale(20); 153 visualViewport.setScale(20);
151 154
152 // Enforce autosizing 155 // Enforce autosizing
153 document().settings()->setTextAutosizingEnabled(true); 156 document().settings()->setTextAutosizingEnabled(true);
154 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20)); 157 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20));
155 document().textAutosizer()->updatePageInfo(); 158 document().textAutosizer()->updatePageInfo();
159 document().view()->updateAllLifecyclePhases();
156 160
157 // In case of autosizing, scale _should_ change 161 // In case of autosizing, scale _should_ change
158 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 162 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect));
159 ASSERT_TRUE(textFinder().activeMatch()); 163 ASSERT_TRUE(textFinder().activeMatch());
160 ASSERT_EQ(1, visualViewport.scale()); // in this case to 1 164 ASSERT_EQ(1, visualViewport.scale()); // in this case to 1
161 165
162 // Disable autosizing and reset scale to 20 166 // Disable autosizing and reset scale to 20
163 visualViewport.setScale(20); 167 visualViewport.setScale(20);
164 document().settings()->setTextAutosizingEnabled(false); 168 document().settings()->setTextAutosizingEnabled(false);
165 document().textAutosizer()->updatePageInfo(); 169 document().textAutosizer()->updatePageInfo();
170 document().view()->updateAllLifecyclePhases();
166 171
167 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 172 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect));
168 ASSERT_TRUE(textFinder().activeMatch()); 173 ASSERT_TRUE(textFinder().activeMatch());
169 ASSERT_EQ(20, visualViewport.scale()); 174 ASSERT_EQ(20, visualViewport.scale());
170 } 175 }
171 176
172 TEST_F(TextFinderTest, FindTextNotFound) 177 TEST_F(TextFinderTest, FindTextNotFound)
173 { 178 {
174 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 179 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
180 document().view()->updateAllLifecyclePhases();
175 181
176 int identifier = 0; 182 int identifier = 0;
177 WebString searchText(String("Boo")); 183 WebString searchText(String("Boo"));
178 WebFindOptions findOptions; // Default. 184 WebFindOptions findOptions; // Default.
179 bool wrapWithinFrame = true; 185 bool wrapWithinFrame = true;
180 WebRect* selectionRect = nullptr; 186 WebRect* selectionRect = nullptr;
181 187
182 EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWith inFrame, selectionRect)); 188 EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWith inFrame, selectionRect));
183 EXPECT_FALSE(textFinder().activeMatch()); 189 EXPECT_FALSE(textFinder().activeMatch());
184 } 190 }
185 191
186 TEST_F(TextFinderTest, FindTextInShadowDOM) 192 TEST_F(TextFinderTest, FindTextInShadowDOM)
187 { 193 {
188 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ; 194 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ;
189 ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(ShadowR ootType::V0, ASSERT_NO_EXCEPTION); 195 ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(ShadowR ootType::V0, ASSERT_NO_EXCEPTION);
190 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION); 196 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION);
191 Node* textInBElement = document().body()->firstChild()->firstChild(); 197 Node* textInBElement = document().body()->firstChild()->firstChild();
192 Node* textInIElement = document().body()->lastChild()->firstChild(); 198 Node* textInIElement = document().body()->lastChild()->firstChild();
193 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild(); 199 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
200 document().view()->updateAllLifecyclePhases();
194 201
195 int identifier = 0; 202 int identifier = 0;
196 WebString searchText(String("foo")); 203 WebString searchText(String("foo"));
197 WebFindOptions findOptions; // Default. 204 WebFindOptions findOptions; // Default.
198 bool wrapWithinFrame = true; 205 bool wrapWithinFrame = true;
199 WebRect* selectionRect = nullptr; 206 WebRect* selectionRect = nullptr;
200 207
201 // TextIterator currently returns the matches in the flat treeorder, so 208 // TextIterator currently returns the matches in the flat treeorder, so
202 // in this case the matches will be returned in the order of 209 // in this case the matches will be returned in the order of
203 // <i> -> <u> -> <b>. 210 // <i> -> <u> -> <b>.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ASSERT_TRUE(activeMatch); 278 ASSERT_TRUE(activeMatch);
272 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 279 EXPECT_EQ(textInBElement, activeMatch->startContainer());
273 EXPECT_EQ(0, activeMatch->startOffset()); 280 EXPECT_EQ(0, activeMatch->startOffset());
274 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 281 EXPECT_EQ(textInBElement, activeMatch->endContainer());
275 EXPECT_EQ(3, activeMatch->endOffset()); 282 EXPECT_EQ(3, activeMatch->endOffset());
276 } 283 }
277 284
278 TEST_F(TextFinderTest, ScopeTextMatchesSimple) 285 TEST_F(TextFinderTest, ScopeTextMatchesSimple)
279 { 286 {
280 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 287 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
288 document().view()->updateAllLifecyclePhases();
289
281 Node* textNode = document().body()->firstChild(); 290 Node* textNode = document().body()->firstChild();
282 291
283 int identifier = 0; 292 int identifier = 0;
284 WebString searchText(String("FindMe")); 293 WebString searchText(String("FindMe"));
285 WebFindOptions findOptions; // Default. 294 WebFindOptions findOptions; // Default.
286 295
287 textFinder().resetMatchCount(); 296 textFinder().resetMatchCount();
288 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 297 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
289 while (textFinder().scopingInProgress()) 298 while (textFinder().scopingInProgress())
290 runPendingTasks(); 299 runPendingTasks();
291 300
292 EXPECT_EQ(2, textFinder().totalMatchCount()); 301 EXPECT_EQ(2, textFinder().totalMatchCount());
293 WebVector<WebFloatRect> matchRects; 302 WebVector<WebFloatRect> matchRects;
294 textFinder().findMatchRects(matchRects); 303 textFinder().findMatchRects(matchRects);
295 ASSERT_EQ(2u, matchRects.size()); 304 ASSERT_EQ(2u, matchRects.size());
296 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]); 305 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]);
297 EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]); 306 EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]);
298 } 307 }
299 308
300 TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM) 309 TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM)
301 { 310 {
302 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ; 311 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ;
303 ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(ShadowR ootType::V0, ASSERT_NO_EXCEPTION); 312 ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(ShadowR ootType::V0, ASSERT_NO_EXCEPTION);
304 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION); 313 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION);
305 Node* textInBElement = document().body()->firstChild()->firstChild(); 314 Node* textInBElement = document().body()->firstChild()->firstChild();
306 Node* textInIElement = document().body()->lastChild()->firstChild(); 315 Node* textInIElement = document().body()->lastChild()->firstChild();
307 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild(); 316 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
317 document().view()->updateAllLifecyclePhases();
308 318
309 int identifier = 0; 319 int identifier = 0;
310 WebString searchText(String("fOO")); 320 WebString searchText(String("fOO"));
311 WebFindOptions findOptions; // Default. 321 WebFindOptions findOptions; // Default.
312 322
313 textFinder().resetMatchCount(); 323 textFinder().resetMatchCount();
314 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 324 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
315 while (textFinder().scopingInProgress()) 325 while (textFinder().scopingInProgress())
316 runPendingTasks(); 326 runPendingTasks();
317 327
318 // TextIterator currently returns the matches in the flat tree order, 328 // TextIterator currently returns the matches in the flat tree order,
319 // so in this case the matches will be returned in the order of 329 // so in this case the matches will be returned in the order of
320 // <i> -> <u> -> <b>. 330 // <i> -> <u> -> <b>.
321 EXPECT_EQ(3, textFinder().totalMatchCount()); 331 EXPECT_EQ(3, textFinder().totalMatchCount());
322 WebVector<WebFloatRect> matchRects; 332 WebVector<WebFloatRect> matchRects;
323 textFinder().findMatchRects(matchRects); 333 textFinder().findMatchRects(matchRects);
324 ASSERT_EQ(3u, matchRects.size()); 334 ASSERT_EQ(3u, matchRects.size());
325 EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[0 ]); 335 EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[0 ]);
326 EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[1 ]); 336 EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[1 ]);
327 EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[2 ]); 337 EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[2 ]);
328 } 338 }
329 339
330 TEST_F(TextFinderTest, ScopeRepeatPatternTextMatches) 340 TEST_F(TextFinderTest, ScopeRepeatPatternTextMatches)
331 { 341 {
332 document().body()->setInnerHTML("ab ab ab ab ab", ASSERT_NO_EXCEPTION); 342 document().body()->setInnerHTML("ab ab ab ab ab", ASSERT_NO_EXCEPTION);
343 document().view()->updateAllLifecyclePhases();
344
333 Node* textNode = document().body()->firstChild(); 345 Node* textNode = document().body()->firstChild();
334 346
335 int identifier = 0; 347 int identifier = 0;
336 WebString searchText(String("ab ab")); 348 WebString searchText(String("ab ab"));
337 WebFindOptions findOptions; // Default. 349 WebFindOptions findOptions; // Default.
338 350
339 textFinder().resetMatchCount(); 351 textFinder().resetMatchCount();
340 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 352 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
341 while (textFinder().scopingInProgress()) 353 while (textFinder().scopingInProgress())
342 runPendingTasks(); 354 runPendingTasks();
343 355
344 EXPECT_EQ(2, textFinder().totalMatchCount()); 356 EXPECT_EQ(2, textFinder().totalMatchCount());
345 WebVector<WebFloatRect> matchRects; 357 WebVector<WebFloatRect> matchRects;
346 textFinder().findMatchRects(matchRects); 358 textFinder().findMatchRects(matchRects);
347 ASSERT_EQ(2u, matchRects.size()); 359 ASSERT_EQ(2u, matchRects.size());
348 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 5), matchRects[0]); 360 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 5), matchRects[0]);
349 EXPECT_EQ(findInPageRect(textNode, 6, textNode, 11), matchRects[1]); 361 EXPECT_EQ(findInPageRect(textNode, 6, textNode, 11), matchRects[1]);
350 } 362 }
351 363
352 TEST_F(TextFinderTest, OverlappingMatches) 364 TEST_F(TextFinderTest, OverlappingMatches)
353 { 365 {
354 document().body()->setInnerHTML("aababaa", ASSERT_NO_EXCEPTION); 366 document().body()->setInnerHTML("aababaa", ASSERT_NO_EXCEPTION);
367 document().view()->updateAllLifecyclePhases();
esprehn 2016/07/22 05:57:10 I bet almost all of these only need updateLayout()
dglazkov 2016/07/22 16:40:50 Yeah, you're right. Let me replace.
368
355 Node* textNode = document().body()->firstChild(); 369 Node* textNode = document().body()->firstChild();
356 370
357 int identifier = 0; 371 int identifier = 0;
358 WebString searchText(String("aba")); 372 WebString searchText(String("aba"));
359 WebFindOptions findOptions; // Default. 373 WebFindOptions findOptions; // Default.
360 374
361 textFinder().resetMatchCount(); 375 textFinder().resetMatchCount();
362 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 376 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
363 while (textFinder().scopingInProgress()) 377 while (textFinder().scopingInProgress())
364 runPendingTasks(); 378 runPendingTasks();
365 379
366 // We shouldn't find overlapped matches. 380 // We shouldn't find overlapped matches.
367 EXPECT_EQ(1, textFinder().totalMatchCount()); 381 EXPECT_EQ(1, textFinder().totalMatchCount());
368 WebVector<WebFloatRect> matchRects; 382 WebVector<WebFloatRect> matchRects;
369 textFinder().findMatchRects(matchRects); 383 textFinder().findMatchRects(matchRects);
370 ASSERT_EQ(1u, matchRects.size()); 384 ASSERT_EQ(1u, matchRects.size());
371 EXPECT_EQ(findInPageRect(textNode, 1, textNode, 4), matchRects[0]); 385 EXPECT_EQ(findInPageRect(textNode, 1, textNode, 4), matchRects[0]);
372 } 386 }
373 387
374 TEST_F(TextFinderTest, SequentialMatches) 388 TEST_F(TextFinderTest, SequentialMatches)
375 { 389 {
376 document().body()->setInnerHTML("ababab", ASSERT_NO_EXCEPTION); 390 document().body()->setInnerHTML("ababab", ASSERT_NO_EXCEPTION);
391 document().view()->updateAllLifecyclePhases();
392
377 Node* textNode = document().body()->firstChild(); 393 Node* textNode = document().body()->firstChild();
378 394
379 int identifier = 0; 395 int identifier = 0;
380 WebString searchText(String("ab")); 396 WebString searchText(String("ab"));
381 WebFindOptions findOptions; // Default. 397 WebFindOptions findOptions; // Default.
382 398
383 textFinder().resetMatchCount(); 399 textFinder().resetMatchCount();
384 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 400 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
385 while (textFinder().scopingInProgress()) 401 while (textFinder().scopingInProgress())
386 runPendingTasks(); 402 runPendingTasks();
387 403
388 EXPECT_EQ(3, textFinder().totalMatchCount()); 404 EXPECT_EQ(3, textFinder().totalMatchCount());
389 WebVector<WebFloatRect> matchRects; 405 WebVector<WebFloatRect> matchRects;
390 textFinder().findMatchRects(matchRects); 406 textFinder().findMatchRects(matchRects);
391 ASSERT_EQ(3u, matchRects.size()); 407 ASSERT_EQ(3u, matchRects.size());
392 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); 408 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]);
393 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); 409 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]);
394 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); 410 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
395 } 411 }
396 412
397 TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM) 413 TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM)
398 { 414 {
399 document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EX CEPTION); 415 document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EX CEPTION);
416 document().view()->updateAllLifecyclePhases();
400 417
401 int identifier = 0; 418 int identifier = 0;
402 WebString searchText(String("FindMe")); 419 WebString searchText(String("FindMe"));
403 WebFindOptions findOptions; // Default. 420 WebFindOptions findOptions; // Default.
404 bool wrapWithinFrame = true; 421 bool wrapWithinFrame = true;
405 WebRect* selectionRect = nullptr; 422 WebRect* selectionRect = nullptr;
406 bool activeNow; 423 bool activeNow;
407 424
408 textFinder().resetMatchCount(); 425 textFinder().resetMatchCount();
409 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 426 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
410 while (textFinder().scopingInProgress()) 427 while (textFinder().scopingInProgress())
411 runPendingTasks(); 428 runPendingTasks();
412 429
413 findOptions.findNext = true; 430 findOptions.findNext = true;
414 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow)); 431 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
415 EXPECT_TRUE(activeNow); 432 EXPECT_TRUE(activeNow);
416 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow)); 433 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
417 EXPECT_TRUE(activeNow); 434 EXPECT_TRUE(activeNow);
418 435
419 // Add new text to DOM and try FindNext. 436 // Add new text to DOM and try FindNext.
420 Element* iElement = toElement(document().body()->lastChild()); 437 Element* iElement = toElement(document().body()->lastChild());
421 ASSERT_TRUE(iElement); 438 ASSERT_TRUE(iElement);
422 iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION); 439 iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION);
440 document().view()->updateAllLifecyclePhases();
423 441
424 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow)); 442 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
425 Range* activeMatch = textFinder().activeMatch(); 443 Range* activeMatch = textFinder().activeMatch();
426 ASSERT_TRUE(activeMatch); 444 ASSERT_TRUE(activeMatch);
427 EXPECT_FALSE(activeNow); 445 EXPECT_FALSE(activeNow);
428 EXPECT_EQ(2, activeMatch->startOffset()); 446 EXPECT_EQ(2, activeMatch->startOffset());
429 EXPECT_EQ(8, activeMatch->endOffset()); 447 EXPECT_EQ(8, activeMatch->endOffset());
430 448
431 // Restart full search and check that added text is found. 449 // Restart full search and check that added text is found.
432 findOptions.findNext = false; 450 findOptions.findNext = false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 String text(Vector<UChar>(100)); 496 String text(Vector<UChar>(100));
479 text.fill('a'); 497 text.fill('a');
480 String searchPattern("abc"); 498 String searchPattern("abc");
481 // Make 4 substrings "abc" in text. 499 // Make 4 substrings "abc" in text.
482 text.insert(searchPattern, 1); 500 text.insert(searchPattern, 1);
483 text.insert(searchPattern, 10); 501 text.insert(searchPattern, 10);
484 text.insert(searchPattern, 50); 502 text.insert(searchPattern, 50);
485 text.insert(searchPattern, 90); 503 text.insert(searchPattern, 90);
486 504
487 document().body()->setInnerHTML(text, ASSERT_NO_EXCEPTION); 505 document().body()->setInnerHTML(text, ASSERT_NO_EXCEPTION);
506 document().view()->updateAllLifecyclePhases();
488 507
489 int identifier = 0; 508 int identifier = 0;
490 WebFindOptions findOptions; // Default. 509 WebFindOptions findOptions; // Default.
491 510
492 textFinder().resetMatchCount(); 511 textFinder().resetMatchCount();
493 512
494 // There will be only one iteration before timeout, because increment 513 // There will be only one iteration before timeout, because increment
495 // of the TimeProxyPlatform timer is greater than timeout threshold. 514 // of the TimeProxyPlatform timer is greater than timeout threshold.
496 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); 515 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true );
497 while (textFinder().scopingInProgress()) 516 while (textFinder().scopingInProgress())
498 runPendingTasks(); 517 runPendingTasks();
499 518
500 EXPECT_EQ(4, textFinder().totalMatchCount()); 519 EXPECT_EQ(4, textFinder().totalMatchCount());
501 } 520 }
502 521
503 } // namespace blink 522 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698