Commit e3f3d26c authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Use NewPasswordFormManager in manage_passwords_ui_controller_test.cc.

This CL replaces PasswordFormManager->NewPasswordFormManager. The main
difference is that a constructor of form managers are different:
PasswordFormManager takes PasswordForm
NewPasswordFormManager takes FormData (which is converted to PasswordForm
inside NewPasswordFormManager during parsing).

Bug: 949519
Change-Id: I0db3bf7bffb8d0bf31bd2f2357b18a7466552f9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774287Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691605}
parent 0e4ece8a
......@@ -23,11 +23,11 @@
#include "chrome/browser/ui/passwords/passwords_model_delegate.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/password_manager/core/browser/fake_form_fetcher.h"
#include "components/password_manager/core/browser/new_password_form_manager.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_manager.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"
......@@ -45,6 +45,12 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using autofill::FormData;
using autofill::FormFieldData;
using autofill::PasswordForm;
using base::ASCIIToUTF16;
using password_manager::NewPasswordFormManager;
using ::testing::_;
using ::testing::Contains;
using ::testing::DoAll;
using ::testing::ElementsAre;
......@@ -53,7 +59,6 @@ using ::testing::Not;
using ::testing::Pointee;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::_;
namespace {
......@@ -131,7 +136,7 @@ TestManagePasswordsUIController::TestManagePasswordsUIController(
set_client(client);
}
TestManagePasswordsUIController::~TestManagePasswordsUIController() {}
TestManagePasswordsUIController::~TestManagePasswordsUIController() = default;
void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
opened_bubble_ = ShouldBubblePopUp();
......@@ -148,7 +153,7 @@ void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
}
void TestManagePasswordsUIController::NeverSavePasswordInternal() {
autofill::PasswordForm blacklisted;
PasswordForm blacklisted;
blacklisted.origin = this->GetOrigin();
blacklisted.signon_realm = blacklisted.origin.spec();
blacklisted.blacklisted_by_user = true;
......@@ -173,8 +178,7 @@ void CreateSmartBubbleFieldTrial() {
class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness {
public:
ManagePasswordsUIControllerTest()
: password_manager_(&client_), field_trial_list_(nullptr) {
ManagePasswordsUIControllerTest() : field_trial_list_(nullptr) {
fetcher_.Fetch();
}
......@@ -182,9 +186,12 @@ class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness {
password_manager::StubPasswordManagerClient& client() { return client_; }
password_manager::FakeFormFetcher& fetcher() { return fetcher_; }
autofill::PasswordForm& test_local_form() { return test_local_form_; }
autofill::PasswordForm& test_federated_form() { return test_federated_form_; }
PasswordForm& test_local_form() { return test_local_form_; }
PasswordForm& test_federated_form() { return test_federated_form_; }
FormData& submitted_form() { return submitted_form_; }
FormData& observed_form() { return observed_form_; }
DialogPromptMock& dialog_prompt() { return dialog_prompt_; }
password_manager::PasswordManagerDriver& driver() { return driver_; }
TestManagePasswordsUIController* controller() {
return static_cast<TestManagePasswordsUIController*>(
......@@ -194,40 +201,39 @@ class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness {
void ExpectIconStateIs(password_manager::ui::State state);
void ExpectIconAndControllerStateIs(password_manager::ui::State state);
std::unique_ptr<password_manager::PasswordFormManager>
CreateFormManagerWithBestMatches(
const autofill::PasswordForm& observed_form,
const std::vector<const autofill::PasswordForm*>& best_matches,
std::unique_ptr<NewPasswordFormManager> CreateFormManagerWithBestMatches(
const FormData& observed_form,
const std::vector<const PasswordForm*>& best_matches,
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder);
std::unique_ptr<password_manager::PasswordFormManager>
std::unique_ptr<NewPasswordFormManager>
CreateFormManagerWithBlacklistedMatches(
const autofill::PasswordForm& observed_form,
const std::vector<const autofill::PasswordForm*>& blacklisted_matches,
const FormData& observed_form,
const std::vector<const PasswordForm*>& blacklisted_matches,
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder);
std::unique_ptr<password_manager::PasswordFormManager> CreateFormManager();
std::unique_ptr<NewPasswordFormManager> CreateFormManager();
std::unique_ptr<password_manager::PasswordFormManager>
CreateFormManagerWithMetricsRecorder(
std::unique_ptr<NewPasswordFormManager> CreateFormManagerWithMetricsRecorder(
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder);
// Tests that the state is not changed when the password is autofilled.
void TestNotChangingStateOnAutofill(password_manager::ui::State state);
MOCK_METHOD1(CredentialCallback, void(const autofill::PasswordForm*));
MOCK_METHOD1(CredentialCallback, void(const PasswordForm*));
private:
password_manager::StubPasswordManagerClient client_;
password_manager::StubPasswordManagerDriver driver_;
password_manager::PasswordManager password_manager_;
password_manager::FakeFormFetcher fetcher_;
autofill::PasswordForm test_local_form_;
autofill::PasswordForm test_federated_form_;
PasswordForm test_local_form_;
PasswordForm test_federated_form_;
FormData submitted_form_;
FormData observed_form_;
base::FieldTrialList field_trial_list_;
DialogPromptMock dialog_prompt_;
};
......@@ -241,16 +247,35 @@ void ManagePasswordsUIControllerTest::SetUp() {
new TestManagePasswordsUIController(web_contents(), &client_);
test_local_form_.origin = GURL("http://example.com/login");
test_local_form_.username_value = base::ASCIIToUTF16("username");
test_local_form_.username_element = base::ASCIIToUTF16("username_element");
test_local_form_.password_value = base::ASCIIToUTF16("12345");
test_local_form_.password_element = base::ASCIIToUTF16("password_element");
test_local_form_.username_value = ASCIIToUTF16("username");
test_local_form_.username_element = ASCIIToUTF16("username_element");
test_local_form_.password_value = ASCIIToUTF16("12345");
test_local_form_.password_element = ASCIIToUTF16("password_element");
test_federated_form_.origin = GURL("http://example.com/login");
test_federated_form_.username_value = base::ASCIIToUTF16("username");
test_federated_form_.username_value = ASCIIToUTF16("username");
test_federated_form_.federation_origin =
url::Origin::Create(GURL("https://federation.test/"));
// Create a simple sign-in form.
observed_form_.url = test_local_form_.origin;
FormFieldData field;
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.
NewPasswordFormManager::set_wait_for_server_predictions_for_filling(false);
// We need to be on a "webby" URL for most tests.
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
content::WebContentsTester::For(web_contents())
......@@ -270,48 +295,44 @@ void ManagePasswordsUIControllerTest::ExpectIconAndControllerStateIs(
EXPECT_EQ(state, controller()->GetState());
}
std::unique_ptr<password_manager::PasswordFormManager>
std::unique_ptr<NewPasswordFormManager>
ManagePasswordsUIControllerTest::CreateFormManagerWithBestMatches(
const autofill::PasswordForm& observed_form,
const std::vector<const autofill::PasswordForm*>& best_matches,
const FormData& observed_form,
const std::vector<const PasswordForm*>& best_matches,
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder) {
auto test_form_manager =
std::make_unique<password_manager::PasswordFormManager>(
&password_manager_, &client_, driver_.AsWeakPtr(), observed_form,
std::make_unique<password_manager::StubFormSaver>(), &fetcher_);
test_form_manager->Init(metrics_recorder);
auto form_manager = std::make_unique<NewPasswordFormManager>(
&client_, driver_.AsWeakPtr(), observed_form, &fetcher_,
std::make_unique<password_manager::StubFormSaver>(), metrics_recorder);
fetcher_.SetNonFederated(best_matches);
fetcher_.NotifyFetchCompleted();
return test_form_manager;
return form_manager;
}
std::unique_ptr<password_manager::PasswordFormManager>
std::unique_ptr<NewPasswordFormManager>
ManagePasswordsUIControllerTest::CreateFormManagerWithBlacklistedMatches(
const autofill::PasswordForm& observed_form,
const std::vector<const autofill::PasswordForm*>& blacklisted_matches,
const FormData& observed_form,
const std::vector<const PasswordForm*>& blacklisted_matches,
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder) {
auto test_form_manager =
std::make_unique<password_manager::PasswordFormManager>(
&password_manager_, &client_, driver_.AsWeakPtr(), observed_form,
std::make_unique<password_manager::StubFormSaver>(), &fetcher_);
test_form_manager->Init(metrics_recorder);
auto form_manager = std::make_unique<NewPasswordFormManager>(
&client_, driver_.AsWeakPtr(), observed_form, &fetcher_,
std::make_unique<password_manager::StubFormSaver>(), metrics_recorder);
fetcher_.SetBlacklisted(blacklisted_matches);
fetcher_.NotifyFetchCompleted();
return test_form_manager;
return form_manager;
}
std::unique_ptr<password_manager::PasswordFormManager>
std::unique_ptr<NewPasswordFormManager>
ManagePasswordsUIControllerTest::CreateFormManager() {
return CreateFormManagerWithMetricsRecorder(nullptr);
}
std::unique_ptr<password_manager::PasswordFormManager>
std::unique_ptr<NewPasswordFormManager>
ManagePasswordsUIControllerTest::CreateFormManagerWithMetricsRecorder(
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder) {
return CreateFormManagerWithBestMatches(test_local_form(), {},
return CreateFormManagerWithBestMatches(observed_form(), {},
metrics_recorder);
}
......@@ -322,9 +343,9 @@ void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill(
state == password_manager::ui::CONFIRMATION_STATE);
// Set the bubble state to |state|.
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
if (state == password_manager::ui::PENDING_PASSWORD_STATE)
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -335,7 +356,7 @@ void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill(
ASSERT_EQ(state, controller()->GetState());
// Autofill happens.
std::map<base::string16, const autofill::PasswordForm*> map;
std::map<base::string16, const PasswordForm*> map;
map.insert(
std::make_pair(test_local_form().username_value, &test_local_form()));
controller()->OnPasswordAutofilled(map, map.begin()->second->origin, nullptr);
......@@ -351,9 +372,9 @@ TEST_F(ManagePasswordsUIControllerTest, DefaultState) {
}
TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) {
const autofill::PasswordForm* test_form_ptr = &test_local_form();
const PasswordForm* test_form_ptr = &test_local_form();
base::string16 kTestUsername = test_form_ptr->username_value;
std::map<base::string16, const autofill::PasswordForm*> map;
std::map<base::string16, const PasswordForm*> map;
map.insert(std::make_pair(kTestUsername, test_form_ptr));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordAutofilled(map, map.begin()->second->origin, nullptr);
......@@ -369,9 +390,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) {
}
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_TRUE(controller()->opened_automatic_bubble());
......@@ -381,12 +402,12 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) {
}
TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) {
autofill::PasswordForm blacklisted;
PasswordForm blacklisted;
blacklisted.origin = test_local_form().origin;
blacklisted.signon_realm = blacklisted.origin.spec();
blacklisted.blacklisted_by_user = true;
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager =
CreateFormManagerWithBlacklistedMatches(test_local_form(), {&blacklisted},
std::unique_ptr<NewPasswordFormManager> test_form_manager =
CreateFormManagerWithBlacklistedMatches(observed_form(), {&blacklisted},
nullptr);
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -397,14 +418,14 @@ TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) {
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) {
CreateSmartBubbleFieldTrial();
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
std::vector<password_manager::InteractionsStats> stats(1);
stats[0].origin_domain = test_local_form().origin.GetOrigin();
stats[0].username_value = test_local_form().username_value;
stats[0].dismissal_count = kGreatDissmisalCount;
fetcher().set_stats(stats);
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_FALSE(controller()->opened_automatic_bubble());
......@@ -417,14 +438,14 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) {
TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleNotSuppressed) {
CreateSmartBubbleFieldTrial();
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
std::vector<password_manager::InteractionsStats> stats(1);
stats[0].origin_domain = test_local_form().origin.GetOrigin();
stats[0].username_value = base::ASCIIToUTF16("not my username");
stats[0].username_value = ASCIIToUTF16("not my username");
stats[0].dismissal_count = kGreatDissmisalCount;
fetcher().set_stats(stats);
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_TRUE(controller()->opened_automatic_bubble());
......@@ -444,9 +465,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) {
ManagePasswordsUIController::FromWebContents(web_content.get());
controller->set_client(&client());
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
// The bubble is ready to open but the tab is inactive. Therefore, we don't
// call UpdateIconAndBubbleState here.
controller->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -460,9 +481,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleCancelled) {
}
TEST_F(ManagePasswordsUIControllerTest, PasswordSaved) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -499,9 +520,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSavedUKMRecording) {
true /*is_main_frame_secure*/, source_id);
// Exercise controller.
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManagerWithMetricsRecorder(recorder));
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -558,9 +579,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSavedUKMRecording) {
}
TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -571,10 +592,10 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) {
TEST_F(ManagePasswordsUIControllerTest,
PasswordBlacklistedWithExistingCredentials) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(test_local_form(), {&test_local_form()},
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(observed_form(), {&test_local_form()},
nullptr));
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -584,7 +605,7 @@ TEST_F(ManagePasswordsUIControllerTest,
}
TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -600,9 +621,9 @@ TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) {
}
TEST_F(ManagePasswordsUIControllerTest, NormalNavigationsClosedBubble) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
controller()->SavePassword(test_local_form().username_value,
......@@ -625,9 +646,9 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) {
content::WebContentsTester::For(web_contents())
->NavigateAndCommit(GURL("chrome://sign-in"));
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_EQ(GURL::EmptyGURL(), controller()->GetOrigin());
......@@ -636,8 +657,8 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) {
}
TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) {
base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
std::map<base::string16, const autofill::PasswordForm*> map;
base::string16 kTestUsername = ASCIIToUTF16("test_username");
std::map<base::string16, const PasswordForm*> map;
map.insert(std::make_pair(kTestUsername, &test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordAutofilled(map, map.begin()->second->origin, nullptr);
......@@ -654,7 +675,7 @@ TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) {
}
TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutomaticPasswordSave(std::move(test_form_manager));
......@@ -666,8 +687,8 @@ TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) {
}
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
GURL origin("http://example.com");
CredentialManagerDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_))
......@@ -699,9 +720,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
}
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(
new autofill::PasswordForm(test_federated_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_federated_form()));
GURL origin("http://example.com");
CredentialManagerDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_))
......@@ -733,8 +753,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
}
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
GURL origin("http://example.com");
CredentialManagerDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_))
......@@ -759,8 +779,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
}
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPrefetch) {
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
GURL origin("http://example.com");
// Simulate requesting a credential during prefetch. The tab has no associated
......@@ -775,8 +795,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPrefetch) {
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) {
test_local_form().is_public_suffix_match = true;
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
GURL origin("http://example.com");
CredentialManagerDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_))
......@@ -808,8 +828,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) {
}
TEST_F(ManagePasswordsUIControllerTest, AutoSignin) {
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin);
......@@ -834,9 +854,9 @@ TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRun) {
TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRunAfterAutofill) {
// Setup the managed state first.
const autofill::PasswordForm* test_form_ptr = &test_local_form();
const PasswordForm* test_form_ptr = &test_local_form();
const base::string16 kTestUsername = test_form_ptr->username_value;
std::map<base::string16, const autofill::PasswordForm*> map;
std::map<base::string16, const PasswordForm*> map;
map.insert(std::make_pair(kTestUsername, test_form_ptr));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordAutofilled(map, test_form_ptr->origin, nullptr);
......@@ -873,13 +893,13 @@ TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRunAfterNavigation) {
}
TEST_F(ManagePasswordsUIControllerTest, AutofillDuringAutoSignin) {
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin);
ExpectIconAndControllerStateIs(password_manager::ui::AUTO_SIGNIN_STATE);
std::map<base::string16, const autofill::PasswordForm*> map;
std::map<base::string16, const PasswordForm*> map;
base::string16 kTestUsername = test_local_form().username_value;
map.insert(std::make_pair(kTestUsername, &test_local_form()));
controller()->OnPasswordAutofilled(map, map.begin()->second->origin, nullptr);
......@@ -888,9 +908,9 @@ TEST_F(ManagePasswordsUIControllerTest, AutofillDuringAutoSignin) {
}
TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) {
base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
std::map<base::string16, const autofill::PasswordForm*> map;
autofill::PasswordForm psl_matched_test_form(test_local_form());
base::string16 kTestUsername = ASCIIToUTF16("test_username");
std::map<base::string16, const PasswordForm*> map;
PasswordForm psl_matched_test_form(test_local_form());
psl_matched_test_form.is_public_suffix_match = true;
map.insert(std::make_pair(kTestUsername, &psl_matched_test_form));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
......@@ -900,7 +920,7 @@ TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) {
}
TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager));
......@@ -909,9 +929,9 @@ TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) {
}
TEST_F(ManagePasswordsUIControllerTest, PasswordUpdated) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnUpdatePasswordSubmitted(std::move(test_form_manager));
......@@ -942,8 +962,8 @@ TEST_F(ManagePasswordsUIControllerTest, ConfirmationStatePasswordAutofilled) {
TEST_F(ManagePasswordsUIControllerTest, OpenBubbleTwice) {
// Open the autosignin bubble.
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
std::vector<std::unique_ptr<PasswordForm>> local_credentials;
local_credentials.emplace_back(new PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin);
......@@ -953,7 +973,7 @@ TEST_F(ManagePasswordsUIControllerTest, OpenBubbleTwice) {
controller()->GetModelDelegateProxy();
// Open the bubble again.
local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
local_credentials.emplace_back(new PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin);
......@@ -975,10 +995,10 @@ TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_UseFallback) {
auto recorder =
base::MakeRefCounted<password_manager::PasswordFormMetricsRecorder>(
true /*is_main_frame_secure*/, source_id);
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManagerWithMetricsRecorder(recorder));
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(3);
controller()->OnShowManualFallbackForSaving(
std::move(test_form_manager), false /* has_generated_password */,
......@@ -1026,12 +1046,12 @@ TEST_F(ManagePasswordsUIControllerTest,
for (bool is_update : {false, true}) {
SCOPED_TRACE(testing::Message("is_update = ") << is_update);
// Create password form manager with stored passwords.
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(test_local_form(),
{&test_local_form()}, nullptr));
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(observed_form(), {&test_local_form()},
nullptr));
// Simulate user typing a password.
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving(
......@@ -1057,11 +1077,11 @@ TEST_F(ManagePasswordsUIControllerTest,
TEST_F(ManagePasswordsUIControllerTest,
ManualFallbackForSaving_HideFallback_WithoutPreexistingPasswords) {
// Create password form manager without stored passwords.
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(test_local_form(), {}, nullptr));
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(observed_form(), {}, nullptr));
// Simulate user typing a password.
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving(
......@@ -1085,9 +1105,9 @@ TEST_F(ManagePasswordsUIControllerTest,
<< enforce_navigation);
ManagePasswordsUIController::set_save_fallback_timeout_in_seconds(0);
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving(
......@@ -1123,9 +1143,9 @@ TEST_F(ManagePasswordsUIControllerTest,
<< user_saved_password);
ManagePasswordsUIController::set_save_fallback_timeout_in_seconds(0);
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving(
......@@ -1164,9 +1184,9 @@ TEST_F(ManagePasswordsUIControllerTest,
TEST_F(ManagePasswordsUIControllerTest,
ManualFallbackForSavingFollowedByAutomaticBubble) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving(
......@@ -1180,16 +1200,19 @@ TEST_F(ManagePasswordsUIControllerTest,
// Automatic form submission detected.
test_form_manager = CreateFormManager();
autofill::PasswordForm form = test_local_form();
form.username_value = base::ASCIIToUTF16("some_other_username");
form.password_value = base::ASCIIToUTF16("password123");
test_form_manager->ProvisionallySave(form);
FormData form = submitted_form();
form.fields[0].value = ASCIIToUTF16("some_other_username");
form.fields[1].value = ASCIIToUTF16("password123");
test_form_manager->ProvisionallySave(form, &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(0);
controller()->OnPasswordSubmitted(std::move(test_form_manager));
// It should have no effect as the bubble was already open.
ExpectIconAndControllerStateIs(password_manager::ui::PENDING_PASSWORD_STATE);
EXPECT_EQ(test_local_form(), controller()->GetPendingPassword());
EXPECT_EQ(test_local_form().username_value,
controller()->GetPendingPassword().username_value);
EXPECT_EQ(test_local_form().password_value,
controller()->GetPendingPassword().password_value);
}
TEST_F(ManagePasswordsUIControllerTest,
......@@ -1197,10 +1220,10 @@ TEST_F(ManagePasswordsUIControllerTest,
for (bool user_closed_bubble : {false, true}) {
SCOPED_TRACE(testing::Message("user_closed_bubble = ")
<< user_closed_bubble);
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(test_local_form(),
{&test_local_form()}, nullptr));
test_form_manager->ProvisionallySave(test_local_form());
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManagerWithBestMatches(observed_form(), {&test_local_form()},
nullptr));
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnShowManualFallbackForSaving(
std::move(test_form_manager), true /* has_generated_password */, false);
......@@ -1221,9 +1244,9 @@ TEST_F(ManagePasswordsUIControllerTest,
}
TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
......@@ -1234,7 +1257,7 @@ TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) {
ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE);
// The controller shouldn't force close the bubble if an autofill happened.
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()).Times(0);
std::map<base::string16, const autofill::PasswordForm*> map;
std::map<base::string16, const PasswordForm*> map;
base::string16 test_username = test_local_form().username_value;
map.insert(std::make_pair(test_username, &test_local_form()));
controller()->OnPasswordAutofilled(map, map.begin()->second->origin, nullptr);
......@@ -1245,9 +1268,9 @@ TEST_F(ManagePasswordsUIControllerTest, AutofillDuringSignInPromo) {
}
TEST_F(ManagePasswordsUIControllerTest, AuthenticateUserToRevealPasswords) {
std::unique_ptr<password_manager::PasswordFormManager> test_form_manager(
std::unique_ptr<NewPasswordFormManager> test_form_manager(
CreateFormManager());
test_form_manager->ProvisionallySave(test_local_form());
test_form_manager->ProvisionallySave(submitted_form(), &driver());
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnPasswordSubmitted(std::move(test_form_manager));
EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
......
......@@ -168,7 +168,9 @@ NewPasswordFormManager::NewPasswordFormManager(
form_fetcher_->AddConsumer(this);
}
NewPasswordFormManager::~NewPasswordFormManager() = default;
NewPasswordFormManager::~NewPasswordFormManager() {
form_fetcher_->RemoveConsumer(this);
}
bool NewPasswordFormManager::DoesManage(
const FormData& form,
......
......@@ -340,6 +340,9 @@ class NewPasswordFormManagerTest : public testing::Test {
StartUploadRequest(_, _, _, _, _, _))
.WillByDefault(testing::Return(true));
fetcher_.reset(new FakeFormFetcher());
fetcher_->Fetch();
CreateFormManager(observed_form_);
}
......@@ -365,8 +368,6 @@ class NewPasswordFormManagerTest : public testing::Test {
// Creates NewPasswordFormManager and sets it to |form_manager_|. Along the
// way a new |fetcher_| is created.
void CreateFormManager(const FormData& observed_form) {
fetcher_.reset(new FakeFormFetcher());
fetcher_->Fetch();
form_manager_.reset(new NewPasswordFormManager(
&client_, driver_.AsWeakPtr(), observed_form, fetcher_.get(),
std::make_unique<NiceMock<MockFormSaver>>(), nullptr));
......@@ -376,8 +377,6 @@ class NewPasswordFormManagerTest : public testing::Test {
// |base_auth_observed_form|. Along the way a new |fetcher_| is created.
void CreateFormManagerForNonWebForm(
const PasswordForm& base_auth_observed_form) {
fetcher_.reset(new FakeFormFetcher());
fetcher_->Fetch();
form_manager_.reset(new NewPasswordFormManager(
&client_, PasswordStore::FormDigest(base_auth_observed_form),
fetcher_.get(), std::make_unique<NiceMock<MockFormSaver>>()));
......
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