Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 10222017: Make password generation switched by a preference in chrome settings rather than a command line fla… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes according to code reviews Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_manager_unittest.cc
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 2f3ae8137a9932fb6ea42eefbc9792c9d670ad4a..236b120e7b39fec9b8547bf7315926b53a74938b 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -2921,9 +2921,63 @@ TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
FormSubmitted(form);
}
-TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
+TEST_F(AutofillManagerTest, RemoveProfile) {
+ // Add and remove an Autofill profile.
+ AutofillProfile* profile = new AutofillProfile;
+ std::string guid = "00000000-0000-0000-0000-000000000102";
+ profile->set_guid(guid.c_str());
+ autofill_manager_->AddProfile(profile);
+
+ GUIDPair guid_pair(guid, 0);
+ GUIDPair empty(std::string(), 0);
+ int id = PackGUIDs(empty, guid_pair);
+
+ autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+
+ EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
+}
Ilya Sherman 2012/05/04 06:04:50 nit: Why is it helpful to move this test? Again,
zysxqn 2012/05/04 18:52:54 Done.
+
+TEST_F(AutofillManagerTest, RemoveCreditCard){
+ // Add and remove an Autofill credit card.
+ CreditCard* credit_card = new CreditCard;
+ std::string guid = "00000000-0000-0000-0000-000000100007";
+ credit_card->set_guid(guid.c_str());
+ autofill_manager_->AddCreditCard(credit_card);
+
+ GUIDPair guid_pair(guid, 0);
+ GUIDPair empty(std::string(), 0);
+ int id = PackGUIDs(guid_pair, empty);
+
+ autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+
+ EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str()));
+}
+
+TEST_F(AutofillManagerTest, RemoveProfileVariant) {
+ // Add and remove an Autofill profile.
+ AutofillProfile* profile = new AutofillProfile;
+ std::string guid = "00000000-0000-0000-0000-000000000102";
+ profile->set_guid(guid.c_str());
+ autofill_manager_->AddProfile(profile);
+
+ GUIDPair guid_pair(guid, 1);
+ GUIDPair empty(std::string(), 0);
+ int id = PackGUIDs(empty, guid_pair);
+
+ autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+
+ // TODO(csharp): Currently variants should not be deleted, but once they are
+ // update these expectations.
+ // http://crbug.com/124211
+ EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
+}
+
+TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
// Allow this test to control what should get synced.
profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
+ // Always set password generation enabled check box so we can test the
+ // behavior of password sync.
+ profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
// Sync some things, but not passwords. Shouldn't send anything since
// password generation is disabled by default.
@@ -2973,55 +3027,46 @@ TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
autofill_manager_->ClearSentStates();
}
-TEST_F(AutofillManagerTest, RemoveProfile) {
- // Add and remove an Autofill profile.
- AutofillProfile* profile = new AutofillProfile;
- std::string guid = "00000000-0000-0000-0000-000000000102";
- profile->set_guid(guid.c_str());
- autofill_manager_->AddProfile(profile);
-
- GUIDPair guid_pair(guid, 0);
- GUIDPair empty(std::string(), 0);
- int id = PackGUIDs(empty, guid_pair);
-
- autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
-
- EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
-}
-
-TEST_F(AutofillManagerTest, RemoveCreditCard){
- // Add and remove an Autofill credit card.
- CreditCard* credit_card = new CreditCard;
- std::string guid = "00000000-0000-0000-0000-000000100007";
- credit_card->set_guid(guid.c_str());
- autofill_manager_->AddCreditCard(credit_card);
-
- GUIDPair guid_pair(guid, 0);
- GUIDPair empty(std::string(), 0);
- int id = PackGUIDs(guid_pair, empty);
-
- autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
+ // Always set password sync enabled so we can test the behavior of password
+ // generation.
+ profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
+ ProfileSyncService* sync_service = GetProfileSyncService();
+ sync_service->SetSyncSetupCompleted();
+ syncable::ModelTypeSet preferred_set;
+ preferred_set.Put(syncable::PASSWORDS);
+ sync_service->ChangePreferredDataTypes(preferred_set);
- EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str()));
-}
+ // Enabled state remains false, should not sent.
+ profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false);
+ UpdatePasswordGenerationState(false);
+ EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
-TEST_F(AutofillManagerTest, RemoveProfileVariant) {
- // Add and remove an Autofill profile.
- AutofillProfile* profile = new AutofillProfile;
- std::string guid = "00000000-0000-0000-0000-000000000102";
- profile->set_guid(guid.c_str());
- autofill_manager_->AddProfile(profile);
+ // Enabled state from false to true, should sent true.
+ profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
+ UpdatePasswordGenerationState(false);
+ EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
+ EXPECT_TRUE(autofill_manager_->GetSentStates()[0]);
+ autofill_manager_->ClearSentStates();
- GUIDPair guid_pair(guid, 1);
- GUIDPair empty(std::string(), 0);
- int id = PackGUIDs(empty, guid_pair);
+ // Enabled states remains true, should not sent.
+ profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
+ UpdatePasswordGenerationState(false);
+ EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
- autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+ // Enabled states from true to false, should sent false.
+ profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false);
+ UpdatePasswordGenerationState(false);
+ EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
+ EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
+ autofill_manager_->ClearSentStates();
- // TODO(csharp): Currently variants should not be deleted, but once they are
- // update these expectations.
- // http://crbug.com/124211
- EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
+ // When a new render_view is created, we send the state even if it's the
+ // same.
+ UpdatePasswordGenerationState(true);
+ EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
+ EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
+ autofill_manager_->ClearSentStates();
}
namespace {

Powered by Google App Engine
This is Rietveld 408576698