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

Unified Diff: chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm

Issue 3302015: AutoFill Mac dialog should be non-modal (Closed)
Patch Set: Indent. Created 10 years, 3 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_dialog_controller_mac_unittest.mm
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
index c2ae027c5f97ea6129dd8e1fe6997efc83471b51..d439288518c5ad84bb2520164d0af2ba1ca062df 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
@@ -151,11 +151,8 @@ class AutoFillDialogControllerTest : public CocoaTest {
void LoadDialog() {
controller_ = [AutoFillDialogController
- controllerWithObserver:&observer_
- profile:helper_.profile()
- importedProfile:imported_profile_
- importedCreditCard:imported_credit_card_];
- [controller_ window];
+ controllerWithObserver:&observer_ profile:helper_.profile()];
+ [controller_ runModelessDialog];
}
std::vector<AutoFillProfile*>& profiles() {
@@ -175,69 +172,36 @@ class AutoFillDialogControllerTest : public CocoaTest {
DISALLOW_COPY_AND_ASSIGN(AutoFillDialogControllerTest);
};
-TEST_F(AutoFillDialogControllerTest, SaveButtonInformsObserver) {
+TEST_F(AutoFillDialogControllerTest, CloseButtonDoesNotInformObserver) {
LoadDialog();
- [controller_ save:nil];
- ASSERT_TRUE(observer_.hit_);
-}
-
-TEST_F(AutoFillDialogControllerTest, CancelButtonDoesNotInformObserver) {
- LoadDialog();
- [controller_ cancel:nil];
+ [controller_ closeDialog];
ASSERT_FALSE(observer_.hit_);
}
-TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) {
+TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverProfiles) {
AutoFillProfile profile;
profiles().push_back(&profile);
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
-
- // Sizes should match.
- ASSERT_EQ(observer_.profiles_.size(), profiles().size());
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
- // Contents should match.
- size_t i = 0;
- size_t count = profiles().size();
- for (i = 0; i < count; i++)
- ASSERT_EQ(observer_.profiles_[i], *profiles()[i]);
-
- // Contents should not match a different profile.
- AutoFillProfile different_profile;
- different_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("joe"));
- for (i = 0; i < count; i++)
- ASSERT_NE(observer_.profiles_[i], different_profile);
+ // Observer should not have profiles.
+ ASSERT_EQ(0UL, observer_.profiles_.size());
}
-TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalCreditCard) {
+TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverCreditCards) {
CreditCard credit_card(ASCIIToUTF16("myCC"), 345);
credit_cards().push_back(&credit_card);
LoadDialog();
- [controller_ save:nil];
-
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
-
- // Sizes should match.
- ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
+ [controller_ closeDialog];
- // Contents should match. With the exception of the |unique_id|.
- size_t i = 0;
- size_t count = credit_cards().size();
- for (i = 0; i < count; i++) {
- credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id());
- ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]);
- }
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
- // Contents should not match a different profile.
- CreditCard different_credit_card(ASCIIToUTF16("different"), 0);
- different_credit_card.SetInfo(
- AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234"));
- for (i = 0; i < count; i++)
- ASSERT_NE(observer_.credit_cards_[i], different_credit_card);
+ // Observer should not have credit cards.
+ ASSERT_EQ(0UL, observer_.credit_cards_.size());
}
TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
@@ -246,20 +210,20 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("C"));
profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith"));
profile.SetInfo(AutoFillType(EMAIL_ADDRESS),
- ASCIIToUTF16("john@chromium.org"));
+ ASCIIToUTF16("john@chromium.org"));
profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google Inc."));
profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1),
ASCIIToUTF16("1122 Mountain View Road"));
profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("Suite #1"));
profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY),
- ASCIIToUTF16("Mountain View"));
+ ASCIIToUTF16("Mountain View"));
profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA"));
profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("94111"));
profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA"));
- profile.SetInfo(
- AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552258"));
- profile.SetInfo(
- AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("024087172258"));
+ profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER),
+ ASCIIToUTF16("014155552258"));
+ profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
+ ASCIIToUTF16("024087172258"));
profiles().push_back(&profile);
LoadDialog();
@@ -281,7 +245,7 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
EXPECT_TRUE([[am faxWholeNumber] isEqualToString:@"024087172258"]);
[sheet save:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
ASSERT_TRUE(observer_.hit_);
ASSERT_TRUE(observer_.profiles_.size() == 1);
@@ -296,11 +260,11 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
CreditCard credit_card(ASCIIToUTF16("myCC"), 345);
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("DCH"));
- credit_card.SetInfo(
- AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234 5678 9101 1121"));
+ credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER),
+ ASCIIToUTF16("1234 5678 9101 1121"));
credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01"));
- credit_card.SetInfo(
- AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), ASCIIToUTF16("2012"));
+ credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
+ ASCIIToUTF16("2012"));
credit_cards().push_back(&credit_card);
LoadDialog();
@@ -322,7 +286,7 @@ TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
EXPECT_TRUE([[numberField stringValue] isEqualToString:@"************1121"]);
[sheet save:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
ASSERT_TRUE(observer_.hit_);
ASSERT_TRUE(observer_.credit_cards_.size() == 1);
@@ -340,23 +304,23 @@ TEST_F(AutoFillDialogControllerTest, TwoProfiles) {
profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
profiles().push_back(&profile2);
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Sizes should match. And should be 2.
- ASSERT_EQ(observer_.profiles_.size(), profiles().size());
- ASSERT_EQ(observer_.profiles_.size(), 2UL);
+ ASSERT_EQ([controller_ profiles].size(), profiles().size());
+ ASSERT_EQ([controller_ profiles].size(), 2UL);
// Contents should match. With the exception of the |unique_id|.
for (size_t i = 0, count = profiles().size(); i < count; i++) {
- profiles()[i]->set_unique_id(observer_.profiles_[i].unique_id());
+ profiles()[i]->set_unique_id([controller_ profiles][i].unique_id());
// Do not compare labels. Label is a derived field.
- observer_.profiles_[i].set_label(string16());
+ [controller_ profiles][i].set_label(string16());
profiles()[i]->set_label(string16());
- ASSERT_EQ(observer_.profiles_[i], *profiles()[i]);
+ ASSERT_EQ([controller_ profiles][i], *profiles()[i]);
}
}
@@ -368,19 +332,19 @@ TEST_F(AutoFillDialogControllerTest, TwoCreditCards) {
credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
credit_cards().push_back(&credit_card2);
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Sizes should match. And should be 2.
- ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
- ASSERT_EQ(observer_.credit_cards_.size(), 2UL);
+ ASSERT_EQ([controller_ creditCards].size(), credit_cards().size());
+ ASSERT_EQ([controller_ creditCards].size(), 2UL);
// Contents should match. With the exception of the |unique_id|.
for (size_t i = 0, count = credit_cards().size(); i < count; i++) {
- credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id());
- ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]);
+ credit_cards()[i]->set_unique_id([controller_ creditCards][i].unique_id());
+ ASSERT_EQ([controller_ creditCards][i], *credit_cards()[i]);
}
}
@@ -396,7 +360,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
ASSERT_TRUE(model != nil);
[model setFullName:@"Don"];
[sheet save:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -425,7 +389,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
ASSERT_TRUE(model != nil);
[model setNameOnCard:@"Don"];
[sheet save:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -450,18 +414,13 @@ TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) {
AutoFillAddressSheetController* sheet = [controller_ addressSheetController];
ASSERT_TRUE(sheet != nil);
[sheet save:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
-
- // Sizes should be same. Empty profile should not be saved.
- ASSERT_EQ(observer_.profiles_.size(), profiles().size());
- ASSERT_EQ(observer_.profiles_.size(), 1UL);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
- // Profile should match original.
- observer_.profiles_[0].set_label(string16());
- ASSERT_EQ(observer_.profiles_[0], profile);
+ // Empty profile should not be saved.
+ ASSERT_EQ(0UL, observer_.profiles_.size());
}
TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) {
@@ -474,18 +433,13 @@ TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) {
[controller_ creditCardSheetController];
ASSERT_TRUE(sheet != nil);
[sheet save:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
-
- // Sizes should be same. Empty credit card should not be saved.
- ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
- ASSERT_EQ(observer_.credit_cards_.size(), 1UL);
+ ASSERT_FALSE(observer_.hit_);
- // Credit card should match original.
- observer_.credit_cards_[0].set_label(string16());
- ASSERT_EQ(observer_.credit_cards_[0], credit_card);
+ // Empty credit card should not be saved.
+ ASSERT_EQ(0UL, observer_.credit_cards_.size());
}
TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
@@ -495,7 +449,7 @@ TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
LoadDialog();
[controller_ selectAddressAtIndex:0];
[controller_ deleteSelection:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -512,7 +466,7 @@ TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) {
LoadDialog();
[controller_ selectCreditCardAtIndex:0];
[controller_ deleteSelection:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -532,7 +486,7 @@ TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) {
LoadDialog();
[controller_ selectAddressAtIndex:1];
[controller_ deleteSelection:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -560,7 +514,7 @@ TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) {
LoadDialog();
[controller_ selectCreditCardAtIndex:1];
[controller_ deleteSelection:nil];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -596,7 +550,7 @@ TEST_F(AutoFillDialogControllerTest, DeleteMultiple) {
[controller_ deleteSelection:nil];
[controller_ selectAddressAtIndex:0];
ASSERT_TRUE([controller_ editButtonEnabled]);
- [controller_ save:nil];
+ [controller_ closeDialog];
// Should hit our observer.
ASSERT_TRUE(observer_.hit_);
@@ -625,10 +579,10 @@ TEST_F(AutoFillDialogControllerTest, DeleteMultiple) {
// Auxilliary profiles are enabled by default.
TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesTrue) {
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Auxiliary profiles setting should be unchanged.
ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
@@ -639,10 +593,10 @@ TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesFalse) {
helper_.profile()->GetPrefs()->SetBoolean(
prefs::kAutoFillAuxiliaryProfilesEnabled, false);
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Auxiliary profiles setting should be unchanged.
ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean(
@@ -654,10 +608,10 @@ TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesChanged) {
prefs::kAutoFillAuxiliaryProfilesEnabled, false);
LoadDialog();
[controller_ setAuxiliaryEnabled:YES];
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Auxiliary profiles setting should be unchanged.
ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
@@ -671,70 +625,37 @@ TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) {
credit_cards().push_back(&credit_card);
helper_.test_profile_->test_manager_->test_data_is_loaded_ = false;
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Sizes should match.
- ASSERT_EQ(observer_.profiles_.size(), profiles().size());
- ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
+ ASSERT_EQ([controller_ profiles].size(), profiles().size());
+ ASSERT_EQ([controller_ creditCards].size(), credit_cards().size());
// Contents should match.
size_t i = 0;
size_t count = profiles().size();
for (i = 0; i < count; i++) {
// Do not compare labels. Label is a derived field.
- observer_.profiles_[i].set_label(string16());
+ [controller_ profiles][i].set_label(string16());
profiles()[i]->set_label(string16());
- ASSERT_EQ(observer_.profiles_[i], *profiles()[i]);
+ ASSERT_EQ([controller_ profiles][i], *profiles()[i]);
}
count = credit_cards().size();
for (i = 0; i < count; i++) {
- ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]);
+ ASSERT_EQ([controller_ creditCards][i], *credit_cards()[i]);
}
}
-TEST_F(AutoFillDialogControllerTest, ImportedParameters) {
- AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
- imported_profile_ = &profile;
- CreditCard credit_card(ASCIIToUTF16("Mastercard"), 0);
- imported_credit_card_ = &credit_card;
-
- // Note: when the |imported_*| parameters are supplied the dialog should
- // ignore any profile and credit card information in the
- // |PersonalDataManager|.
- AutoFillProfile profile_ignored(ASCIIToUTF16("Work"), 0);
- profiles().push_back(&profile_ignored);
- CreditCard credit_card_ignored(ASCIIToUTF16("Visa"), 0);
- credit_cards().push_back(&credit_card_ignored);
-
- LoadDialog();
- [controller_ save:nil];
-
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
-
- // Sizes should match.
- ASSERT_EQ(1UL, observer_.profiles_.size());
- ASSERT_EQ(1UL, observer_.credit_cards_.size());
-
- // Do not compare labels. Label is a derived field.
- observer_.profiles_[0].set_label(string16());
- profile.set_label(string16());
-
- // Contents should match.
- ASSERT_EQ(observer_.profiles_[0], profile);
- ASSERT_EQ(observer_.credit_cards_[0], credit_card);
-}
-
// AutoFill is enabled by default.
TEST_F(AutoFillDialogControllerTest, AutoFillEnabledTrue) {
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// AutoFill enabled setting should be unchanged.
ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
@@ -744,10 +665,10 @@ TEST_F(AutoFillDialogControllerTest, AutoFillEnabledTrue) {
TEST_F(AutoFillDialogControllerTest, AutoFillEnabledFalse) {
helper_.profile()->GetPrefs()->SetBoolean(prefs::kAutoFillEnabled, false);
LoadDialog();
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// AutoFill enabled setting should be unchanged.
ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean(
@@ -759,10 +680,10 @@ TEST_F(AutoFillDialogControllerTest, AutoFillEnabledChanged) {
prefs::kAutoFillAuxiliaryProfilesEnabled, false);
LoadDialog();
[controller_ setAutoFillEnabled:YES];
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Should hit our observer.
- ASSERT_TRUE(observer_.hit_);
+ // Should not hit our observer.
+ ASSERT_FALSE(observer_.hit_);
// Auxiliary profiles setting should be unchanged.
ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
@@ -785,7 +706,7 @@ TEST_F(AutoFillDialogControllerTest, PolicyRefresh) {
ASSERT_TRUE([controller_ autoFillManaged]);
ASSERT_TRUE([controller_ autoFillEnabled]);
- [controller_ cancel:nil];
+ [controller_ closeDialog];
}
TEST_F(AutoFillDialogControllerTest, PolicyDisabledAndSave) {
@@ -800,7 +721,7 @@ TEST_F(AutoFillDialogControllerTest, PolicyDisabledAndSave) {
ASSERT_TRUE([controller_ autoFillManagedAndDisabled]);
[controller_ setAuxiliaryEnabled:YES];
- [controller_ save:nil];
+ [controller_ closeDialog];
// Observer should not have been called.
ASSERT_FALSE(observer_.hit_);
@@ -822,10 +743,10 @@ TEST_F(AutoFillDialogControllerTest, PolicyEnabledAndSave) {
ASSERT_FALSE([controller_ autoFillManagedAndDisabled]);
[controller_ setAuxiliaryEnabled:YES];
- [controller_ save:nil];
+ [controller_ closeDialog];
- // Observer should have been notified.
- ASSERT_TRUE(observer_.hit_);
+ // Observer should not have been notified.
+ ASSERT_FALSE(observer_.hit_);
// Auxiliary profiles setting should have been saved.
ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean(
« no previous file with comments | « chrome/browser/autofill/autofill_dialog_controller_mac.mm ('k') | chrome/browser/autofill/autofill_dialog_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698