Commit 53c74300 authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Migrate ManagePasswordsUIControllerTest to mocked PasswordFormManager.

Bug: 998496
Change-Id: I47c837120811b27de1f22fccb35893ccb7c2ebcc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901471Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713375}
parent 8ee61860
...@@ -403,7 +403,7 @@ void ManagePasswordsUIController::OnNopeUpdateClicked() { ...@@ -403,7 +403,7 @@ void ManagePasswordsUIController::OnNopeUpdateClicked() {
void ManagePasswordsUIController::NeverSavePassword() { void ManagePasswordsUIController::NeverSavePassword() {
DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_STATE, GetState()); DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_STATE, GetState());
NeverSavePasswordInternal(); passwords_data_.form_manager()->OnNeverClicked();
ClearPopUpFlagForBubble(); ClearPopUpFlagForBubble();
if (passwords_data_.GetCurrentForms().empty()) if (passwords_data_.GetCurrentForms().empty())
passwords_data_.OnInactive(); passwords_data_.OnInactive();
...@@ -431,11 +431,13 @@ void ManagePasswordsUIController::SavePassword(const base::string16& username, ...@@ -431,11 +431,13 @@ void ManagePasswordsUIController::SavePassword(const base::string16& username,
} }
save_fallback_timer_.Stop(); save_fallback_timer_.Stop();
SavePasswordInternal(); passwords_data_.form_manager()->Save();
passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE);
// The icon is to be updated after the bubble (either "Save password" or "Sign // The icon is to be updated after the bubble (either "Save password" or "Sign
// in to Chrome") is closed. // in to Chrome") is closed.
bubble_status_ = BubbleStatus::SHOWN_PENDING_ICON_UPDATE; bubble_status_ = BubbleStatus::SHOWN_PENDING_ICON_UPDATE;
if (Browser* browser = chrome::FindBrowserWithWebContents(web_contents()))
browser->window()->GetAutofillBubbleHandler()->OnPasswordSaved();
} }
void ManagePasswordsUIController::ChooseCredential( void ManagePasswordsUIController::ChooseCredential(
...@@ -516,21 +518,6 @@ bool ManagePasswordsUIController::ArePasswordsRevealedWhenBubbleIsOpened() ...@@ -516,21 +518,6 @@ bool ManagePasswordsUIController::ArePasswordsRevealedWhenBubbleIsOpened()
return are_passwords_revealed_when_next_bubble_is_opened_; return are_passwords_revealed_when_next_bubble_is_opened_;
} }
void ManagePasswordsUIController::SavePasswordInternal() {
passwords_data_.form_manager()->Save();
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (!browser)
return;
browser->window()->GetAutofillBubbleHandler()->OnPasswordSaved();
}
void ManagePasswordsUIController::NeverSavePasswordInternal() {
password_manager::PasswordFormManagerForUI* form_manager =
passwords_data_.form_manager();
DCHECK(form_manager);
form_manager->OnNeverClicked();
}
void ManagePasswordsUIController::HidePasswordBubble() { void ManagePasswordsUIController::HidePasswordBubble() {
if (TabDialogs* tab_dialogs = TabDialogs::FromWebContents(web_contents())) if (TabDialogs* tab_dialogs = TabDialogs::FromWebContents(web_contents()))
tab_dialogs->HideManagePasswordsBubble(); tab_dialogs->HideManagePasswordsBubble();
......
...@@ -151,11 +151,6 @@ class ManagePasswordsUIController ...@@ -151,11 +151,6 @@ class ManagePasswordsUIController
explicit ManagePasswordsUIController( explicit ManagePasswordsUIController(
content::WebContents* web_contents); content::WebContents* web_contents);
// The pieces of saving and blacklisting passwords that interact with
// FormManager, split off into internal functions for testing/mocking.
virtual void SavePasswordInternal();
virtual void NeverSavePasswordInternal();
// Hides the bubble if opened. Mocked in the tests. // Hides the bubble if opened. Mocked in the tests.
virtual void HidePasswordBubble(); virtual void HidePasswordBubble();
......
...@@ -8,50 +8,42 @@ ...@@ -8,50 +8,42 @@
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/passwords/credential_leak_dialog_controller.h" #include "chrome/browser/ui/passwords/credential_leak_dialog_controller.h"
#include "chrome/browser/ui/passwords/credential_manager_dialog_controller.h" #include "chrome/browser/ui/passwords/credential_manager_dialog_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
#include "chrome/browser/ui/passwords/password_dialog_prompts.h" #include "chrome/browser/ui/passwords/password_dialog_prompts.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h" #include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/fake_form_fetcher.h" #include "components/password_manager/core/browser/mock_password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h" #include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_form_manager.h" #include "components/password_manager/core/browser/password_form_metrics_recorder.h"
#include "components/password_manager/core/browser/statistics_table.h" #include "components/password_manager/core/browser/statistics_table.h"
#include "components/password_manager/core/browser/stub_form_saver.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h" #include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/stub_password_manager_driver.h"
#include "components/password_manager/core/common/password_manager_ui.h" #include "components/password_manager/core/common/password_manager_ui.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/ukm/test_ukm_recorder.h" #include "components/ukm/test_ukm_recorder.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_navigation_handle.h" #include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "content/public/test/web_contents_tester.h" #include "content/public/test/web_contents_tester.h"
#include "services/metrics/public/cpp/ukm_source.h" #include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using autofill::FormData;
using autofill::FormFieldData;
using autofill::PasswordForm; using autofill::PasswordForm;
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using password_manager::PasswordFormManager; using password_manager::MockPasswordFormManagerForUI;
using ::testing::_; using ::testing::_;
using ::testing::AtMost;
using ::testing::Contains; using ::testing::Contains;
using ::testing::DoAll; using ::testing::DoAll;
using ::testing::ElementsAre; using ::testing::ElementsAre;
...@@ -59,6 +51,7 @@ using ::testing::IsEmpty; ...@@ -59,6 +51,7 @@ using ::testing::IsEmpty;
using ::testing::Not; using ::testing::Not;
using ::testing::Pointee; using ::testing::Pointee;
using ::testing::Return; using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::SaveArg; using ::testing::SaveArg;
namespace { namespace {
...@@ -85,15 +78,11 @@ class PasswordLeakDialogMock : public CredentialLeakPrompt { ...@@ -85,15 +78,11 @@ class PasswordLeakDialogMock : public CredentialLeakPrompt {
class TestManagePasswordsIconView : public ManagePasswordsIconView { class TestManagePasswordsIconView : public ManagePasswordsIconView {
public: public:
TestManagePasswordsIconView() = default;
void SetState(password_manager::ui::State state) override { state_ = state; } void SetState(password_manager::ui::State state) override { state_ = state; }
password_manager::ui::State state() { return state_; } password_manager::ui::State state() { return state_; }
private: private:
password_manager::ui::State state_; password_manager::ui::State state_;
DISALLOW_COPY_AND_ASSIGN(TestManagePasswordsIconView);
}; };
// This sublass is used to disable some code paths which are not essential for // This sublass is used to disable some code paths which are not essential for
...@@ -103,7 +92,6 @@ class TestManagePasswordsUIController : public ManagePasswordsUIController { ...@@ -103,7 +92,6 @@ class TestManagePasswordsUIController : public ManagePasswordsUIController {
TestManagePasswordsUIController( TestManagePasswordsUIController(
content::WebContents* contents, content::WebContents* contents,
password_manager::PasswordManagerClient* client); password_manager::PasswordManagerClient* client);
~TestManagePasswordsUIController() override;
bool opened_bubble() const { return opened_bubble_; } bool opened_bubble() const { return opened_bubble_; }
bool opened_automatic_bubble() const { return opened_automatic_bubble_; } bool opened_automatic_bubble() const { return opened_automatic_bubble_; }
...@@ -123,8 +111,6 @@ class TestManagePasswordsUIController : public ManagePasswordsUIController { ...@@ -123,8 +111,6 @@ class TestManagePasswordsUIController : public ManagePasswordsUIController {
private: private:
void UpdateBubbleAndIconVisibility() override; void UpdateBubbleAndIconVisibility() override;
void SavePasswordInternal() override {}
void NeverSavePasswordInternal() override;
void HidePasswordBubble() override; void HidePasswordBubble() override;
bool ShowAuthenticationDialog() override { return true; } bool ShowAuthenticationDialog() override { return true; }
...@@ -144,8 +130,6 @@ TestManagePasswordsUIController::TestManagePasswordsUIController( ...@@ -144,8 +130,6 @@ TestManagePasswordsUIController::TestManagePasswordsUIController(
set_client(client); set_client(client);
} }
TestManagePasswordsUIController::~TestManagePasswordsUIController() = default;
void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() { void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
opened_bubble_ = ShouldBubblePopUp(); opened_bubble_ = ShouldBubblePopUp();
opened_automatic_bubble_ = IsAutomaticallyOpeningBubble(); opened_automatic_bubble_ = IsAutomaticallyOpeningBubble();
...@@ -160,17 +144,6 @@ void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() { ...@@ -160,17 +144,6 @@ void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
} }
} }
void TestManagePasswordsUIController::NeverSavePasswordInternal() {
PasswordForm blacklisted;
blacklisted.origin = this->GetOrigin();
blacklisted.signon_realm = blacklisted.origin.spec();
blacklisted.blacklisted_by_user = true;
password_manager::PasswordStoreChange change(
password_manager::PasswordStoreChange::ADD, blacklisted);
password_manager::PasswordStoreChangeList list(1, change);
OnLoginsChanged(list);
}
void TestManagePasswordsUIController::HidePasswordBubble() { void TestManagePasswordsUIController::HidePasswordBubble() {
opened_automatic_bubble_ = false; opened_automatic_bubble_ = false;
are_passwords_revealed_in_opened_bubble_ = false; are_passwords_revealed_in_opened_bubble_ = false;
...@@ -184,22 +157,15 @@ void TestManagePasswordsUIController::HidePasswordBubble() { ...@@ -184,22 +157,15 @@ void TestManagePasswordsUIController::HidePasswordBubble() {
class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness { class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness {
public: public:
ManagePasswordsUIControllerTest() : field_trial_list_(nullptr) {
fetcher_.Fetch();
}
void SetUp() override; void SetUp() override;
password_manager::StubPasswordManagerClient& client() { return client_; } password_manager::StubPasswordManagerClient& client() { return client_; }
password_manager::FakeFormFetcher& fetcher() { return fetcher_; }
PasswordForm& test_local_form() { return test_local_form_; } PasswordForm& test_local_form() { return test_local_form_; }
PasswordForm& test_federated_form() { return test_federated_form_; } PasswordForm& test_federated_form() { return test_federated_form_; }
FormData& submitted_form() { return submitted_form_; } PasswordForm& submitted_form() { return submitted_form_; }
FormData& observed_form() { return observed_form_; }
CredentialManagementDialogPromptMock& dialog_prompt() { CredentialManagementDialogPromptMock& dialog_prompt() {
return dialog_prompt_; return dialog_prompt_;
} }
password_manager::PasswordManagerDriver& driver() { return driver_; }
TestManagePasswordsUIController* controller() { TestManagePasswordsUIController* controller() {
return static_cast<TestManagePasswordsUIController*>( return static_cast<TestManagePasswordsUIController*>(
...@@ -209,39 +175,20 @@ class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness { ...@@ -209,39 +175,20 @@ class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness {
void ExpectIconStateIs(password_manager::ui::State state); void ExpectIconStateIs(password_manager::ui::State state);
void ExpectIconAndControllerStateIs(password_manager::ui::State state); void ExpectIconAndControllerStateIs(password_manager::ui::State state);
std::unique_ptr<PasswordFormManager> CreateFormManagerWithBestMatches( std::unique_ptr<MockPasswordFormManagerForUI>
const FormData& observed_form, CreateFormManagerWithBestMatches(
const std::vector<const PasswordForm*>& best_matches, const std::vector<const PasswordForm*>* best_matches,
scoped_refptr<password_manager::PasswordFormMetricsRecorder> bool is_blacklisted = false);
metrics_recorder);
std::unique_ptr<PasswordFormManager> CreateFormManagerWithBlacklistedMatches(
const FormData& observed_form,
bool is_blacklisted,
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder);
std::unique_ptr<PasswordFormManager> CreateFormManager();
std::unique_ptr<PasswordFormManager> CreateFormManagerWithMetricsRecorder(
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder);
// Tests that the state is not changed when the password is autofilled. // Tests that the state is not changed when the password is autofilled.
void TestNotChangingStateOnAutofill(password_manager::ui::State state); void TestNotChangingStateOnAutofill(password_manager::ui::State state);
MOCK_METHOD1(CredentialCallback, void(const PasswordForm*));
private: private:
password_manager::StubPasswordManagerClient client_; password_manager::StubPasswordManagerClient client_;
password_manager::StubPasswordManagerDriver driver_;
password_manager::FakeFormFetcher fetcher_;
PasswordForm test_local_form_; PasswordForm test_local_form_;
PasswordForm test_federated_form_; PasswordForm test_federated_form_;
FormData submitted_form_; PasswordForm submitted_form_;
FormData observed_form_;
base::FieldTrialList field_trial_list_;
CredentialManagementDialogPromptMock dialog_prompt_; CredentialManagementDialogPromptMock dialog_prompt_;
}; };
...@@ -264,24 +211,9 @@ void ManagePasswordsUIControllerTest::SetUp() { ...@@ -264,24 +211,9 @@ void ManagePasswordsUIControllerTest::SetUp() {
test_federated_form_.federation_origin = test_federated_form_.federation_origin =
url::Origin::Create(GURL("https://federation.test/")); url::Origin::Create(GURL("https://federation.test/"));
// Create a simple sign-in form. submitted_form_ = test_local_form_;
observed_form_.url = test_local_form_.origin; submitted_form_.username_value = ASCIIToUTF16("submitted_username");
FormFieldData field; submitted_form_.password_value = ASCIIToUTF16("pass12345");
field.name = ASCIIToUTF16("username_element");
field.form_control_type = "text";
observed_form_.fields.push_back(field);
field.name = ASCIIToUTF16("password_element");
field.form_control_type = "password";
observed_form_.fields.push_back(field);
submitted_form_ = observed_form_;
// Set username and password.
submitted_form_.fields[0].value = test_local_form_.username_value;
submitted_form_.fields[1].value = test_local_form_.password_value;
// Turn off waiting for server predictions in order to avoid dealing with
// posted tasks.
PasswordFormManager::set_wait_for_server_predictions_for_filling(false);
// We need to be on a "webby" URL for most tests. // We need to be on a "webby" URL for most tests.
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
...@@ -302,47 +234,35 @@ void ManagePasswordsUIControllerTest::ExpectIconAndControllerStateIs( ...@@ -302,47 +234,35 @@ void ManagePasswordsUIControllerTest::ExpectIconAndControllerStateIs(
EXPECT_EQ(state, controller()->GetState()); EXPECT_EQ(state, controller()->GetState());
} }
std::unique_ptr<PasswordFormManager> std::unique_ptr<MockPasswordFormManagerForUI>
ManagePasswordsUIControllerTest::CreateFormManagerWithBestMatches( ManagePasswordsUIControllerTest::CreateFormManagerWithBestMatches(
const FormData& observed_form, const std::vector<const PasswordForm*>* best_matches,
const std::vector<const PasswordForm*>& best_matches, bool is_blacklisted) {
scoped_refptr<password_manager::PasswordFormMetricsRecorder> auto form_manager =
metrics_recorder) { std::make_unique<testing::StrictMock<MockPasswordFormManagerForUI>>();
auto form_manager = std::make_unique<PasswordFormManager>( EXPECT_CALL(*form_manager, GetBestMatches())
&client_, driver_.AsWeakPtr(), observed_form, &fetcher_, .Times(AtMost(1))
std::make_unique<password_manager::StubFormSaver>(), metrics_recorder); .WillOnce(ReturnRef(*best_matches));
fetcher_.SetNonFederated(best_matches); EXPECT_CALL(*form_manager, GetFederatedMatches())
fetcher_.NotifyFetchCompleted(); .Times(AtMost(1))
return form_manager; .WillOnce(Return(std::vector<const autofill::PasswordForm*>()));
} EXPECT_CALL(*form_manager, GetOrigin())
.Times(AtMost(1))
std::unique_ptr<PasswordFormManager> .WillOnce(ReturnRef(test_local_form_.origin));
ManagePasswordsUIControllerTest::CreateFormManagerWithBlacklistedMatches( EXPECT_CALL(*form_manager, IsBlacklisted())
const FormData& observed_form, .Times(AtMost(1))
bool is_blacklisted, .WillOnce(Return(is_blacklisted));
scoped_refptr<password_manager::PasswordFormMetricsRecorder> EXPECT_CALL(*form_manager, GetInteractionsStats())
metrics_recorder) { .Times(AtMost(1))
auto form_manager = std::make_unique<PasswordFormManager>( .WillOnce(
&client_, driver_.AsWeakPtr(), observed_form, &fetcher_, Return(base::span<const password_manager::InteractionsStats>()));
std::make_unique<password_manager::StubFormSaver>(), metrics_recorder); EXPECT_CALL(*form_manager, GetPendingCredentials())
fetcher_.SetBlacklisted(is_blacklisted); .WillRepeatedly(ReturnRef(submitted_form_));
fetcher_.NotifyFetchCompleted(); EXPECT_CALL(*form_manager, GetMetricsRecorder())
.WillRepeatedly(Return(nullptr));
return form_manager; return form_manager;
} }
std::unique_ptr<PasswordFormManager>
ManagePasswordsUIControllerTest::CreateFormManager() {
return CreateFormManagerWithMetricsRecorder(nullptr);
}
std::unique_ptr<PasswordFormManager>
ManagePasswordsUIControllerTest::CreateFormManagerWithMetricsRecorder(
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder) {
return CreateFormManagerWithBestMatches(observed_form(), {},
metrics_recorder);
}
void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill( void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill(
password_manager::ui::State state) { password_manager::ui::State state) {
DCHECK(state == password_manager::ui::PENDING_PASSWORD_STATE || DCHECK(state == password_manager::ui::PENDING_PASSWORD_STATE ||
...@@ -350,8 +270,9 @@ void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill( ...@@ -350,8 +270,9 @@ void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill(
state == password_manager::ui::CONFIRMATION_STATE); state == password_manager::ui::CONFIRMATION_STATE);
// Set the bubble state to |state|. // Set the bubble state to |state|.
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); std::unique_ptr<MockPasswordFormManagerForUI> test_form_manager =
CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
if (state == password_manager::ui::PENDING_PASSWORD_STATE) if (state == password_manager::ui::PENDING_PASSWORD_STATE)
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
...@@ -362,8 +283,7 @@ void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill( ...@@ -362,8 +283,7 @@ void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill(
ASSERT_EQ(state, controller()->GetState()); ASSERT_EQ(state, controller()->GetState());
// Autofill happens. // Autofill happens.
std::vector<const PasswordForm*> forms; std::vector<const PasswordForm*> forms = {&test_local_form()};
forms.push_back(&test_local_form());
controller()->OnPasswordAutofilled(forms, forms.front()->origin, nullptr); controller()->OnPasswordAutofilled(forms, forms.front()->origin, nullptr);
// State shouldn't changed. // State shouldn't changed.
...@@ -377,26 +297,24 @@ TEST_F(ManagePasswordsUIControllerTest, DefaultState) { ...@@ -377,26 +297,24 @@ TEST_F(ManagePasswordsUIControllerTest, DefaultState) {
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) { TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) {
const PasswordForm* test_form_ptr = &test_local_form(); std::vector<const PasswordForm*> forms = {&test_local_form()};
base::string16 kTestUsername = test_form_ptr->username_value;
std::vector<const PasswordForm*> forms;
forms.push_back(test_form_ptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordAutofilled(forms, forms.front()->origin, nullptr); controller()->OnPasswordAutofilled(forms, forms.front()->origin, nullptr);
EXPECT_EQ(test_form_ptr->origin, controller()->GetOrigin()); EXPECT_EQ(test_local_form().origin, controller()->GetOrigin());
ASSERT_EQ(1u, controller()->GetCurrentForms().size()); ASSERT_EQ(1u, controller()->GetCurrentForms().size());
EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value); EXPECT_EQ(test_local_form().username_value,
controller()->GetCurrentForms()[0]->username_value);
// Controller should store a separate copy of the form as it doesn't own it. // Controller should store a separate copy of the form as it doesn't own it.
EXPECT_NE(test_form_ptr, controller()->GetCurrentForms()[0].get()); EXPECT_NE(&test_local_form(), controller()->GetCurrentForms()[0].get());
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) { TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_TRUE(controller()->opened_automatic_bubble()); EXPECT_TRUE(controller()->opened_automatic_bubble());
...@@ -406,9 +324,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) { ...@@ -406,9 +324,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) {
} }
TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) { TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) {
std::unique_ptr<PasswordFormManager> test_form_manager = std::vector<const PasswordForm*> best_matches;
CreateFormManagerWithBlacklistedMatches(observed_form(), auto test_form_manager =
/*is_blacklisted=*/true, nullptr); CreateFormManagerWithBestMatches(&best_matches, /*is_blacklisted=*/true);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_FALSE(controller()->opened_automatic_bubble()); EXPECT_FALSE(controller()->opened_automatic_bubble());
...@@ -417,13 +335,14 @@ TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) { ...@@ -417,13 +335,14 @@ TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) {
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) { TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
std::vector<password_manager::InteractionsStats> stats(1); std::vector<password_manager::InteractionsStats> stats(1);
stats[0].origin_domain = test_local_form().origin.GetOrigin(); stats[0].origin_domain = submitted_form().origin.GetOrigin();
stats[0].username_value = test_local_form().username_value; stats[0].username_value = submitted_form().username_value;
stats[0].dismissal_count = kGreatDissmisalCount; stats[0].dismissal_count = kGreatDissmisalCount;
fetcher().set_stats(stats); EXPECT_CALL(*test_form_manager, GetInteractionsStats)
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); .WillRepeatedly(Return(stats));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_FALSE(controller()->opened_automatic_bubble()); EXPECT_FALSE(controller()->opened_automatic_bubble());
...@@ -431,24 +350,23 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) { ...@@ -431,24 +350,23 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) {
EXPECT_EQ(stats[0], *controller()->GetCurrentInteractionStats()); EXPECT_EQ(stats[0], *controller()->GetCurrentInteractionStats());
ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE); ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE);
variations::testing::ClearAllVariationParams();
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleNotSuppressed) { TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleNotSuppressed) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
std::vector<password_manager::InteractionsStats> stats(1); std::vector<password_manager::InteractionsStats> stats(1);
stats[0].origin_domain = test_local_form().origin.GetOrigin(); stats[0].origin_domain = submitted_form().origin.GetOrigin();
stats[0].username_value = ASCIIToUTF16("not my username"); stats[0].username_value = ASCIIToUTF16("not my username");
stats[0].dismissal_count = kGreatDissmisalCount; stats[0].dismissal_count = kGreatDissmisalCount;
fetcher().set_stats(stats); EXPECT_CALL(*test_form_manager, GetInteractionsStats)
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); .WillRepeatedly(Return(stats));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_TRUE(controller()->opened_automatic_bubble()); EXPECT_TRUE(controller()->opened_automatic_bubble());
EXPECT_FALSE(controller()->GetCurrentInteractionStats()); EXPECT_FALSE(controller()->GetCurrentInteractionStats());
ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE); ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE);
variations::testing::ClearAllVariationParams();
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) { TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) {
...@@ -461,8 +379,8 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) { ...@@ -461,8 +379,8 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) {
ManagePasswordsUIController::FromWebContents(web_content.get()); ManagePasswordsUIController::FromWebContents(web_content.get());
controller->set_client(&client()); controller->set_client(&client());
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
// The bubble is ready to open but the tab is inactive. Therefore, we don't // The bubble is ready to open but the tab is inactive. Therefore, we don't
// call UpdateIconAndBubbleState here. // call UpdateIconAndBubbleState here.
controller->OnPasswordSubmitted(std::move(test_form_manager)); controller->OnPasswordSubmitted(std::move(test_form_manager));
...@@ -476,14 +394,15 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) { ...@@ -476,14 +394,15 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) {
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordSaved) { TEST_F(ManagePasswordsUIControllerTest, PasswordSaved) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, Save());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
controller()->SavePassword(test_local_form().username_value, controller()->SavePassword(submitted_form().username_value,
test_local_form().password_value); submitted_form().password_value);
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
"PasswordManager.PasswordSavedWithManualFallback", false, 1); "PasswordManager.PasswordSavedWithManualFallback", false, 1);
...@@ -514,17 +433,25 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSavedUKMRecording) { ...@@ -514,17 +433,25 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSavedUKMRecording) {
true /*is_main_frame_secure*/, source_id); true /*is_main_frame_secure*/, source_id);
// Exercise controller. // Exercise controller.
std::unique_ptr<PasswordFormManager> test_form_manager( std::vector<const PasswordForm*> best_matches;
CreateFormManagerWithMetricsRecorder(recorder)); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); EXPECT_CALL(*test_form_manager, GetMetricsRecorder)
.WillRepeatedly(Return(recorder.get()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager,
OnUpdateUsernameFromPrompt(ASCIIToUTF16("other_username")))
.Times(test.edit_username);
EXPECT_CALL(*test_form_manager,
OnUpdatePasswordFromPrompt(ASCIIToUTF16("other_pwd")))
.Times(test.change_password);
EXPECT_CALL(*test_form_manager, Save());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
controller()->SavePassword( controller()->SavePassword(
test.edit_username ? base::UTF8ToUTF16("other_username") test.edit_username ? base::UTF8ToUTF16("other_username")
: test_local_form().username_value, : submitted_form().username_value,
test.change_password ? base::UTF8ToUTF16("other_pwd") test.change_password ? base::UTF8ToUTF16("other_pwd")
: test_local_form().password_value); : submitted_form().password_value);
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
// Fake navigation so that the old form manager gets destroyed and // Fake navigation so that the old form manager gets destroyed and
...@@ -573,9 +500,11 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSavedUKMRecording) { ...@@ -573,9 +500,11 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSavedUKMRecording) {
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) { TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, OnNeverClicked());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
...@@ -585,11 +514,10 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) { ...@@ -585,11 +514,10 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) {
TEST_F(ManagePasswordsUIControllerTest, TEST_F(ManagePasswordsUIControllerTest,
PasswordBlacklistedWithExistingCredentials) { PasswordBlacklistedWithExistingCredentials) {
std::unique_ptr<PasswordFormManager> test_form_manager( std::vector<const PasswordForm*> best_matches = {&test_local_form()};
CreateFormManagerWithBestMatches(observed_form(), {&test_local_form()}, auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
nullptr));
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, OnNeverClicked());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
...@@ -598,7 +526,8 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -598,7 +526,8 @@ TEST_F(ManagePasswordsUIControllerTest,
} }
TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) { TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches = {&test_local_form()};
auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE); ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE);
...@@ -613,12 +542,13 @@ TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) { ...@@ -613,12 +542,13 @@ TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) {
} }
TEST_F(ManagePasswordsUIControllerTest, NormalNavigationsClosedBubble) { TEST_F(ManagePasswordsUIControllerTest, NormalNavigationsClosedBubble) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, Save());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
controller()->SavePassword(test_local_form().username_value, controller()->SavePassword(submitted_form().username_value,
test_local_form().password_value); submitted_form().password_value);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnBubbleHidden(); controller()->OnBubbleHidden();
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
...@@ -637,8 +567,8 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) { ...@@ -637,8 +567,8 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) {
content::WebContentsTester::For(web_contents()) content::WebContentsTester::For(web_contents())
->NavigateAndCommit(GURL("chrome://sign-in")); ->NavigateAndCommit(GURL("chrome://sign-in"));
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_EQ(GURL::EmptyGURL(), controller()->GetOrigin()); EXPECT_EQ(GURL::EmptyGURL(), controller()->GetOrigin());
...@@ -665,7 +595,8 @@ TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) { ...@@ -665,7 +595,8 @@ TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) {
} }
TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) { TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutomaticPasswordSave(std::move(test_form_manager)); controller()->OnAutomaticPasswordSave(std::move(test_form_manager));
EXPECT_EQ(password_manager::ui::CONFIRMATION_STATE, controller()->GetState()); EXPECT_EQ(password_manager::ui::CONFIRMATION_STATE, controller()->GetState());
...@@ -686,10 +617,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) { ...@@ -686,10 +617,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
EXPECT_CALL(dialog_prompt(), ShowAccountChooser()); EXPECT_CALL(dialog_prompt(), ShowAccountChooser());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true)); EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true));
EXPECT_TRUE(controller()->OnChooseCredentials( base::MockCallback<ManagePasswordsState::CredentialsCallback> choose_callback;
std::move(local_credentials), origin, EXPECT_TRUE(controller()->OnChooseCredentials(std::move(local_credentials),
base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, origin, choose_callback.Get()));
base::Unretained(this))));
EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
controller()->GetState()); controller()->GetState());
EXPECT_EQ(origin, controller()->GetOrigin()); EXPECT_EQ(origin, controller()->GetOrigin());
...@@ -700,7 +630,7 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) { ...@@ -700,7 +630,7 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
ExpectIconStateIs(password_manager::ui::INACTIVE_STATE); ExpectIconStateIs(password_manager::ui::INACTIVE_STATE);
EXPECT_CALL(dialog_prompt(), ControllerGone()); EXPECT_CALL(dialog_prompt(), ControllerGone());
EXPECT_CALL(*this, CredentialCallback(Pointee(test_local_form()))); EXPECT_CALL(choose_callback, Run(Pointee(test_local_form())));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
dialog_controller->OnChooseCredentials( dialog_controller->OnChooseCredentials(
*dialog_controller->GetLocalForms()[0], *dialog_controller->GetLocalForms()[0],
...@@ -719,10 +649,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) { ...@@ -719,10 +649,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
EXPECT_CALL(dialog_prompt(), ShowAccountChooser()); EXPECT_CALL(dialog_prompt(), ShowAccountChooser());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true)); EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true));
EXPECT_TRUE(controller()->OnChooseCredentials( base::MockCallback<ManagePasswordsState::CredentialsCallback> choose_callback;
std::move(local_credentials), origin, EXPECT_TRUE(controller()->OnChooseCredentials(std::move(local_credentials),
base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, origin, choose_callback.Get()));
base::Unretained(this))));
EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
controller()->GetState()); controller()->GetState());
EXPECT_EQ(origin, controller()->GetOrigin()); EXPECT_EQ(origin, controller()->GetOrigin());
...@@ -733,7 +662,7 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) { ...@@ -733,7 +662,7 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
ExpectIconStateIs(password_manager::ui::INACTIVE_STATE); ExpectIconStateIs(password_manager::ui::INACTIVE_STATE);
EXPECT_CALL(dialog_prompt(), ControllerGone()); EXPECT_CALL(dialog_prompt(), ControllerGone());
EXPECT_CALL(*this, CredentialCallback(Pointee(test_federated_form()))); EXPECT_CALL(choose_callback, Run(Pointee(test_federated_form())));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
dialog_controller->OnChooseCredentials( dialog_controller->OnChooseCredentials(
*dialog_controller->GetLocalForms()[0], *dialog_controller->GetLocalForms()[0],
...@@ -752,16 +681,15 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) { ...@@ -752,16 +681,15 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
EXPECT_CALL(dialog_prompt(), ShowAccountChooser()); EXPECT_CALL(dialog_prompt(), ShowAccountChooser());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true)); EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true));
EXPECT_TRUE(controller()->OnChooseCredentials( base::MockCallback<ManagePasswordsState::CredentialsCallback> choose_callback;
std::move(local_credentials), origin, EXPECT_TRUE(controller()->OnChooseCredentials(std::move(local_credentials),
base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, origin, choose_callback.Get()));
base::Unretained(this))));
EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
controller()->GetState()); controller()->GetState());
EXPECT_EQ(origin, controller()->GetOrigin()); EXPECT_EQ(origin, controller()->GetOrigin());
EXPECT_CALL(dialog_prompt(), ControllerGone()).Times(0); EXPECT_CALL(dialog_prompt(), ControllerGone()).Times(0);
EXPECT_CALL(*this, CredentialCallback(nullptr)); EXPECT_CALL(choose_callback, Run(nullptr));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
dialog_controller->OnCloseDialog(); dialog_controller->OnCloseDialog();
EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->GetState()); EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->GetState());
...@@ -775,10 +703,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPrefetch) { ...@@ -775,10 +703,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPrefetch) {
// Simulate requesting a credential during prefetch. The tab has no associated // Simulate requesting a credential during prefetch. The tab has no associated
// browser. Nothing should happen. // browser. Nothing should happen.
EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(false)); EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(false));
base::MockCallback<ManagePasswordsState::CredentialsCallback> choose_callback;
EXPECT_FALSE(controller()->OnChooseCredentials( EXPECT_FALSE(controller()->OnChooseCredentials(
std::move(local_credentials), origin, std::move(local_credentials), origin, choose_callback.Get()));
base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
base::Unretained(this))));
EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState());
} }
...@@ -794,10 +721,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) { ...@@ -794,10 +721,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) {
EXPECT_CALL(dialog_prompt(), ShowAccountChooser()); EXPECT_CALL(dialog_prompt(), ShowAccountChooser());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true)); EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true));
EXPECT_TRUE(controller()->OnChooseCredentials( base::MockCallback<ManagePasswordsState::CredentialsCallback> choose_callback;
std::move(local_credentials), origin, EXPECT_TRUE(controller()->OnChooseCredentials(std::move(local_credentials),
base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, origin, choose_callback.Get()));
base::Unretained(this))));
EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
controller()->GetState()); controller()->GetState());
EXPECT_EQ(origin, controller()->GetOrigin()); EXPECT_EQ(origin, controller()->GetOrigin());
...@@ -807,7 +733,7 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) { ...@@ -807,7 +733,7 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) {
ExpectIconStateIs(password_manager::ui::INACTIVE_STATE); ExpectIconStateIs(password_manager::ui::INACTIVE_STATE);
EXPECT_CALL(dialog_prompt(), ControllerGone()); EXPECT_CALL(dialog_prompt(), ControllerGone());
EXPECT_CALL(*this, CredentialCallback(Pointee(test_local_form()))); EXPECT_CALL(choose_callback, Run(Pointee(test_local_form())));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
dialog_controller->OnChooseCredentials( dialog_controller->OnChooseCredentials(
*dialog_controller->GetLocalForms()[0], *dialog_controller->GetLocalForms()[0],
...@@ -909,7 +835,8 @@ TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) { ...@@ -909,7 +835,8 @@ TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) {
} }
TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) { TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager)); controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager));
ExpectIconAndControllerStateIs( ExpectIconAndControllerStateIs(
...@@ -917,16 +844,17 @@ TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) { ...@@ -917,16 +844,17 @@ TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) {
} }
TEST_F(ManagePasswordsUIControllerTest, PasswordUpdated) { TEST_F(ManagePasswordsUIControllerTest, PasswordUpdated) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> best_matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&best_matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, Save());
controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager)); controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager));
ExpectIconAndControllerStateIs( ExpectIconAndControllerStateIs(
password_manager::ui::PENDING_PASSWORD_UPDATE_STATE); password_manager::ui::PENDING_PASSWORD_UPDATE_STATE);
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
controller()->SavePassword(test_local_form().username_value, controller()->SavePassword(submitted_form().username_value,
test_local_form().password_value); submitted_form().password_value);
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
"PasswordManager.PasswordSavedWithManualFallback", false, 1); "PasswordManager.PasswordSavedWithManualFallback", false, 1);
...@@ -982,10 +910,12 @@ TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_UseFallback) { ...@@ -982,10 +910,12 @@ TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_UseFallback) {
auto recorder = auto recorder =
base::MakeRefCounted<password_manager::PasswordFormMetricsRecorder>( base::MakeRefCounted<password_manager::PasswordFormMetricsRecorder>(
true /*is_main_frame_secure*/, source_id); true /*is_main_frame_secure*/, source_id);
std::unique_ptr<PasswordFormManager> test_form_manager( std::vector<const PasswordForm*> matches;
CreateFormManagerWithMetricsRecorder(recorder)); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
EXPECT_CALL(*test_form_manager, GetMetricsRecorder)
.WillRepeatedly(Return(recorder.get()));
EXPECT_CALL(*test_form_manager, Save());
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(3); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(3);
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
std::move(test_form_manager), false /* has_generated_password */, std::move(test_form_manager), false /* has_generated_password */,
...@@ -996,8 +926,8 @@ TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_UseFallback) { ...@@ -996,8 +926,8 @@ TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_UseFallback) {
EXPECT_FALSE(controller()->opened_automatic_bubble()); EXPECT_FALSE(controller()->opened_automatic_bubble());
// A user clicks on omnibox icon, opens the bubble and press Save/Update. // A user clicks on omnibox icon, opens the bubble and press Save/Update.
controller()->SavePassword(test_local_form().username_value, controller()->SavePassword(submitted_form().username_value,
test_local_form().password_value); submitted_form().password_value);
// Fake navigation so that the old form manager gets destroyed and // Fake navigation so that the old form manager gets destroyed and
// reports its metrics. Need to close the bubble, otherwise the bubble // reports its metrics. Need to close the bubble, otherwise the bubble
...@@ -1033,12 +963,8 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1033,12 +963,8 @@ TEST_F(ManagePasswordsUIControllerTest,
for (bool is_update : {false, true}) { for (bool is_update : {false, true}) {
SCOPED_TRACE(testing::Message("is_update = ") << is_update); SCOPED_TRACE(testing::Message("is_update = ") << is_update);
// Create password form manager with stored passwords. // Create password form manager with stored passwords.
std::unique_ptr<PasswordFormManager> test_form_manager( std::vector<const PasswordForm*> matches = {&test_local_form()};
CreateFormManagerWithBestMatches(observed_form(), {&test_local_form()}, auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
nullptr));
// Simulate user typing a password.
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
...@@ -1064,11 +990,8 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1064,11 +990,8 @@ TEST_F(ManagePasswordsUIControllerTest,
TEST_F(ManagePasswordsUIControllerTest, TEST_F(ManagePasswordsUIControllerTest,
ManualFallbackForSaving_HideFallback_WithoutPreexistingPasswords) { ManualFallbackForSaving_HideFallback_WithoutPreexistingPasswords) {
// Create password form manager without stored passwords. // Create password form manager without stored passwords.
std::unique_ptr<PasswordFormManager> test_form_manager( std::vector<const PasswordForm*> matches;
CreateFormManagerWithBestMatches(observed_form(), {}, nullptr)); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
// Simulate user typing a password.
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
...@@ -1092,8 +1015,8 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1092,8 +1015,8 @@ TEST_F(ManagePasswordsUIControllerTest,
<< enforce_navigation); << enforce_navigation);
ManagePasswordsUIController::set_save_fallback_timeout_in_seconds(0); ManagePasswordsUIController::set_save_fallback_timeout_in_seconds(0);
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
...@@ -1129,10 +1052,11 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1129,10 +1052,11 @@ TEST_F(ManagePasswordsUIControllerTest,
<< user_saved_password); << user_saved_password);
ManagePasswordsUIController::set_save_fallback_timeout_in_seconds(0); ManagePasswordsUIController::set_save_fallback_timeout_in_seconds(0);
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, Save()).Times(user_saved_password);
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
std::move(test_form_manager), false /* has_generated_password */, std::move(test_form_manager), false /* has_generated_password */,
false /* is_update */); false /* is_update */);
...@@ -1150,8 +1074,8 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1150,8 +1074,8 @@ TEST_F(ManagePasswordsUIControllerTest,
password_manager::ui::PENDING_PASSWORD_STATE); password_manager::ui::PENDING_PASSWORD_STATE);
if (user_saved_password) { if (user_saved_password) {
controller()->SavePassword(test_local_form().username_value, controller()->SavePassword(submitted_form().username_value,
test_local_form().password_value); submitted_form().password_value);
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
} else { } else {
// A user closed the bubble. The fallback should be hidden after // A user closed the bubble. The fallback should be hidden after
...@@ -1169,8 +1093,13 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1169,8 +1093,13 @@ TEST_F(ManagePasswordsUIControllerTest,
TEST_F(ManagePasswordsUIControllerTest, TEST_F(ManagePasswordsUIControllerTest,
ManualFallbackForSavingFollowedByAutomaticBubble) { ManualFallbackForSavingFollowedByAutomaticBubble) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
PasswordForm pending = test_local_form();
pending.username_value = ASCIIToUTF16("manual_username");
pending.password_value = ASCIIToUTF16("manual_pass1234");
EXPECT_CALL(*test_form_manager, GetPendingCredentials())
.WillRepeatedly(ReturnRef(pending));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
...@@ -1183,19 +1112,15 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1183,19 +1112,15 @@ TEST_F(ManagePasswordsUIControllerTest,
controller()->OnBubbleShown(); controller()->OnBubbleShown();
// Automatic form submission detected. // Automatic form submission detected.
test_form_manager = CreateFormManager(); test_form_manager = CreateFormManagerWithBestMatches(&matches);
FormData form = submitted_form();
form.fields[0].value = ASCIIToUTF16("some_other_username");
form.fields[1].value = ASCIIToUTF16("password123");
test_form_manager->ProvisionallySave(form, &driver(), nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(0); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(0);
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
// It should have no effect as the bubble was already open. // It should have no effect as the bubble was already open.
ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE); ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE);
EXPECT_EQ(test_local_form().username_value, EXPECT_EQ(ASCIIToUTF16("manual_username"),
controller()->GetPendingPassword().username_value); controller()->GetPendingPassword().username_value);
EXPECT_EQ(test_local_form().password_value, EXPECT_EQ(ASCIIToUTF16("manual_pass1234"),
controller()->GetPendingPassword().password_value); controller()->GetPendingPassword().password_value);
} }
...@@ -1204,10 +1129,8 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1204,10 +1129,8 @@ TEST_F(ManagePasswordsUIControllerTest,
for (bool user_closed_bubble : {false, true}) { for (bool user_closed_bubble : {false, true}) {
SCOPED_TRACE(testing::Message("user_closed_bubble = ") SCOPED_TRACE(testing::Message("user_closed_bubble = ")
<< user_closed_bubble); << user_closed_bubble);
std::unique_ptr<PasswordFormManager> test_form_manager( std::vector<const PasswordForm*> matches = {&test_local_form()};
CreateFormManagerWithBestMatches(observed_form(), {&test_local_form()}, auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
nullptr));
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving( controller()->OnShowManualFallbackForSaving(
std::move(test_form_manager), true /* has_generated_password */, false); std::move(test_form_manager), true /* has_generated_password */, false);
...@@ -1228,13 +1151,14 @@ TEST_F(ManagePasswordsUIControllerTest, ...@@ -1228,13 +1151,14 @@ TEST_F(ManagePasswordsUIControllerTest,
} }
TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) { TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
EXPECT_CALL(*test_form_manager, Save());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
controller()->SavePassword(test_local_form().username_value, controller()->SavePassword(submitted_form().username_value,
test_local_form().password_value); submitted_form().password_value);
// The state is 'Managed' but the bubble may still be on the screen showing // The state is 'Managed' but the bubble may still be on the screen showing
// the sign-in promo. // the sign-in promo.
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
...@@ -1250,8 +1174,8 @@ TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) { ...@@ -1250,8 +1174,8 @@ TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) {
} }
TEST_F(ManagePasswordsUIControllerTest, AuthenticateUserToRevealPasswords) { TEST_F(ManagePasswordsUIControllerTest, AuthenticateUserToRevealPasswords) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> matches;
test_form_manager->ProvisionallySave(submitted_form(), &driver(), nullptr); auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager)); controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
...@@ -1280,7 +1204,8 @@ TEST_F(ManagePasswordsUIControllerTest, AuthenticateUserToRevealPasswords) { ...@@ -1280,7 +1204,8 @@ TEST_F(ManagePasswordsUIControllerTest, AuthenticateUserToRevealPasswords) {
} }
TEST_F(ManagePasswordsUIControllerTest, UpdateBubbleAfterLeakCheck) { TEST_F(ManagePasswordsUIControllerTest, UpdateBubbleAfterLeakCheck) {
std::unique_ptr<PasswordFormManager> test_form_manager(CreateFormManager()); std::vector<const PasswordForm*> matches;
auto test_form_manager = CreateFormManagerWithBestMatches(&matches);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager)); controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager));
EXPECT_TRUE(controller()->opened_automatic_bubble()); EXPECT_TRUE(controller()->opened_automatic_bubble());
......
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