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

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

Issue 1605863002: Restart search in page when new text is found. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added default value for local var Created 4 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/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"
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 EXPECT_EQ(3, textFinder().totalMatchCount()); 388 EXPECT_EQ(3, textFinder().totalMatchCount());
389 WebVector<WebFloatRect> matchRects; 389 WebVector<WebFloatRect> matchRects;
390 textFinder().findMatchRects(matchRects); 390 textFinder().findMatchRects(matchRects);
391 ASSERT_EQ(3u, matchRects.size()); 391 ASSERT_EQ(3u, matchRects.size());
392 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); 392 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]);
393 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); 393 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]);
394 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); 394 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
395 } 395 }
396 396
397 TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM)
398 {
399 document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EX CEPTION);
400
401 int identifier = 0;
402 WebString searchText(String("FindMe"));
403 WebFindOptions findOptions; // Default.
404 bool wrapWithinFrame = true;
405 WebRect* selectionRect = nullptr;
406 bool activeNow;
407
408 textFinder().resetMatchCount();
409 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
410 while (textFinder().scopingInProgress())
411 runPendingTasks();
412
413 findOptions.findNext = true;
414 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
415 EXPECT_TRUE(activeNow);
416 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
417 EXPECT_TRUE(activeNow);
418
419 // Add new text to DOM and try FindNext.
420 Element* iElement = toElement(document().body()->lastChild());
421 ASSERT_TRUE(iElement);
422 iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION);
423
424 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
425 Range* activeMatch = textFinder().activeMatch();
426 ASSERT_TRUE(activeMatch);
427 EXPECT_FALSE(activeNow);
428 EXPECT_EQ(2, activeMatch->startOffset());
429 EXPECT_EQ(8, activeMatch->endOffset());
430
431 // Restart full search and check that added text is found.
432 findOptions.findNext = false;
433 textFinder().resetMatchCount();
434 textFinder().cancelPendingScopingEffort();
435 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
436 while (textFinder().scopingInProgress())
437 runPendingTasks();
438 EXPECT_EQ(2, textFinder().totalMatchCount());
439
440 WebVector<WebFloatRect> matchRects;
441 textFinder().findMatchRects(matchRects);
442 ASSERT_EQ(2u, matchRects.size());
443 Node* textInBElement = document().body()->firstChild()->firstChild();
444 Node* textInIElement = document().body()->lastChild()->firstChild();
445 EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10), matchRects[ 0]);
446 EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8), matchRects[1 ]);
447 }
448
397 class TextFinderFakeTimerTest : public TextFinderTest { 449 class TextFinderFakeTimerTest : public TextFinderTest {
398 protected: 450 protected:
399 void SetUp() override 451 void SetUp() override
400 { 452 {
401 s_timeElapsed = 0.0; 453 s_timeElapsed = 0.0;
402 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); 454 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime);
403 } 455 }
404 456
405 void TearDown() override 457 void TearDown() override
406 { 458 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // There will be only one iteration before timeout, because increment 494 // There will be only one iteration before timeout, because increment
443 // of the TimeProxyPlatform timer is greater than timeout threshold. 495 // of the TimeProxyPlatform timer is greater than timeout threshold.
444 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); 496 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true );
445 while (textFinder().scopingInProgress()) 497 while (textFinder().scopingInProgress())
446 runPendingTasks(); 498 runPendingTasks();
447 499
448 EXPECT_EQ(4, textFinder().totalMatchCount()); 500 EXPECT_EQ(4, textFinder().totalMatchCount());
449 } 501 }
450 502
451 } // namespace blink 503 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebLocalFrameImpl.cpp ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698