Commit 01d9f933 authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Show touch to fill UI only once per page load.

Bug: 957532

Change-Id: I07b8dac342b519e11329f513bb276580aa39d4bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831858
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701212}
parent d65e70b7
...@@ -1701,7 +1701,7 @@ TEST_F(PasswordAutofillAgentTest, ...@@ -1701,7 +1701,7 @@ TEST_F(PasswordAutofillAgentTest,
// Tests that TryToShowTouchToFill() works correctly for fillable and // Tests that TryToShowTouchToFill() works correctly for fillable and
// non-fillable fields. // non-fillable fields.
TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFill) { TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillUsername) {
// Initially no fill data is available. // Initially no fill data is available.
WebInputElement random_element = GetInputElementByID("random_field"); WebInputElement random_element = GetInputElementByID("random_field");
EXPECT_FALSE( EXPECT_FALSE(
...@@ -1718,13 +1718,40 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFill) { ...@@ -1718,13 +1718,40 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFill) {
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(username_element_)); password_autofill_agent_->TryToShowTouchToFill(username_element_));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
}
TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillPassword) {
SimulateOnFillPasswordForm(fill_data_);
EXPECT_CALL(fake_driver_, ShowTouchToFill); EXPECT_CALL(fake_driver_, ShowTouchToFill);
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_)); password_autofill_agent_->TryToShowTouchToFill(password_element_));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
}
EXPECT_FALSE(password_autofill_agent_->TryToShowTouchToFill(random_element)); TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillShownOnlyOnce) {
SimulateOnFillPasswordForm(fill_data_);
password_autofill_agent_->TryToShowTouchToFill(username_element_);
base::RunLoop().RunUntilIdle();
// Touch to fill is shown not more than one time per page load. Check that.
EXPECT_FALSE(
password_autofill_agent_->TryToShowTouchToFill(username_element_));
EXPECT_FALSE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
// Reload the page and simulate fill.
LoadHTML(kFormHTML);
UpdateOriginForHTML(kFormHTML);
UpdateUsernameAndPasswordElements();
SimulateOnFillPasswordForm(fill_data_);
// After the reload touch to fill is shown again.
EXPECT_CALL(fake_driver_, ShowTouchToFill);
EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
base::RunLoop().RunUntilIdle();
} }
// Tests that |FillIntoFocusedField| doesn't fill read-only text fields. // Tests that |FillIntoFocusedField| doesn't fill read-only text fields.
......
...@@ -772,6 +772,9 @@ bool PasswordAutofillAgent::TryToShowTouchToFill( ...@@ -772,6 +772,9 @@ bool PasswordAutofillAgent::TryToShowTouchToFill(
!base::Contains(password_to_username_, *element))) { !base::Contains(password_to_username_, *element))) {
return false; return false;
} }
if (was_touch_to_fill_ui_shown_)
return false;
was_touch_to_fill_ui_shown_ = true;
GetPasswordManagerDriver()->ShowTouchToFill(); GetPasswordManagerDriver()->ShowTouchToFill();
return true; return true;
...@@ -1340,6 +1343,7 @@ void PasswordAutofillAgent::CleanupOnDocumentShutdown() { ...@@ -1340,6 +1343,7 @@ void PasswordAutofillAgent::CleanupOnDocumentShutdown() {
autofilled_elements_cache_.clear(); autofilled_elements_cache_.clear();
last_updated_field_renderer_id_ = FormData::kNotSetFormRendererId; last_updated_field_renderer_id_ = FormData::kNotSetFormRendererId;
last_updated_form_renderer_id_ = FormData::kNotSetFormRendererId; last_updated_form_renderer_id_ = FormData::kNotSetFormRendererId;
was_touch_to_fill_ui_shown_ = false;
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
page_passwords_analyser_.Reset(); page_passwords_analyser_.Reset();
#endif #endif
......
...@@ -533,6 +533,8 @@ class PasswordAutofillAgent : public content::RenderFrameObserver, ...@@ -533,6 +533,8 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
// Contains renderer id of the form of the last updated input element. // Contains renderer id of the form of the last updated input element.
uint32_t last_updated_form_renderer_id_ = FormData::kNotSetFormRendererId; uint32_t last_updated_form_renderer_id_ = FormData::kNotSetFormRendererId;
bool was_touch_to_fill_ui_shown_ = false;
DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
}; };
......
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