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

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

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

  // TextIterator currently returns the matches in the flat 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, FindTextInShadowDOM) {
  document().body()->setInnerHTML("<b>FOO</b><i>foo</i>");
  ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(
      ShadowRootType::V0, ASSERT_NO_EXCEPTION);
  shadowRoot->setInnerHTML(
      "<content select=\"i\"></content><u>Foo</u><content></content>");
  Node* textInBElement = document().body()->firstChild()->firstChild();
  Node* textInIElement = document().body()->lastChild()->firstChild();
  Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
  document().updateStyleAndLayout();

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

  // 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));
  Range* activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInIElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInIElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  findOptions.findNext = true;
  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInUElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInUElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInBElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInBElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  // Should wrap to the first match.
  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInIElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInIElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  // Fresh search in the reverse order.
  identifier = 1;
  findOptions = WebFindOptions();
  findOptions.forward = false;

  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInBElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInBElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  findOptions.findNext = true;
  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInUElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInUElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInIElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInIElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());

  // And wrap.
  ASSERT_TRUE(
      textFinder().find(identifier, searchText, findOptions, wrapWithinFrame));
  activeMatch = textFinder().activeMatch();
  ASSERT_TRUE(activeMatch);
  EXPECT_EQ(textInBElement, activeMatch->startContainer());
  EXPECT_EQ(0, activeMatch->startOffset());
  EXPECT_EQ(textInBElement, activeMatch->endContainer());
  EXPECT_EQ(3, activeMatch->endOffset());
}