| Index: third_party/WebKit/Source/web/tests/TextFinderTest.cpp
 | 
| diff --git a/third_party/WebKit/Source/web/tests/TextFinderTest.cpp b/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
 | 
| index a3ec1cc8e5f6b46a19b817f03fc69bc4980e458e..506722c93dd972f37842efbbc135b376c7480a9d 100644
 | 
| --- a/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
 | 
| +++ b/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
 | 
| @@ -76,8 +76,9 @@ TEST_F(TextFinderTest, FindTextSimple)
 | 
|      WebFindOptions findOptions; // Default.
 | 
|      bool wrapWithinFrame = true;
 | 
|      WebRect* selectionRect = nullptr;
 | 
| +    bool* activeNow = nullptr;
 | 
|  
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      Range* activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textNode, activeMatch->startContainer());
 | 
| @@ -86,7 +87,7 @@ TEST_F(TextFinderTest, FindTextSimple)
 | 
|      EXPECT_EQ(10, activeMatch->endOffset());
 | 
|  
 | 
|      findOptions.findNext = true;
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textNode, activeMatch->startContainer());
 | 
| @@ -95,7 +96,7 @@ TEST_F(TextFinderTest, FindTextSimple)
 | 
|      EXPECT_EQ(20, activeMatch->endOffset());
 | 
|  
 | 
|      // Should wrap to the first match.
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textNode, activeMatch->startContainer());
 | 
| @@ -108,7 +109,7 @@ TEST_F(TextFinderTest, FindTextSimple)
 | 
|      findOptions = WebFindOptions();
 | 
|      findOptions.forward = false;
 | 
|  
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textNode, activeMatch->startContainer());
 | 
| @@ -117,7 +118,7 @@ TEST_F(TextFinderTest, FindTextSimple)
 | 
|      EXPECT_EQ(20, activeMatch->endOffset());
 | 
|  
 | 
|      findOptions.findNext = true;
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textNode, activeMatch->startContainer());
 | 
| @@ -126,7 +127,7 @@ TEST_F(TextFinderTest, FindTextSimple)
 | 
|      EXPECT_EQ(10, activeMatch->endOffset());
 | 
|  
 | 
|      // Wrap to the first match (last occurence in the document).
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textNode, activeMatch->startContainer());
 | 
| @@ -144,6 +145,7 @@ TEST_F(TextFinderTest, FindTextAutosizing)
 | 
|      WebFindOptions findOptions; // Default.
 | 
|      bool wrapWithinFrame = true;
 | 
|      WebRect* selectionRect = nullptr;
 | 
| +    bool* activeNow = nullptr;
 | 
|  
 | 
|      // Set viewport scale to 20 in order to simulate zoom-in
 | 
|      VisualViewport& visualViewport = document().page()->frameHost().visualViewport();
 | 
| @@ -155,7 +157,7 @@ TEST_F(TextFinderTest, FindTextAutosizing)
 | 
|      document().textAutosizer()->updatePageInfo();
 | 
|  
 | 
|      // In case of autosizing, scale _should_ change
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      ASSERT_TRUE(textFinder().activeMatch());
 | 
|      ASSERT_EQ(1, visualViewport.scale()); // in this case to 1
 | 
|  
 | 
| @@ -164,7 +166,7 @@ TEST_F(TextFinderTest, FindTextAutosizing)
 | 
|      document().settings()->setTextAutosizingEnabled(false);
 | 
|      document().textAutosizer()->updatePageInfo();
 | 
|  
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      ASSERT_TRUE(textFinder().activeMatch());
 | 
|      ASSERT_EQ(20, visualViewport.scale());
 | 
|  }
 | 
| @@ -178,8 +180,9 @@ TEST_F(TextFinderTest, FindTextNotFound)
 | 
|      WebFindOptions findOptions; // Default.
 | 
|      bool wrapWithinFrame = true;
 | 
|      WebRect* selectionRect = nullptr;
 | 
| +    bool* activeNow = nullptr;
 | 
|  
 | 
| -    EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      EXPECT_FALSE(textFinder().activeMatch());
 | 
|  }
 | 
|  
 | 
| @@ -197,11 +200,12 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      WebFindOptions findOptions; // Default.
 | 
|      bool wrapWithinFrame = true;
 | 
|      WebRect* selectionRect = nullptr;
 | 
| +    bool* activeNow = nullptr;
 | 
|  
 | 
|      // TextIterator currently returns the matches in the flat treeorder, so
 | 
|      // in this case the matches will be returned in the order of
 | 
|      // <i> -> <u> -> <b>.
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      Range* activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInIElement, activeMatch->startContainer());
 | 
