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]); }
TEST_F(TextFinderTest, FindTextInShadowDOM) { 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. bool wrapWithinFrame = true; WebRect* selectionRect = nullptr; // TextIterator currently returns the matches in the composed 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)); 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, selectionRect)); 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, selectionRect)); 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, selectionRect)); 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, selectionRect)); 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, selectionRect)); 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, selectionRect)); 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, selectionRect)); 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()); }