예제 #1
0
TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM)
{
    document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION);
    RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = document().body()->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
    shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content></content>", ASSERT_NO_EXCEPTION);
    Node* textInBElement = document().body()->firstChild()->firstChild();
    Node* textInIElement = document().body()->lastChild()->firstChild();
    Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();

    int identifier = 0;
    WebString searchText(String("fOO"));
    WebFindOptions findOptions; // Default.

    textFinder().resetMatchCount();
    textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
    while (textFinder().scopingInProgress())
        runPendingTasks();

    // TextIterator currently returns the matches in the composed tree order,
    // so in this case the matches will be returned in the order of
    // <i> -> <u> -> <b>.
    EXPECT_EQ(3, textFinder().totalMatchCount());
    WebVector<WebFloatRect> matchRects;
    textFinder().findMatchRects(matchRects);
    ASSERT_EQ(3u, matchRects.size());
    EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[0]);
    EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[1]);
    EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[2]);
}
예제 #2
0
TEST_F(TextFinderTest, ScopeTextMatchesRepeated) {
  document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ");
  document().updateStyleAndLayout();

  Node* textNode = document().body()->firstChild();

  int identifier = 0;
  WebString searchText1(String("XFindMe"));
  WebString searchText2(String("FindMe"));
  WebFindOptions findOptions;  // Default.

  textFinder().resetMatchCount();
  textFinder().startScopingStringMatches(identifier, searchText1, findOptions);
  textFinder().startScopingStringMatches(identifier, searchText2, findOptions);
  while (textFinder().scopingInProgress())
    runPendingTasks();

  // Only searchText2 should be highlighted.
  EXPECT_EQ(2, textFinder().totalMatchCount());
  WebVector<WebFloatRect> matchRects;
  textFinder().findMatchRects(matchRects);
  ASSERT_EQ(2u, matchRects.size());
  EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]);
  EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]);
}
예제 #3
0
TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM) {
  document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>");
  document().updateStyleAndLayout();

  int identifier = 0;
  WebString searchText(String("FindMe"));
  WebFindOptions findOptions;  // Default.
  bool wrapWithinFrame = true;
  bool activeNow;

  textFinder().resetMatchCount();
  textFinder().startScopingStringMatches(identifier, searchText, findOptions);
  while (textFinder().scopingInProgress())
    runPendingTasks();

  findOptions.findNext = true;
  ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions,
                                wrapWithinFrame, &activeNow));
  EXPECT_TRUE(activeNow);
  ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions,
                                wrapWithinFrame, &activeNow));
  EXPECT_TRUE(activeNow);

  // Add new text to DOM and try FindNext.
  Element* iElement = toElement(document().body()->lastChild());
  ASSERT_TRUE(iElement);
  iElement->setInnerHTML("ZZFindMe");
  document().updateStyleAndLayout();

  ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions,
                                wrapWithinFrame, &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().startScopingStringMatches(identifier, searchText, findOptions);
  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]);
}
예제 #4
0
TEST_F(TextFinderTest, ScopeRepeatPatternTextMatches)
{
    document().body()->setInnerHTML("ab ab ab ab ab", ASSERT_NO_EXCEPTION);
    Node* textNode = document().body()->firstChild();

    int identifier = 0;
    WebString searchText(String("ab ab"));
    WebFindOptions findOptions; // Default.

    textFinder().resetMatchCount();
    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());
    EXPECT_EQ(findInPageRect(textNode, 0, textNode, 5), matchRects[0]);
    EXPECT_EQ(findInPageRect(textNode, 6, textNode, 11), matchRects[1]);
}
예제 #5
0
TEST_F(TextFinderTest, SequentialMatches) {
  document().body()->setInnerHTML("ababab");
  document().updateStyleAndLayout();

  Node* textNode = document().body()->firstChild();

  int identifier = 0;
  WebString searchText(String("ab"));
  WebFindOptions findOptions;  // Default.

  textFinder().resetMatchCount();
  textFinder().startScopingStringMatches(identifier, searchText, findOptions);
  while (textFinder().scopingInProgress())
    runPendingTasks();

  EXPECT_EQ(3, textFinder().totalMatchCount());
  WebVector<WebFloatRect> matchRects;
  textFinder().findMatchRects(matchRects);
  ASSERT_EQ(3u, matchRects.size());
  EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]);
  EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]);
  EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
}
예제 #6
0
TEST_F(TextFinderTest, OverlappingMatches)
{
    document().body()->setInnerHTML("aababaa", ASSERT_NO_EXCEPTION);
    Node* textNode = document().body()->firstChild();

    int identifier = 0;
    WebString searchText(String("aba"));
    WebFindOptions findOptions; // Default.

    textFinder().resetMatchCount();
    textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
    while (textFinder().scopingInProgress())
        runPendingTasks();

    // We shouldn't find overlapped matches.
    EXPECT_EQ(1, textFinder().totalMatchCount());
    WebVector<WebFloatRect> matchRects;
    textFinder().findMatchRects(matchRects);
    ASSERT_EQ(1u, matchRects.size());
    EXPECT_EQ(findInPageRect(textNode, 1, textNode, 4), matchRects[0]);
}