| @@ -210,7 +214,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      EXPECT_EQ(3, activeMatch->endOffset());
 | 
|  
 | 
|      findOptions.findNext = true;
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInUElement, activeMatch->startContainer());
 | 
| @@ -218,7 +222,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      EXPECT_EQ(textInUElement, activeMatch->endContainer());
 | 
|      EXPECT_EQ(3, activeMatch->endOffset());
 | 
|  
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInBElement, activeMatch->startContainer());
 | 
| @@ -227,7 +231,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      EXPECT_EQ(3, activeMatch->endOffset());
 | 
|  
 | 
|      // Should wrap to the first match.
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInIElement, activeMatch->startContainer());
 | 
| @@ -240,7 +244,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      findOptions = WebFindOptions();
 | 
|      findOptions.forward = false;
 | 
|  
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInBElement, activeMatch->startContainer());
 | 
| @@ -249,7 +253,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      EXPECT_EQ(3, activeMatch->endOffset());
 | 
|  
 | 
|      findOptions.findNext = true;
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInUElement, activeMatch->startContainer());
 | 
| @@ -257,7 +261,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      EXPECT_EQ(textInUElement, activeMatch->endContainer());
 | 
|      EXPECT_EQ(3, activeMatch->endOffset());
 | 
|  
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInIElement, activeMatch->startContainer());
 | 
| @@ -266,7 +270,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
 | 
|      EXPECT_EQ(3, activeMatch->endOffset());
 | 
|  
 | 
|      // And wrap.
 | 
| -    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
 | 
|      activeMatch = textFinder().activeMatch();
 | 
|      ASSERT_TRUE(activeMatch);
 | 
|      EXPECT_EQ(textInBElement, activeMatch->startContainer());
 | 
| @@ -394,6 +398,58 @@ TEST_F(TextFinderTest, SequentialMatches)
 | 
|      EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
 | 
|  }
 | 
|  
 | 
| +TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM)
 | 
| +{
 | 
| +    document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EXCEPTION);
 | 
| +
 | 
| +    int identifier = 0;
 | 
| +    WebString searchText(String("FindMe"));
 | 
| +    WebFindOptions findOptions; // Default.
 | 
| +    bool wrapWithinFrame = true;
 | 
| +    WebRect* selectionRect = nullptr;
 | 
| +    bool activeNow;
 | 
| +
 | 
| +    textFinder().resetMatchCount();
 | 
| +    textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
 | 
| +    while (textFinder().scopingInProgress())
 | 
| +        runPendingTasks();
 | 
| +
 | 
| +    findOptions.findNext = true;
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, &activeNow));
 | 
| +    EXPECT_TRUE(activeNow);
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, &activeNow));
 | 
| +    EXPECT_TRUE(activeNow);
 | 
| +
 | 
| +    // Add new text to DOM and try FindNext.
 | 
| +    Element* iElement = toElement(document().body()->lastChild());
 | 
| +    ASSERT_TRUE(iElement);
 | 
| +    iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION);
 | 
| +
 | 
| +    ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, &activeNow));
 | 
| +    Range* activeMatch = textFinder().activeMatch();
 | 
| +    ASSERT_TRUE(activeMatch);
 | 
| +    EXPECT_FALSE(activeNow);
 | 
| +    EXPECT_EQ(2, activeMatch->startOffset());
 | 
| +    EXPECT_EQ(8, activeMatch->endOffset());
 | 
| +
 | 
| +    // Restart full search and check that added text is found.
 | 
| +    findOptions.findNext = false;
 | 
| +    textFinder().resetMatchCount();
 | 
| +    textFinder().cancelPendingScopingEffort();
 | 
| +    textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
 | 
| +    while (textFinder().scopingInProgress())
 | 
| +        runPendingTasks();
 | 
| +    EXPECT_EQ(2, textFinder().totalMatchCount());
 | 
| +
 | 
| +    WebVector<WebFloatRect> matchRects;
 | 
| +    textFinder().findMatchRects(matchRects);
 | 
| +    ASSERT_EQ(2u, matchRects.size());
 | 
| +    Node* textInBElement = document().body()->firstChild()->firstChild();
 | 
| +    Node* textInIElement = document().body()->lastChild()->firstChild();
 | 
| +    EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10), matchRects[0]);
 | 
| +    EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8), matchRects[1]);
 | 
| +}
 | 
| +
 | 
|  class TextFinderFakeTimerTest : public TextFinderTest {
 | 
|  protected:
 | 
|      // A simple platform that mocks out the clock.
 | 
| 
 |