| Index: components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| diff --git a/components/password_manager/core/browser/password_autofill_manager_unittest.cc b/components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| index ab09812d3429900d2393a1e68681d145164296c5..1f46b403c1249eedccae54448bbfd1ae9da51fe4 100644
|
| --- a/components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| +++ b/components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| @@ -73,13 +73,15 @@ class PasswordAutofillManagerTest : public testing::Test {
|
| protected:
|
| PasswordAutofillManagerTest()
|
| : test_username_(base::ASCIIToUTF16(kAliceUsername)),
|
| - test_password_(base::ASCIIToUTF16(kAlicePassword)) {}
|
| + test_password_(base::ASCIIToUTF16(kAlicePassword)),
|
| + fill_data_id_(0) {}
|
|
|
| void SetUp() override {
|
| // Add a preferred login and an additional login to the FillData.
|
| - username_field_.name = base::ASCIIToUTF16(kUsernameName);
|
| - username_field_.value = test_username_;
|
| - fill_data_.basic_data.fields.push_back(username_field_);
|
| + autofill::FormFieldData username_field;
|
| + username_field.name = base::ASCIIToUTF16(kUsernameName);
|
| + username_field.value = test_username_;
|
| + fill_data_.basic_data.fields.push_back(username_field);
|
|
|
| autofill::FormFieldData password_field;
|
| password_field.name = base::ASCIIToUTF16(kPasswordName);
|
| @@ -92,19 +94,21 @@ class PasswordAutofillManagerTest : public testing::Test {
|
| autofill::AutofillClient* autofill_client) {
|
| password_autofill_manager_.reset(
|
| new PasswordAutofillManager(client, autofill_client));
|
| - password_autofill_manager_->OnAddPasswordFormMapping(username_field_,
|
| + password_autofill_manager_->OnAddPasswordFormMapping(fill_data_id_,
|
| fill_data_);
|
| }
|
|
|
| protected:
|
| + int fill_data_id() { return fill_data_id_; }
|
| +
|
| scoped_ptr<PasswordAutofillManager> password_autofill_manager_;
|
|
|
| - autofill::FormFieldData username_field_;
|
| base::string16 test_username_;
|
| base::string16 test_password_;
|
|
|
| private:
|
| autofill::PasswordFormFillData fill_data_;
|
| + const int fill_data_id_;
|
|
|
| // The TestAutofillDriver uses a SequencedWorkerPool which expects the
|
| // existence of a MessageLoop.
|
| @@ -118,23 +122,22 @@ TEST_F(PasswordAutofillManagerTest, FillSuggestion) {
|
| EXPECT_CALL(*client->mock_driver(),
|
| FillSuggestion(test_username_, test_password_));
|
| EXPECT_TRUE(password_autofill_manager_->FillSuggestionForTest(
|
| - username_field_, test_username_));
|
| + fill_data_id(), test_username_));
|
| testing::Mock::VerifyAndClearExpectations(client->mock_driver());
|
|
|
| EXPECT_CALL(*client->mock_driver(),
|
| FillSuggestion(_, _)).Times(0);
|
| EXPECT_FALSE(password_autofill_manager_->FillSuggestionForTest(
|
| - username_field_, base::ASCIIToUTF16(kInvalidUsername)));
|
| + fill_data_id(), base::ASCIIToUTF16(kInvalidUsername)));
|
|
|
| - autofill::FormFieldData invalid_username_field;
|
| - invalid_username_field.name = base::ASCIIToUTF16(kInvalidUsername);
|
| + const int invalid_fill_data_id = fill_data_id() + 1;
|
|
|
| EXPECT_FALSE(password_autofill_manager_->FillSuggestionForTest(
|
| - invalid_username_field, test_username_));
|
| + invalid_fill_data_id, test_username_));
|
|
|
| password_autofill_manager_->Reset();
|
| EXPECT_FALSE(password_autofill_manager_->FillSuggestionForTest(
|
| - username_field_, test_username_));
|
| + fill_data_id(), test_username_));
|
| }
|
|
|
| TEST_F(PasswordAutofillManagerTest, PreviewSuggestion) {
|
| @@ -144,22 +147,21 @@ TEST_F(PasswordAutofillManagerTest, PreviewSuggestion) {
|
| EXPECT_CALL(*client->mock_driver(),
|
| PreviewSuggestion(test_username_, test_password_));
|
| EXPECT_TRUE(password_autofill_manager_->PreviewSuggestionForTest(
|
| - username_field_, test_username_));
|
| + fill_data_id(), test_username_));
|
| testing::Mock::VerifyAndClearExpectations(client->mock_driver());
|
|
|
| EXPECT_CALL(*client->mock_driver(), PreviewSuggestion(_, _)).Times(0);
|
| EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest(
|
| - username_field_, base::ASCIIToUTF16(kInvalidUsername)));
|
| + fill_data_id(), base::ASCIIToUTF16(kInvalidUsername)));
|
|
|
| - autofill::FormFieldData invalid_username_field;
|
| - invalid_username_field.name = base::ASCIIToUTF16(kInvalidUsername);
|
| + const int invalid_fill_data_id = fill_data_id() + 1;
|
|
|
| EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest(
|
| - invalid_username_field, test_username_));
|
| + invalid_fill_data_id, test_username_));
|
|
|
| password_autofill_manager_->Reset();
|
| EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest(
|
| - username_field_, test_username_));
|
| + fill_data_id(), test_username_));
|
| }
|
|
|
| // Test that the popup is marked as visible after recieving password
|
| @@ -175,7 +177,7 @@ TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) {
|
| data.basic_data.fields[0].value = test_username_;
|
| data.basic_data.fields[1].value = test_password_;
|
| data.preferred_realm = "http://foo.com/";
|
| - autofill::FormFieldData dummy_key;
|
| + int dummy_key = 0;
|
| password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
|
|
|
| EXPECT_CALL(*client->mock_driver(),
|
| @@ -192,7 +194,8 @@ TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) {
|
| testing::ElementsAre(autofill::POPUP_ITEM_ID_PASSWORD_ENTRY),
|
| _));
|
| password_autofill_manager_->OnShowPasswordSuggestions(
|
| - dummy_key, base::string16(), false, element_bounds);
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::string16(), false,
|
| + element_bounds);
|
|
|
| // Accepting a suggestion should trigger a call to hide the popup.
|
| EXPECT_CALL(*autofill_client, HideAutofillPopup());
|
| @@ -226,7 +229,7 @@ TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) {
|
| other_names.push_back(other_username);
|
| data.other_possible_usernames[usernames_key] = other_names;
|
|
|
| - autofill::FormFieldData dummy_key;
|
| + int dummy_key = 0;
|
| password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
|
|
|
| // First, simulate displaying suggestions matching an empty prefix.
|
| @@ -237,7 +240,8 @@ TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) {
|
| test_username_, additional_username, other_username),
|
| _, _, _, _));
|
| password_autofill_manager_->OnShowPasswordSuggestions(
|
| - dummy_key, base::string16(), false, element_bounds);
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::string16(), false,
|
| + element_bounds);
|
|
|
| // Now simulate displaying suggestions matching "John".
|
| EXPECT_CALL(*autofill_client,
|
| @@ -246,7 +250,8 @@ TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) {
|
| additional_username, other_username),
|
| _, _, _, _));
|
| password_autofill_manager_->OnShowPasswordSuggestions(
|
| - dummy_key, base::ASCIIToUTF16("John"), false, element_bounds);
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("John"), false,
|
| + element_bounds);
|
|
|
| // Finally, simulate displaying all suggestions, without any prefix matching.
|
| EXPECT_CALL(*autofill_client,
|
| @@ -256,7 +261,8 @@ TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) {
|
| test_username_, additional_username, other_username),
|
| _, _, _, _));
|
| password_autofill_manager_->OnShowPasswordSuggestions(
|
| - dummy_key, base::ASCIIToUTF16("xyz"), true, element_bounds);
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true,
|
| + element_bounds);
|
| }
|
|
|
| } // namespace password_manager
|
|
|