Commit 7f927fda authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Preview fill for Touch To Fill

This change implements highlighting the username and password field that
are about to be filled in by Touch To Fill.

Bug: 1013182
Change-Id: I778dddef757641aede49c682e83da69606313dbc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1859979Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705906}
parent e881c531
...@@ -1718,6 +1718,8 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillUsername) { ...@@ -1718,6 +1718,8 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillUsername) {
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(username_element_)); password_autofill_agent_->TryToShowTouchToFill(username_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard()); EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
EXPECT_EQ(WebAutofillState::kPreviewed, username_element_.GetAutofillState());
EXPECT_EQ(WebAutofillState::kPreviewed, password_element_.GetAutofillState());
EXPECT_CALL(fake_driver_, ShowTouchToFill); EXPECT_CALL(fake_driver_, ShowTouchToFill);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -1729,6 +1731,7 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillPassword) { ...@@ -1729,6 +1731,7 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillPassword) {
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_)); password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard()); EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
EXPECT_EQ(WebAutofillState::kPreviewed, password_element_.GetAutofillState());
EXPECT_CALL(fake_driver_, ShowTouchToFill); EXPECT_CALL(fake_driver_, ShowTouchToFill);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -1745,19 +1748,23 @@ TEST_F(PasswordAutofillAgentTest, DontTryToShowTouchToFillReadonlyPassword) { ...@@ -1745,19 +1748,23 @@ TEST_F(PasswordAutofillAgentTest, DontTryToShowTouchToFillReadonlyPassword) {
TEST_F(PasswordAutofillAgentTest, TouchToFillDismissed) { TEST_F(PasswordAutofillAgentTest, TouchToFillDismissed) {
SimulateOnFillPasswordForm(fill_data_); SimulateOnFillPasswordForm(fill_data_);
auto previous_state = password_element_.GetAutofillState();
// Touch to fill will be shown multiple times until TouchToFillDismissed() // Touch to fill will be shown multiple times until TouchToFillDismissed()
// gets called. // gets called.
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_)); password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard()); EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
EXPECT_EQ(WebAutofillState::kPreviewed, password_element_.GetAutofillState());
EXPECT_CALL(fake_driver_, ShowTouchToFill); EXPECT_CALL(fake_driver_, ShowTouchToFill);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Make sure that resetting Touch To Fill resets the Autofill state.
password_autofill_agent_->TouchToFillDismissed(); password_autofill_agent_->TouchToFillDismissed();
EXPECT_FALSE( EXPECT_FALSE(
password_autofill_agent_->TryToShowTouchToFill(password_element_)); password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_FALSE(password_autofill_agent_->ShouldSuppressKeyboard()); EXPECT_FALSE(password_autofill_agent_->ShouldSuppressKeyboard());
EXPECT_EQ(previous_state, password_element_.GetAutofillState());
// Reload the page and simulate fill. // Reload the page and simulate fill.
LoadHTML(kFormHTML); LoadHTML(kFormHTML);
...@@ -1769,6 +1776,7 @@ TEST_F(PasswordAutofillAgentTest, TouchToFillDismissed) { ...@@ -1769,6 +1776,7 @@ TEST_F(PasswordAutofillAgentTest, TouchToFillDismissed) {
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_)); password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard()); EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
EXPECT_EQ(WebAutofillState::kPreviewed, password_element_.GetAutofillState());
EXPECT_CALL(fake_driver_, ShowTouchToFill); EXPECT_CALL(fake_driver_, ShowTouchToFill);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -784,20 +784,33 @@ bool PasswordAutofillAgent::TryToShowTouchToFill( ...@@ -784,20 +784,33 @@ bool PasswordAutofillAgent::TryToShowTouchToFill(
if (touch_to_fill_state_ != TouchToFillState::kShouldShow) if (touch_to_fill_state_ != TouchToFillState::kShouldShow)
return false; return false;
const WebInputElement* element = ToWebInputElement(&control_element); const WebInputElement* input_element = ToWebInputElement(&control_element);
WebInputElement username_element; WebInputElement username_element;
WebInputElement password_element; WebInputElement password_element;
PasswordInfo* password_info = nullptr; PasswordInfo* password_info = nullptr;
if (!element || if (!input_element ||
!FindPasswordInfoForElement(*element, &username_element, !FindPasswordInfoForElement(*input_element, &username_element,
&password_element, &password_info)) { &password_element, &password_info)) {
return false; return false;
} }
DCHECK(!password_element.IsNull()); // Don't trigger Touch To Fill when there is no password element or it is not
if (!IsElementEditable(password_element)) // editable.
if (password_element.IsNull() || !IsElementEditable(password_element))
return false; return false;
// Highlight the fields that are about to be filled by the user and remember
// the old autofill state of |username_element| and |password_element|.
if (IsUsernameAmendable(username_element,
input_element->IsPasswordFieldForAutofill())) {
username_autofill_state_ = username_element.GetAutofillState();
username_element.SetAutofillState(WebAutofillState::kPreviewed);
}
password_autofill_state_ = password_element.GetAutofillState();
password_element.SetAutofillState(WebAutofillState::kPreviewed);
focused_input_element_ = *input_element;
GetPasswordManagerDriver()->ShowTouchToFill(); GetPasswordManagerDriver()->ShowTouchToFill();
touch_to_fill_state_ = TouchToFillState::kIsShowing; touch_to_fill_state_ = TouchToFillState::kIsShowing;
return true; return true;
...@@ -1208,6 +1221,24 @@ void PasswordAutofillAgent::SetLoggingState(bool active) { ...@@ -1208,6 +1221,24 @@ void PasswordAutofillAgent::SetLoggingState(bool active) {
void PasswordAutofillAgent::TouchToFillDismissed() { void PasswordAutofillAgent::TouchToFillDismissed() {
touch_to_fill_state_ = TouchToFillState::kWasShown; touch_to_fill_state_ = TouchToFillState::kWasShown;
// Clear the autofill state from the username and password element. Note that
// we don't make use of ClearPreview() here, since this is considering the
// elements' SuggestedValue(), which Touch To Fill does not set.
DCHECK(!focused_input_element_.IsNull());
WebInputElement username_element;
WebInputElement password_element;
PasswordInfo* password_info = nullptr;
if (!FindPasswordInfoForElement(focused_input_element_, &username_element,
&password_element, &password_info)) {
return;
}
if (!username_element.IsNull())
username_element.SetAutofillState(username_autofill_state_);
if (!password_element.IsNull())
password_element.SetAutofillState(password_autofill_state_);
} }
void PasswordAutofillAgent::AnnotateFieldsWithParsingResult( void PasswordAutofillAgent::AnnotateFieldsWithParsingResult(
......
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