Commit b2cb08ab authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Mfill android] Don't show manual generation dialog if focus changed

If the focused field changes between the user manually requesting to
generate a password and the callback coming back from the renderer to
show the dialog, the callback should be ignored and the dialog should
not be shown. This is because it is no longer relevant to the current
focused field.

Bug: 835234
Change-Id: Ic778d504b9aa07c12238ddc8ad4dada317801542
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1655433Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668407}
parent 0f886e93
......@@ -128,7 +128,8 @@ void PasswordGenerationControllerImpl::OnAutomaticGenerationAvailable(
void PasswordGenerationControllerImpl::ShowManualGenerationDialog(
const password_manager::PasswordManagerDriver* target_frame_driver,
const autofill::password_generation::PasswordGenerationUIData& ui_data) {
if (!IsActiveFrameDriver(target_frame_driver))
if (!IsActiveFrameDriver(target_frame_driver) ||
!manual_generation_requested_)
return;
generation_element_data_ = std::make_unique<GenerationElementData>(ui_data);
ShowDialog(true /* manual */);
......@@ -144,6 +145,7 @@ void PasswordGenerationControllerImpl::FocusedInputChanged(
void PasswordGenerationControllerImpl::OnGenerationRequested(bool manual) {
if (manual) {
manual_generation_requested_ = true;
ChromePasswordManagerClient::FromWebContents(web_contents_)
->GeneratePassword();
} else {
......@@ -241,6 +243,7 @@ void PasswordGenerationControllerImpl::ResetState() {
active_frame_driver_.reset();
generation_element_data_.reset();
dialog_view_.reset();
manual_generation_requested_ = false;
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(PasswordGenerationControllerImpl)
......@@ -116,6 +116,10 @@ class PasswordGenerationControllerImpl
// Creation callback for the modal dialog view meant to facilitate testing.
CreateDialogFactory create_dialog_factory_;
// Whether manual generation was requested from the UI. Used to filter out
// unexpected or delayed manual generation responses from the renderer.
bool manual_generation_requested_ = false;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationControllerImpl);
......
......@@ -7,6 +7,7 @@
#include <utility>
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
......@@ -53,6 +54,7 @@ class TestPasswordManagerClient : public ChromePasswordManagerClient {
~TestPasswordManagerClient() override;
bool IsSavingAndFillingEnabled(const GURL& url) const override;
void GeneratePassword() override;
password_manager::PasswordStore* GetPasswordStore() const override;
private:
......@@ -89,6 +91,8 @@ bool TestPasswordManagerClient::IsSavingAndFillingEnabled(
return true;
}
void TestPasswordManagerClient::GeneratePassword() {}
password_manager::PasswordStore* TestPasswordManagerClient::GetPasswordStore()
const {
return mock_password_store_.get();
......@@ -412,6 +416,8 @@ TEST_F(PasswordGenerationControllerTest,
TEST_F(PasswordGenerationControllerTest, HidesDialogWhenFocusChanges) {
base::string16 test_password = ASCIIToUTF16("t3stp@ssw0rd");
InitializeManualGeneration(test_password);
controller()->OnGenerationRequested(true);
NiceMock<MockPasswordGenerationDialogView>* raw_dialog_view =
mock_dialog_.get();
EXPECT_CALL(mock_dialog_factory(), Run)
......@@ -433,6 +439,8 @@ TEST_F(PasswordGenerationControllerTest, HidesDialogWhenFocusChanges) {
TEST_F(PasswordGenerationControllerTest, ShowManualDialogForActiveFrame) {
base::string16 test_password = ASCIIToUTF16("t3stp@ssw0rd");
InitializeManualGeneration(test_password);
controller()->OnGenerationRequested(true);
NiceMock<MockPasswordGenerationDialogView>* raw_dialog_view =
mock_dialog_.get();
EXPECT_CALL(mock_dialog_factory(), Run)
......@@ -455,6 +463,7 @@ TEST_F(PasswordGenerationControllerTest,
TEST_F(PasswordGenerationControllerTest, DontShowDialogIfAlreadyShown) {
base::string16 test_password = ASCIIToUTF16("t3stp@ssw0rd");
InitializeManualGeneration(test_password);
controller()->OnGenerationRequested(true);
NiceMock<MockPasswordGenerationDialogView>* raw_dialog_view =
mock_dialog_.get();
......@@ -471,3 +480,18 @@ TEST_F(PasswordGenerationControllerTest, DontShowDialogIfAlreadyShown) {
controller()->ShowManualGenerationDialog(mock_password_manager_driver_.get(),
GetTestGenerationUIData1());
}
TEST_F(PasswordGenerationControllerTest, DontShowManualDialogIfFocusChanged) {
base::string16 test_password = ASCIIToUTF16("t3stp@ssw0rd");
InitializeManualGeneration(test_password);
controller()->OnGenerationRequested(true);
EXPECT_CALL(mock_manual_filling_controller_,
OnAutomaticGenerationStatusChanged(false));
controller()->FocusedInputChanged(
FocusedFieldType::kFillablePasswordField,
base::AsWeakPtr(mock_password_manager_driver_.get()));
EXPECT_CALL(mock_dialog_factory(), Run).Times(0);
controller()->ShowManualGenerationDialog(mock_password_manager_driver_.get(),
GetTestGenerationUIData1());
}
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