Commit 5951fdcf authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

DL: Tidy up find-in-page tests

Remove unnecessary test (TextFinder::Find test, since
find-in-page now just uses FindInPage::Find directly),
split up large test.

Bug: 882663
Change-Id: Ie4a1e71b780224047b6fe674c2f90f413e9599b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631147Reviewed-by: default avatarFergal Daly <fergal@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664670}
parent b05fc715
...@@ -104,9 +104,6 @@ class DisplayLockContextTest : public testing::Test { ...@@ -104,9 +104,6 @@ class DisplayLockContextTest : public testing::Test {
return *static_cast<Document*>( return *static_cast<Document*>(
web_view_helper_.LocalMainFrame()->GetDocument()); web_view_helper_.LocalMainFrame()->GetDocument());
} }
TextFinder& GetTextFinder() {
return web_view_helper_.LocalMainFrame()->EnsureTextFinder();
}
FindInPage* GetFindInPage() { FindInPage* GetFindInPage() {
return web_view_helper_.LocalMainFrame()->GetFindInPage(); return web_view_helper_.LocalMainFrame()->GetFindInPage();
} }
...@@ -131,6 +128,40 @@ class DisplayLockContextTest : public testing::Test { ...@@ -131,6 +128,40 @@ class DisplayLockContextTest : public testing::Test {
test::RunPendingTasks(); test::RunPendingTasks();
} }
void LockElement(Element& element, bool activatable) {
DisplayLockOptions options;
options.setActivatable(activatable);
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
ScriptState::Scope scope(script_state);
element.getDisplayLockForBindings()->acquire(script_state, &options);
UpdateAllLifecyclePhasesForTest();
}
void CommitElement(Element& element) {
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
ScriptState::Scope scope(script_state);
element.getDisplayLockForBindings()->commit(script_state);
UpdateAllLifecyclePhasesForTest();
}
mojom::blink::FindOptionsPtr FindOptions(bool find_next = false) {
auto find_options = mojom::blink::FindOptions::New();
find_options->run_synchronously_for_testing = true;
find_options->find_next = find_next;
find_options->forward = true;
return find_options;
}
void Find(String search_text,
DisplayLockTestFindInPageClient& client,
bool find_next = false) {
client.Reset();
GetFindInPage()->Find(FAKE_FIND_ID, search_text, FindOptions(find_next));
test::RunPendingTasks();
}
const int FAKE_FIND_ID = 1;
private: private:
base::Optional<RuntimeEnabledFeatures::Backup> features_backup_; base::Optional<RuntimeEnabledFeatures::Backup> features_backup_;
frame_test_helpers::WebViewHelper web_view_helper_; frame_test_helpers::WebViewHelper web_view_helper_;
...@@ -241,7 +272,8 @@ TEST_F(DisplayLockContextTest, LockAfterAppendStyleDirtyBits) { ...@@ -241,7 +272,8 @@ TEST_F(DisplayLockContextTest, LockAfterAppendStyleDirtyBits) {
MakeRGB(0, 0, 255)); MakeRGB(0, 0, 255));
} }
TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaTextFinder) { TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaFindInPage) {
ResizeAndFocus();
SetHtmlInnerHTML(R"HTML( SetHtmlInnerHTML(R"HTML(
<style> <style>
#container { #container {
...@@ -253,64 +285,23 @@ TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaTextFinder) { ...@@ -253,64 +285,23 @@ TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaTextFinder) {
<body><div id="container">testing</div></body> <body><div id="container">testing</div></body>
)HTML"); )HTML");
int identifier = 0; const String search_text = "testing";
WebString search_text(String("testing")); DisplayLockTestFindInPageClient client;
auto& text_finder = GetTextFinder(); client.SetFrame(LocalMainFrame());
auto find_options = mojom::blink::FindOptions::New();
bool wrap_within_frame = true;
ASSERT_TRUE(text_finder.Find(identifier, search_text, *find_options,
wrap_within_frame));
text_finder.ClearActiveFindMatch();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
auto* element = GetDocument().getElementById("container");
{
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
ScriptState::Scope scope(script_state);
element->getDisplayLockForBindings()->acquire(script_state, nullptr);
}
UpdateAllLifecyclePhasesForTest();
// Sanity checks to ensure the element is locked.
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldStyle(
DisplayLockContext::kChildren));
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldLayout(
DisplayLockContext::kChildren));
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldPaint());
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 1);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 1);
EXPECT_FALSE(element->GetDisplayLockContext()->IsActivatable());
EXPECT_FALSE(text_finder.Find(identifier, search_text, *find_options,
wrap_within_frame));
// Now commit the lock and ensure we can find the text.
{
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
ScriptState::Scope scope(script_state);
element->getDisplayLockForBindings()->commit(script_state);
}
EXPECT_TRUE(element->GetDisplayLockContext()->ShouldStyle(
DisplayLockContext::kChildren));
EXPECT_TRUE(element->GetDisplayLockContext()->ShouldLayout(
DisplayLockContext::kChildren));
EXPECT_TRUE(element->GetDisplayLockContext()->ShouldPaint());
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0); auto* container = GetDocument().getElementById("container");
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0); LockElement(*container, false /* activatable */);
Find(search_text, client);
EXPECT_EQ(0, client.Count());
EXPECT_TRUE(text_finder.Find(identifier, search_text, *find_options, // Check if we can find the result after we commit.
wrap_within_frame)); CommitElement(*container);
Find(search_text, client);
EXPECT_EQ(1, client.Count());
} }
TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaFindInPage) { TEST_F(DisplayLockContextTest,
ActivatableLockedElementIsSearchableViaFindInPage) {
ResizeAndFocus(); ResizeAndFocus();
SetHtmlInnerHTML(R"HTML( SetHtmlInnerHTML(R"HTML(
<style> <style>
...@@ -323,84 +314,28 @@ TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaFindInPage) { ...@@ -323,84 +314,28 @@ TEST_F(DisplayLockContextTest, LockedElementIsNotSearchableViaFindInPage) {
<body><div id="container">testing</div></body> <body><div id="container">testing</div></body>
)HTML"); )HTML");
WebString search_text(String("testing")); const String search_text = "testing";
auto* find_in_page = GetFindInPage();
ASSERT_TRUE(find_in_page);
DisplayLockTestFindInPageClient client; DisplayLockTestFindInPageClient client;
client.SetFrame(LocalMainFrame()); client.SetFrame(LocalMainFrame());
auto find_options = mojom::blink::FindOptions::New(); // Finds on a normal element.
find_options->run_synchronously_for_testing = true; Find(search_text, client);
find_options->find_next = false;
find_options->forward = true;
int current_id = 123;
find_in_page->Find(current_id++, "testing", find_options->Clone());
EXPECT_FALSE(client.FindResultsAreReady());
test::RunPendingTasks();
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(1, client.Count()); EXPECT_EQ(1, client.Count());
client.Reset(); // Clears selections since we're going to use the same query next time.
GetFindInPage()->StopFinding(
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0); mojom::StopFindAction::kStopFindActionClearSelection);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
auto* element = GetDocument().getElementById("container"); auto* container = GetDocument().getElementById("container");
{ LockElement(*container, true /* activatable */);
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
ScriptState::Scope scope(script_state);
element->getDisplayLockForBindings()->acquire(script_state, nullptr);
}
UpdateAllLifecyclePhasesForTest();
// Sanity checks to ensure the element is locked.
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldStyle(
DisplayLockContext::kChildren));
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldLayout(
DisplayLockContext::kChildren));
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldPaint());
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 1);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 1);
EXPECT_FALSE(element->GetDisplayLockContext()->IsActivatable());
find_in_page->Find(current_id++, "testing", find_options->Clone());
EXPECT_FALSE(client.FindResultsAreReady());
test::RunPendingTasks();
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(0, client.Count());
client.Reset();
// Now commit the lock and ensure we can find the text.
{
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
ScriptState::Scope scope(script_state);
element->getDisplayLockForBindings()->commit(script_state);
}
EXPECT_TRUE(element->GetDisplayLockContext()->ShouldStyle(
DisplayLockContext::kChildren));
EXPECT_TRUE(element->GetDisplayLockContext()->ShouldLayout(
DisplayLockContext::kChildren));
EXPECT_TRUE(element->GetDisplayLockContext()->ShouldPaint());
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
find_in_page->Find(current_id++, "testing", find_options->Clone()); EXPECT_TRUE(container->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(client.FindResultsAreReady()); // Check if we can still get the same result with the same query.
test::RunPendingTasks(); Find(search_text, client);
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(1, client.Count()); EXPECT_EQ(1, client.Count());
client.Reset(); EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
} }
TEST_F(DisplayLockContextTest, TEST_F(DisplayLockContextTest, FindInPageWithChangedContent) {
ActivatableLockedElementIsSearchableViaFindInPage) {
ResizeAndFocus(); ResizeAndFocus();
SetHtmlInnerHTML(R"HTML( SetHtmlInnerHTML(R"HTML(
<style> <style>
...@@ -413,163 +348,142 @@ TEST_F(DisplayLockContextTest, ...@@ -413,163 +348,142 @@ TEST_F(DisplayLockContextTest,
<body><div id="container">testing</div></body> <body><div id="container">testing</div></body>
)HTML"); )HTML");
WebString search_text(String("testing")); // Check if the result is correct if we update the contents.
auto* find_in_page = GetFindInPage(); auto* container = GetDocument().getElementById("container");
ASSERT_TRUE(find_in_page); LockElement(*container, true /* activatable */);
EXPECT_TRUE(container->GetDisplayLockContext()->IsLocked());
container->SetInnerHTMLFromString(
"testing"
"<div>testing</div>"
"tes<div style='display:none;'>x</div>ting");
DisplayLockTestFindInPageClient client; DisplayLockTestFindInPageClient client;
client.SetFrame(LocalMainFrame()); client.SetFrame(LocalMainFrame());
Find("testing", client);
EXPECT_EQ(3, client.Count());
EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
}
auto find_options = mojom::blink::FindOptions::New(); TEST_F(DisplayLockContextTest, FindInPageWithNoMatchesWontUnlock) {
find_options->run_synchronously_for_testing = true; ResizeAndFocus();
find_options->find_next = false; SetHtmlInnerHTML(R"HTML(
find_options->forward = true; <style>
#container {
int current_id = 123; width: 100px;
find_in_page->Find(current_id++, "testing", find_options->Clone()); height: 100px;
EXPECT_FALSE(client.FindResultsAreReady()); contain: style layout paint;
test::RunPendingTasks(); }
EXPECT_TRUE(client.FindResultsAreReady()); </style>
EXPECT_EQ(1, client.Count()); <body><div id="container">tes<div>ting</div><div style='display:none;'>testing</div></div></body>
client.Reset(); )HTML");
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
DisplayLockOptions options;
options.setActivatable(true);
auto* element = GetDocument().getElementById("container");
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame());
{
ScriptState::Scope scope(script_state);
element->getDisplayLockForBindings()->acquire(script_state, &options);
}
UpdateAllLifecyclePhasesForTest();
// Sanity checks to ensure the element is locked. auto* container = GetDocument().getElementById("container");
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldStyle( LockElement(*container, true /* activatable */);
DisplayLockContext::kChildren)); LockElement(*container, true /* activatable */);
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldLayout( EXPECT_TRUE(container->GetDisplayLockContext()->IsLocked());
DisplayLockContext::kChildren));
EXPECT_FALSE(element->GetDisplayLockContext()->ShouldPaint());
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 1);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
EXPECT_TRUE(element->GetDisplayLockContext()->IsActivatable()); DisplayLockTestFindInPageClient client;
client.SetFrame(LocalMainFrame());
Find("testing", client);
// No results found, container stays locked.
EXPECT_EQ(0, client.Count());
EXPECT_TRUE(container->GetDisplayLockContext()->IsLocked());
}
// Check if we can still get the same result with the same query. TEST_F(DisplayLockContextTest,
find_in_page->Find(current_id++, "testing", find_options->Clone()); NestedActivatableLockedElementIsSearchableViaFindInPage) {
EXPECT_FALSE(client.FindResultsAreReady()); ResizeAndFocus();
test::RunPendingTasks(); SetHtmlInnerHTML(R"HTML(
EXPECT_TRUE(client.FindResultsAreReady()); <body>
EXPECT_EQ(1, client.Count()); <style>
EXPECT_EQ(1, client.ActiveIndex()); div {
client.Reset(); width: 100px;
height: 100px;
contain: style layout;
}
</style>
<div id='container'>
<div>testing1</div>
<div id='activatable'>
testing2
<div id='nestedNonActivatable'>
testing3
</div>
</div>
<div id='nonActivatable'>testing4</div>
</div>
"</body>"
)HTML");
// Check if the result is correct if we update the contents. auto* container = GetDocument().getElementById("container");
element->SetInnerHTMLFromString(
"<div>tes</div>ting"
"<div style='display:none;'>testing</div>");
find_in_page->Find(current_id++, "testing", find_options->Clone());
EXPECT_FALSE(client.FindResultsAreReady());
test::RunPendingTasks();
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(0, client.Count());
EXPECT_EQ(-1, client.ActiveIndex());
client.Reset();
// Assert the container is still locked.
EXPECT_TRUE(element->GetDisplayLockContext()->IsLocked());
// Check if the result is correct if we have non-activatable lock.
element->SetInnerHTMLFromString(
"<div>testing1</div>"
"<div id='activatable' style='contain: style layout;'>"
" testing2"
" <div id='nestedNonActivatable' style='contain: style layout;'>"
" testing3"
" </div>"
"</div>"
"<div id='nonActivatable' style='contain: style layout;'>testing4</div>");
auto* activatable = GetDocument().getElementById("activatable"); auto* activatable = GetDocument().getElementById("activatable");
auto* non_activatable = GetDocument().getElementById("nonActivatable"); auto* non_activatable = GetDocument().getElementById("nonActivatable");
auto* nested_non_activatable = auto* nested_non_activatable =
GetDocument().getElementById("nestedNonActivatable"); GetDocument().getElementById("nestedNonActivatable");
{ LockElement(*non_activatable, false /* activatable */);
ScriptState::Scope scope(script_state); LockElement(*nested_non_activatable, false /* activatable */);
activatable->getDisplayLockForBindings()->acquire(script_state, &options); LockElement(*activatable, true /* activatable */);
nested_non_activatable->getDisplayLockForBindings()->acquire(script_state, LockElement(*container, true /* activatable */);
nullptr);
non_activatable->getDisplayLockForBindings()->acquire(script_state,
nullptr);
}
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 4);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 2);
EXPECT_TRUE(element->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(container->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(activatable->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(activatable->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(non_activatable->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(non_activatable->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(nested_non_activatable->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(nested_non_activatable->GetDisplayLockContext()->IsLocked());
find_in_page->Find(current_id++, "testing", find_options->Clone()); // We can find testing1 and testing2.
EXPECT_FALSE(client.FindResultsAreReady()); DisplayLockTestFindInPageClient client;
test::RunPendingTasks(); client.SetFrame(LocalMainFrame());
EXPECT_TRUE(client.FindResultsAreReady()); Find("testing", client);
EXPECT_EQ(2, client.Count()); EXPECT_EQ(2, client.Count());
EXPECT_EQ(1, client.ActiveIndex()); EXPECT_EQ(1, client.ActiveIndex());
client.Reset();
UpdateAllLifecyclePhasesForTest(); // #container should be unlocked, since the match is inside that
// The locked container should be unlocked, since the match is inside that // element ("testing1" inside the div).
// container ("testing1" inside the div). EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 3); // Since the active match isn't located within other locked elements
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 2); // they need to stay locked.
EXPECT_FALSE(element->GetDisplayLockContext()->IsLocked());
// Since the active match isn't in any locked container, they need to be
// locked.
EXPECT_TRUE(activatable->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(activatable->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(non_activatable->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(non_activatable->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(nested_non_activatable->GetDisplayLockContext()->IsLocked()); EXPECT_TRUE(nested_non_activatable->GetDisplayLockContext()->IsLocked());
}
// Check if the result is correct if we update style. TEST_F(DisplayLockContextTest,
activatable->setAttribute("style", "contain: style layout; display: none;"); NestedActivatableLockedElementIsUnlockedByFindInPage) {
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 3); ResizeAndFocus();
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 2); SetHtmlInnerHTML(R"HTML(
<body>
<style>
div {
width: 100px;
height: 100px;
contain: style layout;
}
</style>
<div id='container'>
<div id='child'>testing1</div>
</div>
)HTML");
auto* container = GetDocument().getElementById("container");
auto* child = GetDocument().getElementById("child");
LockElement(*child, true /* activatable */);
LockElement(*container, true /* activatable */);
find_in_page->Find(current_id++, "testing", find_options->Clone()); EXPECT_TRUE(container->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(client.FindResultsAreReady()); EXPECT_TRUE(child->GetDisplayLockContext()->IsLocked());
test::RunPendingTasks(); // We can find testing1 and testing2.
EXPECT_TRUE(client.FindResultsAreReady()); DisplayLockTestFindInPageClient client;
client.SetFrame(LocalMainFrame());
Find("testing", client);
EXPECT_EQ(1, client.Count()); EXPECT_EQ(1, client.Count());
EXPECT_EQ(1, client.ActiveIndex()); EXPECT_EQ(1, client.ActiveIndex());
client.Reset();
// Now commit all the locks and ensure we can find.
{
ScriptState::Scope scope(script_state);
element->getDisplayLockForBindings()->commit(script_state);
activatable->getDisplayLockForBindings()->commit(script_state);
nested_non_activatable->getDisplayLockForBindings()->commit(script_state);
non_activatable->getDisplayLockForBindings()->commit(script_state);
}
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0); EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0); EXPECT_FALSE(child->GetDisplayLockContext()->IsLocked());
find_in_page->Find(current_id++, "testing", find_options->Clone());
EXPECT_FALSE(client.FindResultsAreReady());
test::RunPendingTasks();
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(2, client.Count());
} }
// Tests find-in-page active match navigation (find next/previous). TEST_F(DisplayLockContextTest,
TEST_F(DisplayLockContextTest, FindInPageNavigateLockedMatches) { FindInPageNavigateLockedMatchesRespectsActivatable) {
ResizeAndFocus(); ResizeAndFocus();
SetHtmlInnerHTML(R"HTML( SetHtmlInnerHTML(R"HTML(
<style> <style>
...@@ -588,136 +502,37 @@ TEST_F(DisplayLockContextTest, FindInPageNavigateLockedMatches) { ...@@ -588,136 +502,37 @@ TEST_F(DisplayLockContextTest, FindInPageNavigateLockedMatches) {
</body> </body>
)HTML"); )HTML");
WebString search_text(String("result"));
auto* find_in_page = GetFindInPage();
ASSERT_TRUE(find_in_page);
DisplayLockTestFindInPageClient client;
client.SetFrame(LocalMainFrame());
DisplayLockOptions options;
options.setActivatable(true);
// Lock the children and container.
auto* container = GetDocument().getElementById("container");
auto* div_one = GetDocument().getElementById("one"); auto* div_one = GetDocument().getElementById("one");
auto* div_two = GetDocument().getElementById("two"); auto* div_two = GetDocument().getElementById("two");
auto* div_three = GetDocument().getElementById("three"); auto* div_three = GetDocument().getElementById("three");
auto* script_state = ToScriptStateForMainWorld(GetDocument().GetFrame()); // Lock three divs, make #div_two non-activatable.
{ LockElement(*div_one, true /* activatable */);
ScriptState::Scope scope(script_state); LockElement(*div_two, false /* activatable */);
container->getDisplayLockForBindings()->acquire(script_state, &options); LockElement(*div_three, true /* activatable */);
div_one->getDisplayLockForBindings()->acquire(script_state, &options);
div_two->getDisplayLockForBindings()->acquire(script_state, &options);
div_three->getDisplayLockForBindings()->acquire(script_state, &options);
}
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 4); DisplayLockTestFindInPageClient client;
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0); client.SetFrame(LocalMainFrame());
WebString search_text(String("result"));
auto find_options = mojom::blink::FindOptions::New();
find_options->run_synchronously_for_testing = true;
find_options->find_next = false;
find_options->forward = true;
int current_id = 123;
// Find should activate "result" number 1 in "#one".
find_in_page->Find(current_id++, search_text, find_options->Clone());
test::RunPendingTasks();
EXPECT_EQ(3, client.Count());
EXPECT_EQ(1, client.ActiveIndex());
EphemeralRange range_one = EphemeralRange::RangeOfContents(*div_one);
ASSERT_FALSE(range_one.IsNull());
EXPECT_EQ(ComputeTextRect(range_one), client.ActiveMatchRect());
UpdateAllLifecyclePhasesForTest();
// |div_one| and the container should be unlocked.
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 2);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(div_one->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(div_two->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(div_three->GetDisplayLockContext()->IsLocked());
// Find next should activate "result" number 2 in "#two".
client.Reset();
find_options->find_next = true;
find_in_page->Find(current_id++, search_text, find_options->Clone());
test::RunPendingTasks();
EXPECT_EQ(3, client.Count());
EXPECT_EQ(2, client.ActiveIndex());
EphemeralRange range_two = EphemeralRange::RangeOfContents(*div_two);
ASSERT_FALSE(range_one.IsNull());
EXPECT_EQ(ComputeTextRect(range_two), client.ActiveMatchRect());
UpdateAllLifecyclePhasesForTest();
// |div_two| should be unlocked.
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 1);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(div_one->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(div_two->GetDisplayLockContext()->IsLocked());
EXPECT_TRUE(div_three->GetDisplayLockContext()->IsLocked());
// Find next should activate "result" number 3 in "#three".
client.Reset();
find_options->find_next = true;
find_in_page->Find(current_id++, search_text, find_options->Clone());
test::RunPendingTasks();
EXPECT_EQ(3, client.Count());
EXPECT_EQ(3, client.ActiveIndex());
EphemeralRange range_three = EphemeralRange::RangeOfContents(*div_three);
ASSERT_FALSE(range_three.IsNull());
EXPECT_EQ(ComputeTextRect(range_three), client.ActiveMatchRect());
UpdateAllLifecyclePhasesForTest();
// |div_three| should be unlocked.
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 0);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 0);
EXPECT_FALSE(container->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(div_one->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(div_two->GetDisplayLockContext()->IsLocked());
EXPECT_FALSE(div_three->GetDisplayLockContext()->IsLocked());
// Lock them again, now making |div_two| non-activatable.
{
ScriptState::Scope scope(script_state);
div_one->getDisplayLockForBindings()->acquire(script_state, &options);
div_two->getDisplayLockForBindings()->acquire(script_state, nullptr);
div_three->getDisplayLockForBindings()->acquire(script_state, &options);
}
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(GetDocument().LockedDisplayLockCount(), 3);
EXPECT_EQ(GetDocument().ActivationBlockingDisplayLockCount(), 1);
// Find result in #one. // Find result in #one.
find_in_page->ClearActiveFindMatch(); Find(search_text, client);
client.Reset();
find_options->find_next = false;
find_in_page->Find(current_id++, search_text, find_options->Clone());
test::RunPendingTasks();
EXPECT_EQ(2, client.Count()); EXPECT_EQ(2, client.Count());
EXPECT_EQ(1, client.ActiveIndex()); EXPECT_EQ(1, client.ActiveIndex());
EphemeralRange range_one = EphemeralRange::RangeOfContents(*div_one);
EXPECT_EQ(ComputeTextRect(range_one), client.ActiveMatchRect()); EXPECT_EQ(ComputeTextRect(range_one), client.ActiveMatchRect());
// Going forward from #one would go to #three. // Going forward from #one would go to #three.
client.Reset(); Find(search_text, client, true /* find_next */);
find_options->find_next = true;
find_in_page->Find(current_id++, search_text, find_options->Clone());
test::RunPendingTasks();
EXPECT_EQ(2, client.Count()); EXPECT_EQ(2, client.Count());
EXPECT_EQ(2, client.ActiveIndex()); EXPECT_EQ(2, client.ActiveIndex());
EphemeralRange range_three = EphemeralRange::RangeOfContents(*div_three);
EXPECT_EQ(ComputeTextRect(range_three), client.ActiveMatchRect()); EXPECT_EQ(ComputeTextRect(range_three), client.ActiveMatchRect());
// Going backwards from #three would go to #one. // Going backwards from #three would go to #one.
client.Reset(); client.Reset();
auto find_options = FindOptions();
find_options->forward = false; find_options->forward = false;
find_in_page->Find(current_id++, search_text, find_options->Clone()); GetFindInPage()->Find(FAKE_FIND_ID, search_text, find_options->Clone());
test::RunPendingTasks(); test::RunPendingTasks();
EXPECT_EQ(2, client.Count()); EXPECT_EQ(2, client.Count());
EXPECT_EQ(1, client.ActiveIndex()); EXPECT_EQ(1, client.ActiveIndex());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment