Commit 37bccc22 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

[iOS] Ignore invalid frameIds

Additionally, update tests to use correctly formatted frame ids.

Fixed: 1098606
Change-Id: I0d0b9cfa473d20433c228863af3a434ffd50b5f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264468
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Auto-Submit: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782598}
parent 0d2e44c0
......@@ -257,7 +257,7 @@ TEST_F(FormSuggestionControllerTest,
SetUpController(@[ [TestSuggestionProvider providerWithSuggestions] ]);
GURL url("http://foo.com");
test_web_state_.SetCurrentURL(url);
web::FakeWebFrame main_frame("main_frame", /*is_main_frame=*/true, url);
web::FakeMainWebFrame main_frame(url);
// Trigger form activity, which should set up the suggestions view.
autofill::FormActivityParams params;
......@@ -280,7 +280,7 @@ TEST_F(FormSuggestionControllerTest, FormActivityBlurShouldBeIgnored) {
SetUpController(@[ [TestSuggestionProvider providerWithSuggestions] ]);
GURL url("http://foo.com");
test_web_state_.SetCurrentURL(url);
web::FakeWebFrame main_frame("main_frame", true, url);
web::FakeMainWebFrame main_frame(url);
autofill::FormActivityParams params;
params.form_name = "form";
......@@ -300,7 +300,7 @@ TEST_F(FormSuggestionControllerTest,
SetUpController(@[]);
GURL url("http://foo.com");
test_web_state_.SetCurrentURL(url);
web::FakeWebFrame main_frame("main_frame", true, url);
web::FakeMainWebFrame main_frame(url);
autofill::FormActivityParams params;
params.form_name = "form";
......@@ -329,7 +329,7 @@ TEST_F(FormSuggestionControllerTest,
SetUpController(@[ provider1, provider2 ]);
GURL url("http://foo.com");
test_web_state_.SetCurrentURL(url);
web::FakeWebFrame main_frame("main_frame", true, url);
web::FakeMainWebFrame main_frame(url);
autofill::FormActivityParams params;
params.form_name = "form";
......@@ -378,7 +378,7 @@ TEST_F(FormSuggestionControllerTest,
SetUpController(@[ provider1, provider2 ]);
GURL url("http://foo.com");
test_web_state_.SetCurrentURL(url);
web::FakeWebFrame main_frame("main_frame", true, url);
web::FakeMainWebFrame main_frame(url);
autofill::FormActivityParams params;
params.form_name = "form";
......@@ -419,7 +419,7 @@ TEST_F(FormSuggestionControllerTest, SelectingSuggestionShouldNotifyDelegate) {
SetUpController(@[ provider ]);
GURL url("http://foo.com");
test_web_state_.SetCurrentURL(url);
web::FakeWebFrame main_frame("main_frame", true, url);
web::FakeMainWebFrame main_frame(url);
autofill::FormActivityParams params;
params.form_name = "form";
......
......@@ -77,8 +77,7 @@ class PaymentRequestFullCardRequesterTest : public PlatformTest {
web_state()->SetJSInjectionReceiver(injectionReceiver);
auto frames_manager = std::make_unique<web::FakeWebFramesManager>();
auto main_frame = std::make_unique<web::FakeWebFrame>(
/*frame_id=*/"main", /*is_main_frame=*/true,
auto main_frame = std::make_unique<web::FakeMainWebFrame>(
/*security_origin=*/GURL());
frames_manager->AddWebFrame(std::move(main_frame));
web_state()->SetWebFramesManager(std::move(frames_manager));
......
......@@ -51,7 +51,7 @@ class FontSizeTabHelperTest : public PlatformTest {
GURL url("https://example.com");
web_state_.SetCurrentURL(url);
auto main_frame = std::make_unique<web::FakeWebFrame>("frameID", true, url);
auto main_frame = std::make_unique<web::FakeMainWebFrame>(url);
fake_main_frame_ = main_frame.get();
AddWebFrame(std::move(main_frame));
......@@ -194,8 +194,7 @@ TEST_F(FontSizeTabHelperTest, ZoomInAllFrames) {
preferred_content_size_category_ = UIContentSizeCategoryExtraLarge;
std::unique_ptr<web::FakeWebFrame> other_frame =
std::make_unique<web::FakeWebFrame>("frameID2", false,
GURL("https://example.com"));
std::make_unique<web::FakeChildWebFrame>(GURL("https://example.com"));
web::FakeWebFrame* fake_other_frame = other_frame.get();
AddWebFrame(std::move(other_frame));
......
......@@ -24,14 +24,6 @@
using base::test::ios::kWaitForJSCompletionTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
namespace {
// Frame ids of fake web frames used in this test class.
const char kOneMatchFrameId[] = "frame_with_one_match";
const char kTwoMatchesFrameId[] = "frame_with_two_matches";
} // namespace
namespace web {
// Tests FindInPageManagerImpl and verifies that the state of
......@@ -55,30 +47,18 @@ class FindInPageManagerImplTest : public WebTest {
// return |js_result| for the JavaScript function call
// "findInString.findString".
std::unique_ptr<FakeWebFrame> CreateMainWebFrameWithJsResultForFind(
std::unique_ptr<base::Value> js_result,
const std::string& frame_id) {
return CreateWebFrameWithJsResultForFind(std::move(js_result), frame_id,
/*is_main_frame=*/true);
std::unique_ptr<base::Value> js_result) {
auto frame = std::make_unique<FakeMainWebFrame>(GURL());
frame->AddJsResultForFunctionCall(std::move(js_result), kFindInPageSearch);
return frame;
}
// Returns a FakeWebFrame child frame with id |frame_id| that
// will return |js_result| for the JavaScript function call
// "findInString.findString".
std::unique_ptr<FakeWebFrame> CreateChildWebFrameWithJsResultForFind(
std::unique_ptr<base::Value> js_result,
const std::string& frame_id) {
return CreateWebFrameWithJsResultForFind(std::move(js_result), frame_id,
/*is_main_frame=*/false);
}
// Returns a FakeWebFrame with id |frame_id| that will return |js_result| for
// the JavaScript function call "findInString.findString".
std::unique_ptr<FakeWebFrame> CreateWebFrameWithJsResultForFind(
std::unique_ptr<base::Value> js_result,
const std::string& frame_id,
bool is_main_frame) {
auto frame =
std::make_unique<FakeWebFrame>(frame_id, is_main_frame, GURL());
std::unique_ptr<base::Value> js_result) {
auto frame = std::make_unique<FakeChildWebFrame>(GURL());
frame->AddJsResultForFunctionCall(std::move(js_result), kFindInPageSearch);
return frame;
}
......@@ -103,11 +83,11 @@ class FindInPageManagerImplTest : public WebTest {
// Tests that Find In Page responds with a total match count of three when a
// frame has one match and another frame has two matches.
TEST_F(FindInPageManagerImplTest, FindMatchesMultipleFrames) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
......@@ -132,11 +112,11 @@ TEST_F(FindInPageManagerImplTest, FindMatchesMultipleFrames) {
// has one match but find in one frame was cancelled. This can occur if the
// frame becomes unavailable.
TEST_F(FindInPageManagerImplTest, FrameCancelFind) {
auto frame_with_null_result = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(), "frame");
auto frame_with_null_result =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>());
FakeWebFrame* frame_with_null_result_ptr = frame_with_null_result.get();
auto frame_with_one_match = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
AddWebFrame(std::move(frame_with_null_result));
AddWebFrame(std::move(frame_with_one_match));
......@@ -160,16 +140,16 @@ TEST_F(FindInPageManagerImplTest, FrameCancelFind) {
// Tests that Find In Page returns a total match count matching the latest find
// if two finds are called.
TEST_F(FindInPageManagerImplTest, ReturnLatestFind) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageSearch);
RemoveWebFrame(kOneMatchFrameId);
RemoveWebFrame(kMainFakeFrameId);
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageSearch);
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
......@@ -189,8 +169,8 @@ TEST_F(FindInPageManagerImplTest, ReturnLatestFind) {
// Tests that Find In Page should not return if the web state is destroyed
// during a find.
TEST_F(FindInPageManagerImplTest, DestroyWebStateDuringFind) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
AddWebFrame(std::move(frame_with_one_match));
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageSearch);
......@@ -203,17 +183,17 @@ TEST_F(FindInPageManagerImplTest, DestroyWebStateDuringFind) {
// Tests that Find In Page updates total match count when a frame with matches
// becomes unavailable during find.
TEST_F(FindInPageManagerImplTest, FrameUnavailableAfterDelegateCallback) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageSearch);
RemoveWebFrame(kTwoMatchesFrameId);
RemoveWebFrame(kChildFakeFrameId);
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
base::RunLoop().RunUntilIdle();
return fake_delegate_.state();
......@@ -230,14 +210,14 @@ TEST_F(FindInPageManagerImplTest, FrameUnavailableAfterDelegateCallback) {
// one match and another that requires pumping to return its two matches.
TEST_F(FindInPageManagerImplTest, FrameRespondsWithPending) {
std::unique_ptr<FakeWebFrame> frame_with_two_matches =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(-1.0),
kTwoMatchesFrameId);
CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(-1.0));
frame_with_two_matches->AddJsResultForFunctionCall(
std::make_unique<base::Value>(2.0), kFindInPagePump);
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_two_matches));
auto frame_with_one_match = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
AddWebFrame(std::move(frame_with_one_match));
......@@ -262,8 +242,8 @@ TEST_F(FindInPageManagerImplTest, FrameRespondsWithPending) {
// Tests that Find In Page doesn't fail when delegate is not set.
TEST_F(FindInPageManagerImplTest, DelegateNotSet) {
GetFindInPageManager()->SetDelegate(nullptr);
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
AddWebFrame(std::move(frame_with_one_match));
......@@ -276,8 +256,8 @@ TEST_F(FindInPageManagerImplTest, DelegateNotSet) {
// Tests that Find In Page returns no matches if can't call JavaScript function.
TEST_F(FindInPageManagerImplTest, FrameCannotCallJavaScriptFunction) {
auto frame_cannot_call_func = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_cannot_call_func =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
frame_cannot_call_func->set_can_call_function(false);
AddWebFrame(std::move(frame_cannot_call_func));
......@@ -306,8 +286,8 @@ TEST_F(FindInPageManagerImplTest, NoFrames) {
// are no matches in the only frame. Tests that Find in Page also did not
// respond with an selected match index value.
TEST_F(FindInPageManagerImplTest, FrameWithNoMatchNoHighlight) {
auto frame_with_zero_matches = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(0.0), "frame_with_zero_matches");
auto frame_with_zero_matches =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(0.0));
FakeWebFrame* frame_with_zero_matches_ptr = frame_with_zero_matches.get();
AddWebFrame(std::move(frame_with_zero_matches));
......@@ -328,8 +308,8 @@ TEST_F(FindInPageManagerImplTest, FrameWithNoMatchNoHighlight) {
// Tests that Find in Page responds with index zero after a find when there are
// two matches in a frame.
TEST_F(FindInPageManagerImplTest, DidHighlightFirstIndex) {
auto frame_with_two_matches = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
auto frame_with_two_matches =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_two_matches));
......@@ -350,8 +330,8 @@ TEST_F(FindInPageManagerImplTest, DidHighlightFirstIndex) {
// Tests that Find in Page responds with index one to a FindInPageNext find
// after a FindInPageSearch find finishes when there are two matches in a frame.
TEST_F(FindInPageManagerImplTest, FindDidHighlightSecondIndexAfterNextCall) {
auto frame_with_two_matches = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
auto frame_with_two_matches =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_two_matches));
......@@ -382,11 +362,11 @@ TEST_F(FindInPageManagerImplTest, FindDidHighlightSecondIndexAfterNextCall) {
// match and another with two matches when making successive FindInPageNext
// calls.
TEST_F(FindInPageManagerImplTest, FindDidSelectAllMatchesWithNextCall) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
......@@ -434,11 +414,11 @@ TEST_F(FindInPageManagerImplTest, FindDidSelectAllMatchesWithNextCall) {
// calls.
TEST_F(FindInPageManagerImplTest,
FindDidLoopThroughAllMatchesWithPreviousCall) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
......@@ -488,11 +468,11 @@ TEST_F(FindInPageManagerImplTest,
// after a FindInPageSearch find finishes when there are two matches in a
// frame and one match in another.
TEST_F(FindInPageManagerImplTest, FindDidHighlightLastIndexAfterPreviousCall) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
......@@ -524,8 +504,8 @@ TEST_F(FindInPageManagerImplTest, FindDidHighlightLastIndexAfterPreviousCall) {
// Tests that Find in Page does not respond to a FindInPageNext or a
// FindInPagePrevious call if no FindInPageSearch find was executed beforehand.
TEST_F(FindInPageManagerImplTest, FindDidNotRepondToNextOrPrevIfNoSearch) {
auto frame_with_three_matches = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(3.0), "frame_with_three_matches");
auto frame_with_three_matches =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(3.0));
AddWebFrame(std::move(frame_with_three_matches));
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageNext);
......@@ -544,11 +524,11 @@ TEST_F(FindInPageManagerImplTest, FindDidNotRepondToNextOrPrevIfNoSearch) {
// removed.
TEST_F(FindInPageManagerImplTest,
FindDidHighlightNextMatchAfterFrameDisappears) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
FakeWebFrame* frame_with_one_match_ptr = frame_with_one_match.get();
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_two_matches_ptr = frame_with_two_matches.get();
AddWebFrame(std::move(frame_with_one_match));
AddWebFrame(std::move(frame_with_two_matches));
......@@ -563,7 +543,7 @@ TEST_F(FindInPageManagerImplTest,
EXPECT_EQ("__gCrWeb.findInPage.selectAndScrollToVisibleMatch(0);",
frame_with_one_match_ptr->GetJavaScriptCallHistory()[1]);
RemoveWebFrame(kOneMatchFrameId);
RemoveWebFrame(kMainFakeFrameId);
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageNext);
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
......@@ -576,11 +556,11 @@ TEST_F(FindInPageManagerImplTest,
// Tests that Find in Page does not respond when frame is removed
TEST_F(FindInPageManagerImplTest, FindDidNotRepondAfterFrameRemoved) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
AddWebFrame(std::move(frame_with_one_match));
RemoveWebFrame(kOneMatchFrameId);
RemoveWebFrame(kMainFakeFrameId);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(fake_delegate_.state());
......@@ -590,8 +570,8 @@ TEST_F(FindInPageManagerImplTest, FindDidNotRepondAfterFrameRemoved) {
// FindInPageSearch find when there is one match in a frame and then responds
// with a total match count of zero when that frame is removed.
TEST_F(FindInPageManagerImplTest, FindInPageUpdateMatchCountAfterFrameRemoved) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
AddWebFrame(std::move(frame_with_one_match));
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageSearch);
......@@ -601,7 +581,7 @@ TEST_F(FindInPageManagerImplTest, FindInPageUpdateMatchCountAfterFrameRemoved) {
return fake_delegate_.state();
}));
RemoveWebFrame(kOneMatchFrameId);
RemoveWebFrame(kMainFakeFrameId);
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
base::RunLoop().RunUntilIdle();
return fake_delegate_.state()->match_count == 0;
......@@ -611,11 +591,10 @@ TEST_F(FindInPageManagerImplTest, FindInPageUpdateMatchCountAfterFrameRemoved) {
// Tests that DidHighlightMatches is not called when a frame with no matches is
// removed from the page.
TEST_F(FindInPageManagerImplTest, FindDidNotResponseAfterFrameDisappears) {
const char kZeroMatchesFrameId[] = "frame_with_zero_matches";
auto frame_with_zero_matches = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(0.0), kZeroMatchesFrameId);
auto frame_with_zero_matches =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(0.0));
auto frame_with_two_matches = CreateChildWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), kTwoMatchesFrameId);
std::make_unique<base::Value>(2.0));
AddWebFrame(std::move(frame_with_zero_matches));
AddWebFrame(std::move(frame_with_two_matches));
......@@ -626,7 +605,7 @@ TEST_F(FindInPageManagerImplTest, FindDidNotResponseAfterFrameDisappears) {
}));
fake_delegate_.Reset();
RemoveWebFrame(kZeroMatchesFrameId);
RemoveWebFrame(kMainFakeFrameId);
EXPECT_FALSE(fake_delegate_.state());
}
......@@ -646,8 +625,8 @@ TEST_F(FindInPageManagerImplTest, FindInPageCanSearchContent) {
// Tests that Find in Page resets the match count to 0 and the query to nil
// after calling StopFinding().
TEST_F(FindInPageManagerImplTest, FindInPageCanStopFind) {
auto frame_with_one_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(1.0), kOneMatchFrameId);
auto frame_with_one_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(1.0));
AddWebFrame(std::move(frame_with_one_match));
GetFindInPageManager()->Find(@"foo", FindInPageOptions::FindInPageSearch);
......@@ -669,8 +648,8 @@ TEST_F(FindInPageManagerImplTest, FindInPageCanStopFind) {
// FindInPageSearch. This simulates a once hidden match becoming visible between
// a FindInPageSearch and a FindInPageNext.
TEST_F(FindInPageManagerImplTest, FindInPageNextUpdatesMatchCount) {
auto frame_with_hidden_match = CreateMainWebFrameWithJsResultForFind(
std::make_unique<base::Value>(2.0), "frame_with_hidden_match");
auto frame_with_hidden_match =
CreateMainWebFrameWithJsResultForFind(std::make_unique<base::Value>(2.0));
FakeWebFrame* frame_with_hidden_match_ptr = frame_with_hidden_match.get();
AddWebFrame(std::move(frame_with_hidden_match));
......
......@@ -12,32 +12,19 @@
#error "This file requires ARC support."
#endif
namespace {
const char kOneMatchFrameId[] = "frame_with_one_match";
const char kTwoMatchesFrameId[] = "frame_with_two_matches";
} // namespace
namespace web {
class FindInPageRequestTest : public WebTest {
protected:
// Returns a FakeWebFrame with id |frame_id|.
std::unique_ptr<FakeWebFrame> CreateWebFrame(const std::string& frame_id,
bool is_main_frame) {
return std::make_unique<FakeWebFrame>(frame_id, is_main_frame,
GURL::EmptyGURL());
}
FindInPageRequestTest() {
auto main_frame = CreateWebFrame(kOneMatchFrameId,
/*is_main_frame=*/true);
auto main_frame = std::make_unique<FakeMainWebFrame>(GURL::EmptyGURL());
request_.AddFrame(main_frame.get());
auto frame_with_two_matches =
CreateWebFrame(kTwoMatchesFrameId, /*is_main_frame=*/false);
std::make_unique<FakeChildWebFrame>(GURL::EmptyGURL());
request_.AddFrame(frame_with_two_matches.get());
request_.Reset(@"foo", 2);
request_.SetMatchCountForFrame(1, kOneMatchFrameId);
request_.SetMatchCountForFrame(2, kTwoMatchesFrameId);
request_.SetMatchCountForFrame(1, kMainFakeFrameId);
request_.SetMatchCountForFrame(2, kChildFakeFrameId);
}
FindInPageRequest request_;
};
......@@ -144,7 +131,7 @@ TEST_F(FindInPageRequestTest, RemoveFrame) {
EXPECT_EQ(3, request_.GetTotalMatchCount());
EXPECT_EQ(1, request_.GetMatchCountForSelectedFrame());
request_.RemoveFrame(kOneMatchFrameId);
request_.RemoveFrame(kMainFakeFrameId);
EXPECT_EQ(2, request_.GetTotalMatchCount());
......@@ -186,7 +173,7 @@ TEST_F(FindInPageRequestTest, SetMatchCountForFrame) {
EXPECT_EQ(3, request_.GetTotalMatchCount());
EXPECT_EQ(1, request_.GetMatchCountForSelectedFrame());
request_.SetMatchCountForFrame(5, kTwoMatchesFrameId);
request_.SetMatchCountForFrame(5, kChildFakeFrameId);
EXPECT_EQ(6, request_.GetTotalMatchCount());
EXPECT_EQ(1, request_.GetMatchCountForSelectedFrame());
......
......@@ -34,14 +34,12 @@ class WebFrameUtilTest : public PlatformTest {
TEST_F(WebFrameUtilTest, GetMainFrame) {
// Still no main frame.
EXPECT_EQ(nullptr, GetMainFrame(&test_web_state_));
auto iframe =
std::make_unique<FakeWebFrame>("iframe", false, GURL::EmptyGURL());
auto iframe = std::make_unique<FakeChildWebFrame>(GURL::EmptyGURL());
fake_web_frames_manager_->AddWebFrame(std::move(iframe));
// Still no main frame.
EXPECT_EQ(nullptr, GetMainFrame(&test_web_state_));
auto main_frame =
std::make_unique<FakeWebFrame>("main_frame", true, GURL::EmptyGURL());
auto main_frame = std::make_unique<FakeMainWebFrame>(GURL::EmptyGURL());
FakeWebFrame* main_frame_ptr = main_frame.get();
fake_web_frames_manager_->AddWebFrame(std::move(main_frame));
// Now there is a main frame.
......@@ -56,18 +54,16 @@ TEST_F(WebFrameUtilTest, GetMainFrame) {
TEST_F(WebFrameUtilTest, GetMainWebFrameId) {
// Still no main frame.
EXPECT_TRUE(GetMainWebFrameId(&test_web_state_).empty());
auto iframe =
std::make_unique<FakeWebFrame>("iframe", false, GURL::EmptyGURL());
auto iframe = std::make_unique<FakeChildWebFrame>(GURL::EmptyGURL());
fake_web_frames_manager_->AddWebFrame(std::move(iframe));
// Still no main frame.
EXPECT_TRUE(GetMainWebFrameId(&test_web_state_).empty());
auto main_frame =
std::make_unique<FakeWebFrame>("main_frame", true, GURL::EmptyGURL());
auto main_frame = std::make_unique<FakeMainWebFrame>(GURL::EmptyGURL());
FakeWebFrame* main_frame_ptr = main_frame.get();
fake_web_frames_manager_->AddWebFrame(std::move(main_frame));
// Now there is a main frame.
EXPECT_EQ("main_frame", GetMainWebFrameId(&test_web_state_));
EXPECT_EQ(kMainFakeFrameId, GetMainWebFrameId(&test_web_state_));
fake_web_frames_manager_->RemoveWebFrame(main_frame_ptr->GetFrameId());
// Now there is no main frame.
......@@ -77,37 +73,36 @@ TEST_F(WebFrameUtilTest, GetMainWebFrameId) {
// Tests the GetWebFrameWithId function.
TEST_F(WebFrameUtilTest, GetWebFrameWithId) {
// Still no main frame.
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "iframe"));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "main_frame"));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, kChildFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, kMainFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "unused"));
auto iframe =
std::make_unique<FakeWebFrame>("iframe", false, GURL::EmptyGURL());
auto iframe = std::make_unique<FakeChildWebFrame>(GURL::EmptyGURL());
FakeWebFrame* iframe_ptr = iframe.get();
fake_web_frames_manager_->AddWebFrame(std::move(iframe));
// There is an iframe.
EXPECT_EQ(iframe_ptr, GetWebFrameWithId(&test_web_state_, "iframe"));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "main_frame"));
EXPECT_EQ(iframe_ptr, GetWebFrameWithId(&test_web_state_, kChildFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, kMainFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "unused"));
auto main_frame =
std::make_unique<FakeWebFrame>("main_frame", true, GURL::EmptyGURL());
auto main_frame = std::make_unique<FakeMainWebFrame>(GURL::EmptyGURL());
FakeWebFrame* main_frame_ptr = main_frame.get();
fake_web_frames_manager_->AddWebFrame(std::move(main_frame));
// Now there is a main frame.
EXPECT_EQ(iframe_ptr, GetWebFrameWithId(&test_web_state_, "iframe"));
EXPECT_EQ(main_frame_ptr, GetWebFrameWithId(&test_web_state_, "main_frame"));
EXPECT_EQ(iframe_ptr, GetWebFrameWithId(&test_web_state_, kChildFakeFrameId));
EXPECT_EQ(main_frame_ptr,
GetWebFrameWithId(&test_web_state_, kMainFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "unused"));
fake_web_frames_manager_->RemoveWebFrame(main_frame_ptr->GetFrameId());
// Now there is only an iframe.
EXPECT_EQ(iframe_ptr, GetWebFrameWithId(&test_web_state_, "iframe"));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "main_frame"));
EXPECT_EQ(iframe_ptr, GetWebFrameWithId(&test_web_state_, kChildFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, kMainFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "unused"));
// Now there nothing left.
fake_web_frames_manager_->RemoveWebFrame(iframe_ptr->GetFrameId());
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "iframe"));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "main_frame"));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, kChildFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, kMainFakeFrameId));
EXPECT_EQ(nullptr, GetWebFrameWithId(&test_web_state_, "unused"));
// Test that GetWebFrameWithId returns nullptr for the empty string.
......@@ -117,20 +112,18 @@ TEST_F(WebFrameUtilTest, GetWebFrameWithId) {
// Tests the GetWebFrameId GetWebFrameId function.
TEST_F(WebFrameUtilTest, GetWebFrameId) {
EXPECT_EQ(std::string(), GetWebFrameId(nullptr));
FakeWebFrame frame("frame", true, GURL::EmptyGURL());
EXPECT_EQ("frame", GetWebFrameId(&frame));
FakeMainWebFrame frame(GURL::EmptyGURL());
EXPECT_EQ(kMainFakeFrameId, GetWebFrameId(&frame));
}
// Tests the GetAllWebFrames function.
TEST_F(WebFrameUtilTest, GetAllWebFrames) {
EXPECT_EQ(0U,
test_web_state_.GetWebFramesManager()->GetAllWebFrames().size());
auto main_frame =
std::make_unique<FakeWebFrame>("main_frame", true, GURL::EmptyGURL());
auto main_frame = std::make_unique<FakeMainWebFrame>(GURL::EmptyGURL());
FakeWebFrame* main_frame_ptr = main_frame.get();
fake_web_frames_manager_->AddWebFrame(std::move(main_frame));
auto iframe =
std::make_unique<FakeWebFrame>("iframe", false, GURL::EmptyGURL());
auto iframe = std::make_unique<FakeChildWebFrame>(GURL::EmptyGURL());
FakeWebFrame* iframe_ptr = iframe.get();
fake_web_frames_manager_->AddWebFrame(std::move(iframe));
std::set<WebFrame*> all_frames =
......
......@@ -5,6 +5,7 @@
#include "ios/web/js_messaging/web_frames_manager_impl.h"
#include "base/base64.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "crypto/symmetric_key.h"
......@@ -161,6 +162,14 @@ void WebFramesManagerImpl::OnFrameBecameAvailable(WKScriptMessage* message) {
std::string frame_id = base::SysNSStringToUTF8(message.body[@"crwFrameId"]);
if (!GetFrameWithId(frame_id)) {
// Validate |frame_id| is a proper hex string.
for (const char& c : frame_id) {
if (!base::IsHexDigit(c)) {
// Ignore frame if |frame_id| is malformed.
return;
}
}
GURL message_frame_origin =
web::GURLOriginWithWKSecurityOrigin(message.frameInfo.securityOrigin);
......
......@@ -20,11 +20,6 @@
namespace {
// Frame ids are base16 string of 128 bit numbers.
const char kMainFrameId[] = "1effd8f52a067c8d3a01762d3c41dfd1";
const char kFrame1Id[] = "1effd8f52a067c8d3a01762d3c41dfd2";
const char kFrame2Id[] = "1effd8f52a067c8d3a01762d3c41dfd3";
// A base64 encoded sample key.
const char kFrameKey[] = "R7lsXtR74c6R9A9k691gUQ8JAd0be+w//Lntgcbjwrc=";
......@@ -46,13 +41,13 @@ class WebFramesManagerImplTest : public PlatformTest,
router_([[CRWWKScriptMessageRouter alloc]
initWithUserContentController:user_content_controller_]),
web_view_(OCMClassMock([WKWebView class])),
main_frame_(kMainFrameId,
main_frame_(kMainFakeFrameId,
/*is_main_frame=*/true,
GURL("https://www.main.test")),
frame_1_(kFrame1Id,
frame_1_(kChildFakeFrameId,
/*is_main_frame=*/false,
GURL("https://www.frame1.test")),
frame_2_(kFrame2Id,
frame_2_(kChildFakeFrameId2,
/*is_main_frame=*/false,
GURL("https://www.frame2.test")) {
// Notify |frames_manager_| that its associated WKWebView has changed from
......@@ -163,6 +158,16 @@ TEST_F(WebFramesManagerImplTest, MainWebFrame) {
EXPECT_FALSE(frames_manager_.GetFrameWithId(main_frame_.GetFrameId()));
}
// Tests that a WebFrame can not be registered with a malformed frame id.
TEST_F(WebFramesManagerImplTest, WebFrameWithInvalidId) {
FakeWebFrame frame_with_invalid_id(kInvalidFrameId,
/*is_main_frame=*/true,
GURL("https://www.main.test"));
SendFrameBecameAvailableMessage(frame_with_invalid_id);
EXPECT_EQ(0ul, frames_manager_.GetAllWebFrames().size());
}
// Tests multiple web frames construction/destruction.
TEST_F(WebFramesManagerImplTest, MultipleWebFrame) {
// Add main frame.
......
......@@ -16,6 +16,12 @@
namespace web {
// Frame ids are base16 string of 128 bit numbers.
const char kMainFakeFrameId[] = "1effd8f52a067c8d3a01762d3c41dfd1";
const char kInvalidFrameId[] = "1effd8f52a067c8d3a01762d3c4;dfd1";
const char kChildFakeFrameId[] = "1effd8f52a067c8d3a01762d3c41dfd2";
const char kChildFakeFrameId2[] = "1effd8f52a067c8d3a01762d3c41dfd3";
FakeWebFrame::FakeWebFrame(const std::string& frame_id,
bool is_main_frame,
GURL security_origin)
......@@ -81,4 +87,18 @@ void FakeWebFrame::AddJsResultForFunctionCall(
result_map_[function_name] = std::move(js_result);
}
// FakeMainWebFrame
FakeMainWebFrame::FakeMainWebFrame(GURL security_origin)
: FakeWebFrame(kMainFakeFrameId, /*is_main_frame=*/true, security_origin) {}
FakeMainWebFrame::~FakeMainWebFrame() {}
// FakeChildWebFrame
FakeChildWebFrame::FakeChildWebFrame(GURL security_origin)
: FakeWebFrame(kChildFakeFrameId,
/*is_main_frame=*/false,
security_origin) {}
FakeChildWebFrame::~FakeChildWebFrame() {}
} // namespace web
......@@ -13,8 +13,18 @@
namespace web {
// Frame id constants which can be used to initialize FakeWebFrame.
// Frame ids are base16 string of 128 bit numbers.
extern const char kMainFakeFrameId[];
extern const char kInvalidFrameId[];
extern const char kChildFakeFrameId[];
extern const char kChildFakeFrameId2[];
// A fake web frame to use for testing.
class FakeWebFrame : public WebFrame {
public:
// Creates a web frame. |frame_id| must be a string representing a valid
// hexadecimal number.
FakeWebFrame(const std::string& frame_id,
bool is_main_frame,
GURL security_origin);
......@@ -77,6 +87,22 @@ class FakeWebFrame : public WebFrame {
bool can_call_function_ = true;
};
// A fake web frame representing the main frame with a |frame_id_| of
// |kMainFakeFrameId|.
class FakeMainWebFrame : public FakeWebFrame {
public:
explicit FakeMainWebFrame(GURL security_origin);
~FakeMainWebFrame() override;
};
// A fake web frame representing a child frame with a |frame_id_| of
// |kChildFakeFrameId|.
class FakeChildWebFrame : public FakeWebFrame {
public:
explicit FakeChildWebFrame(GURL security_origin);
~FakeChildWebFrame() override;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_FRAME_H_
......@@ -312,7 +312,7 @@ TEST_F(WebStateImplTest, ObserverTest) {
// Test that WebFrameDidBecomeAvailable() is called.
ASSERT_FALSE(observer->web_frame_available_info());
web::FakeWebFrame main_frame("main", true, GURL());
web::FakeMainWebFrame main_frame(GURL::EmptyGURL());
web_state_->OnWebFrameAvailable(&main_frame);
ASSERT_TRUE(observer->web_frame_available_info());
EXPECT_EQ(web_state_.get(), observer->web_frame_available_info()->web_state);
......@@ -815,7 +815,7 @@ TEST_F(WebStateImplTest, ScriptCommand) {
value_1.SetString("a", "b");
const GURL kUrl1("http://foo");
bool is_called_1 = false;
web::FakeWebFrame main_frame("main", true, GURL());
web::FakeMainWebFrame main_frame(GURL::EmptyGURL());
auto subscription_1 = web_state_->AddScriptCommandCallback(
base::BindRepeating(&HandleScriptCommand, &is_called_1, &value_1, kUrl1,
/*expected_user_is_interacting*/ false, &main_frame),
......@@ -838,7 +838,7 @@ TEST_F(WebStateImplTest, ScriptCommand) {
value_3.SetString("e", "f");
const GURL kUrl3("http://iframe");
bool is_called_3 = false;
web::FakeWebFrame subframe("subframe", false, GURL());
web::FakeChildWebFrame subframe(GURL::EmptyGURL());
auto subscription_3 = web_state_->AddScriptCommandCallback(
base::BindRepeating(&HandleScriptCommand, &is_called_3, &value_3, kUrl3,
/*expected_user_is_interacting*/ false, &subframe),
......
......@@ -63,7 +63,6 @@ NSString* const kTestFormName = @"FormName";
uint32_t kTestUniqueFormID = 0;
NSString* const kTestFieldIdentifier = @"FieldIdentifier";
uint32_t kTestUniqueFieldID = 1;
NSString* const kTestFrameId = @"FrameID";
NSString* const kTestFieldValue = @"FieldValue";
NSString* const kTestDisplayDescription = @"DisplayDescription";
......@@ -89,6 +88,8 @@ class CWVAutofillControllerTest : public PlatformTest {
[[FakeAutofillAgent alloc] initWithPrefService:&pref_service_
webState:&web_state_];
frame_id_ = base::SysUTF8ToNSString(web::kMainFakeFrameId);
auto frames_manager = std::make_unique<web::FakeWebFramesManager>();
web_frames_manager_ = frames_manager.get();
web_state_.SetWebFramesManager(std::move(frames_manager));
......@@ -140,6 +141,7 @@ class CWVAutofillControllerTest : public PlatformTest {
autofill::TestPersonalDataManager personal_data_manager_;
autofill::TestStrikeDatabase strike_database_;
syncer::TestSyncService sync_service_;
NSString* frame_id_;
web::FakeWebFramesManager* web_frames_manager_;
CWVAutofillController* autofill_controller_;
FakeAutofillAgent* autofill_agent_;
......@@ -160,7 +162,7 @@ TEST_F(CWVAutofillControllerTest, FetchProfileSuggestions) {
[autofill_agent_ addSuggestion:suggestion
forFormName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId];
frameID:frame_id_];
__block BOOL fetch_completion_was_called = NO;
id fetch_completion = ^(NSArray<CWVAutofillSuggestion*>* suggestions) {
......@@ -174,7 +176,7 @@ TEST_F(CWVAutofillControllerTest, FetchProfileSuggestions) {
[autofill_controller_ fetchSuggestionsForFormWithName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
fieldType:@""
frameID:kTestFrameId
frameID:frame_id_
completionHandler:fetch_completion];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForActionTimeout, ^bool {
......@@ -193,18 +195,18 @@ TEST_F(CWVAutofillControllerTest, FetchPasswordSuggestions) {
[autofill_agent_ addSuggestion:suggestion
forFormName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId];
frameID:frame_id_];
CWVAutofillSuggestion* passwordSuggestion =
[[CWVAutofillSuggestion alloc] initWithFormSuggestion:suggestion
formName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId
frameID:frame_id_
isPasswordSuggestion:YES];
[password_controller_ addPasswordSuggestion:passwordSuggestion
formName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId];
frameID:frame_id_];
__block BOOL fetch_completion_was_called = NO;
id fetch_completion = ^(NSArray<CWVAutofillSuggestion*>* suggestions) {
......@@ -220,7 +222,7 @@ TEST_F(CWVAutofillControllerTest, FetchPasswordSuggestions) {
[autofill_controller_ fetchSuggestionsForFormWithName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
fieldType:@""
frameID:kTestFrameId
frameID:frame_id_
completionHandler:fetch_completion];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForActionTimeout, ^bool {
......@@ -240,7 +242,7 @@ TEST_F(CWVAutofillControllerTest, AcceptSuggestion) {
[[CWVAutofillSuggestion alloc] initWithFormSuggestion:form_suggestion
formName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId
frameID:frame_id_
isPasswordSuggestion:NO];
__block BOOL accept_completion_was_called = NO;
[autofill_controller_ acceptSuggestion:suggestion
......@@ -256,18 +258,17 @@ TEST_F(CWVAutofillControllerTest, AcceptSuggestion) {
form_suggestion,
[autofill_agent_ selectedSuggestionForFormName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId]);
frameID:frame_id_]);
}
// Tests CWVAutofillController clears form.
TEST_F(CWVAutofillControllerTest, ClearForm) {
auto frame = std::make_unique<web::FakeWebFrame>(
base::SysNSStringToUTF8(kTestFrameId), true, GURL::EmptyGURL());
auto frame = std::make_unique<web::FakeMainWebFrame>(GURL::EmptyGURL());
AddWebFrame(std::move(frame));
__block BOOL clear_form_completion_was_called = NO;
[autofill_controller_ clearFormWithName:kTestFormName
fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId
frameID:frame_id_
completionHandler:^{
clear_form_completion_was_called = YES;
}];
......@@ -279,7 +280,7 @@ TEST_F(CWVAutofillControllerTest, ClearForm) {
EXPECT_NSEQ(kTestFormName, js_autofill_manager_.lastClearedFormName);
EXPECT_NSEQ(kTestFieldIdentifier,
js_autofill_manager_.lastClearedFieldIdentifier);
EXPECT_NSEQ(kTestFrameId, js_autofill_manager_.lastClearedFrameIdentifier);
EXPECT_NSEQ(frame_id_, js_autofill_manager_.lastClearedFrameIdentifier);
}
// Tests CWVAutofillController focus previous field.
......@@ -318,7 +319,7 @@ TEST_F(CWVAutofillControllerTest, FocusCallback) {
didFocusOnFieldWithIdentifier:kTestFieldIdentifier
fieldType:@""
formName:kTestFormName
frameID:kTestFrameId
frameID:frame_id_
value:kTestFieldValue
userInitiated:YES];
......@@ -328,11 +329,10 @@ TEST_F(CWVAutofillControllerTest, FocusCallback) {
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.unique_field_id = kTestUniqueFieldID;
params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.frame_id = base::SysNSStringToUTF8(kTestFrameId);
params.frame_id = web::kMainFakeFrameId;
params.has_user_gesture = true;
params.type = "focus";
web::FakeWebFrame frame(base::SysNSStringToUTF8(kTestFrameId), true,
GURL::EmptyGURL());
web::FakeMainWebFrame frame(GURL::EmptyGURL());
form_activity_tab_helper_->FormActivityRegistered(&frame, params);
[delegate verify];
}
......@@ -346,7 +346,7 @@ TEST_F(CWVAutofillControllerTest, InputCallback) {
didInputInFieldWithIdentifier:kTestFieldIdentifier
fieldType:@""
formName:kTestFormName
frameID:kTestFrameId
frameID:frame_id_
value:kTestFieldValue
userInitiated:YES];
......@@ -354,11 +354,10 @@ TEST_F(CWVAutofillControllerTest, InputCallback) {
params.form_name = base::SysNSStringToUTF8(kTestFormName);
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.frame_id = base::SysNSStringToUTF8(kTestFrameId);
params.frame_id = web::kMainFakeFrameId;
params.type = "input";
params.has_user_gesture = true;
web::FakeWebFrame frame(base::SysNSStringToUTF8(kTestFrameId), true,
GURL::EmptyGURL());
web::FakeMainWebFrame frame(GURL::EmptyGURL());
form_activity_tab_helper_->FormActivityRegistered(&frame, params);
[delegate verify];
}
......@@ -368,26 +367,25 @@ TEST_F(CWVAutofillControllerTest, BlurCallback) {
id delegate = OCMProtocolMock(@protocol(CWVAutofillControllerDelegate));
autofill_controller_.delegate = delegate;
[[delegate expect] autofillController:autofill_controller_
didBlurOnFieldWithIdentifier:kTestFieldIdentifier
fieldType:@""
formName:kTestFormName
frameID:kTestFrameId
value:kTestFieldValue
userInitiated:YES];
autofill::FormActivityParams params;
params.form_name = base::SysNSStringToUTF8(kTestFormName);
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.frame_id = base::SysNSStringToUTF8(kTestFrameId);
params.type = "blur";
params.has_user_gesture = true;
web::FakeWebFrame frame(base::SysNSStringToUTF8(kTestFrameId), true,
GURL::EmptyGURL());
form_activity_tab_helper_->FormActivityRegistered(&frame, params);
[delegate verify];
[[delegate expect] autofillController:autofill_controller_
didBlurOnFieldWithIdentifier:kTestFieldIdentifier
fieldType:@""
formName:kTestFormName
frameID:frame_id_
value:kTestFieldValue
userInitiated:YES];
autofill::FormActivityParams params;
params.form_name = base::SysNSStringToUTF8(kTestFormName);
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.frame_id = web::kMainFakeFrameId;
params.type = "blur";
params.has_user_gesture = true;
web::FakeMainWebFrame frame(GURL::EmptyGURL());
form_activity_tab_helper_->FormActivityRegistered(&frame, params);
[delegate verify];
}
// Tests CWVAutofillController delegate submit callback is invoked.
......@@ -395,30 +393,29 @@ TEST_F(CWVAutofillControllerTest, SubmitCallback) {
id delegate = OCMProtocolMock(@protocol(CWVAutofillControllerDelegate));
autofill_controller_.delegate = delegate;
[[delegate expect] autofillController:autofill_controller_
didSubmitFormWithName:kTestFormName
frameID:kTestFrameId
userInitiated:YES];
web::FakeWebFrame frame(base::SysNSStringToUTF8(kTestFrameId), true,
GURL::EmptyGURL());
form_activity_tab_helper_->DocumentSubmitted(
/*sender_frame*/ &frame, base::SysNSStringToUTF8(kTestFormName),
/*form_data=*/"",
/*user_initiated=*/true,
/*is_main_frame=*/true);
[[delegate expect] autofillController:autofill_controller_
didSubmitFormWithName:kTestFormName
frameID:kTestFrameId
userInitiated:NO];
form_activity_tab_helper_->DocumentSubmitted(
/*sender_frame*/ &frame, base::SysNSStringToUTF8(kTestFormName),
/*form_data=*/"",
/*user_initiated=*/false,
/*is_main_frame=*/true);
[delegate verify];
[[delegate expect] autofillController:autofill_controller_
didSubmitFormWithName:kTestFormName
frameID:frame_id_
userInitiated:YES];
web::FakeMainWebFrame frame(GURL::EmptyGURL());
form_activity_tab_helper_->DocumentSubmitted(
/*sender_frame*/ &frame, base::SysNSStringToUTF8(kTestFormName),
/*form_data=*/"",
/*user_initiated=*/true,
/*is_main_frame=*/true);
[[delegate expect] autofillController:autofill_controller_
didSubmitFormWithName:kTestFormName
frameID:frame_id_
userInitiated:NO];
form_activity_tab_helper_->DocumentSubmitted(
/*sender_frame*/ &frame, base::SysNSStringToUTF8(kTestFormName),
/*form_data=*/"",
/*user_initiated=*/false,
/*is_main_frame=*/true);
[delegate verify];
}
} // namespace ios_web_view
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