summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-27 15:25:57 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-27 15:25:57 +0000
commite94f1860db455c3af9e8e245505b2335e5cf1be5 (patch)
tree8be682860612b86d5aa28d124538f44a8bc1a8f4 /chrome
parent809cc4d808f30112929ef9c33183e6cc052d3f88 (diff)
downloadchromium_src-e94f1860db455c3af9e8e245505b2335e5cf1be5.zip
chromium_src-e94f1860db455c3af9e8e245505b2335e5cf1be5.tar.gz
chromium_src-e94f1860db455c3af9e8e245505b2335e5cf1be5.tar.bz2
Autofill deprecate unique_ids in favor of guids for Mac UI
Removes use of labels and unique_ids in the Mac UI for Autofill. BUG=58813 TEST=AutoFillAddressModelTest.*:AutoFillAddressSheetControllerTest.*:AutoFillCreditCardModelTest.*:AutoFillDialogControllerTest.* Review URL: http://codereview.chromium.org/4110004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64073 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/autofill/autofill_address_model_mac_unittest.mm6
-rw-r--r--chrome/browser/autofill/autofill_address_sheet_controller_mac_unittest.mm2
-rw-r--r--chrome/browser/autofill/autofill_credit_card_model_mac_unittest.mm6
-rw-r--r--chrome/browser/autofill/autofill_credit_card_sheet_controller_mac_unittest.mm2
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac.h6
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac.mm39
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm91
-rw-r--r--chrome/browser/autofill/autofill_profile.cc30
-rw-r--r--chrome/browser/autofill/autofill_profile.h5
-rw-r--r--chrome/browser/autofill/credit_card.cc89
-rw-r--r--chrome/browser/autofill/credit_card.h20
-rw-r--r--chrome/browser/autofill/form_group.cc2
-rw-r--r--chrome/browser/autofill/form_group.h2
14 files changed, 112 insertions, 194 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 6078e74..7a51308 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6655,9 +6655,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_AUTOFILL_BAD_LABEL_TOOLTIP" desc="Tooltip that appears over the wrong label.">
Label must contain at least one character.
</message>
- <message name="IDS_AUTOFILL_NEW_ADDRESS" desc="The profile label of a new address.">
- New address
- </message>
<message name="IDS_AUTOFILL_MAC_ADDRESS_LINE_SEPARATOR" desc="The separator character used to join multi-line addresses on the Mac.">
, '''
</message>
@@ -6676,9 +6673,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_NAME_FORMAT" desc="The format string of the summary of an address. $1=firstName, $2=separator, $3=lastName">
<ph name="FIRSTNAME">$1<ex>John</ex></ph><ph name="SEPARATOR">$2<ex>''' '''</ex></ph><ph name="LASTNAME">$3<ex>Smith</ex></ph>
</message>
- <message name="IDS_AUTOFILL_NEW_CREDITCARD" desc="The profile label of a new credit card.">
- New credit card
- </message>
<message name="IDS_AUTOFILL_UNTITLED_LABEL" desc="The text substituted on empty label">
Untitled
</message>
diff --git a/chrome/browser/autofill/autofill_address_model_mac_unittest.mm b/chrome/browser/autofill/autofill_address_model_mac_unittest.mm
index 3cf29c8..21ee8b5 100644
--- a/chrome/browser/autofill/autofill_address_model_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_address_model_mac_unittest.mm
@@ -18,14 +18,14 @@ typedef CocoaTest AutoFillAddressModelTest;
TEST(AutoFillAddressModelTest, Basic) {
// A basic test that creates a new instance and releases.
// Aids valgrind leak detection.
- AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
+ AutoFillProfile profile;
scoped_nsobject<AutoFillAddressModel> model([[AutoFillAddressModel alloc]
initWithProfile:profile]);
EXPECT_TRUE(model.get());
}
TEST(AutoFillAddressModelTest, InitializationFromProfile) {
- AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
+ AutoFillProfile profile;
autofill_test::SetProfileInfo(
&profile,
"Billing",
@@ -59,7 +59,7 @@ TEST(AutoFillAddressModelTest, InitializationFromProfile) {
}
TEST(AutoFillAddressModelTest, CopyModelToProfile) {
- AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
+ AutoFillProfile profile;
autofill_test::SetProfileInfo(
&profile,
"Billing",
diff --git a/chrome/browser/autofill/autofill_address_sheet_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_address_sheet_controller_mac_unittest.mm
index 7c72255..2d6d34a 100644
--- a/chrome/browser/autofill/autofill_address_sheet_controller_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_address_sheet_controller_mac_unittest.mm
@@ -17,7 +17,7 @@ typedef CocoaTest AutoFillAddressSheetControllerTest;
TEST(AutoFillAddressSheetControllerTest, Basic) {
// A basic test that creates a new instance and releases.
// Aids valgrind leak detection.
- AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
+ AutoFillProfile profile;
scoped_nsobject<AutoFillAddressSheetController> controller(
[[AutoFillAddressSheetController alloc]
initWithProfile:profile
diff --git a/chrome/browser/autofill/autofill_credit_card_model_mac_unittest.mm b/chrome/browser/autofill/autofill_credit_card_model_mac_unittest.mm
index 0f10a12..e95c2dd 100644
--- a/chrome/browser/autofill/autofill_credit_card_model_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_credit_card_model_mac_unittest.mm
@@ -18,14 +18,14 @@ typedef CocoaTest AutoFillCreditCardModelTest;
TEST(AutoFillCreditCardModelTest, Basic) {
// A basic test that creates a new instance and releases.
// Aids valgrind leak detection.
- CreditCard credit_card(ASCIIToUTF16("myCC"), 0);
+ CreditCard credit_card;
scoped_nsobject<AutoFillCreditCardModel> model(
[[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]);
EXPECT_TRUE(model.get());
}
TEST(AutoFillCreditCardModelTest, InitializationFromCreditCard) {
- CreditCard credit_card(string16(), 0);
+ CreditCard credit_card;
autofill_test::SetCreditCardInfo(&credit_card, "Corporate",
"John Dillinger", "123456789012", "01", "2010");
scoped_nsobject<AutoFillCreditCardModel> model(
@@ -39,7 +39,7 @@ TEST(AutoFillCreditCardModelTest, InitializationFromCreditCard) {
}
TEST(AutoFillCreditCardModelTest, CopyModelToCreditCard) {
- CreditCard credit_card(string16(), 0);
+ CreditCard credit_card;
autofill_test::SetCreditCardInfo(&credit_card, "Corporate",
"John Dillinger", "123456789012", "01", "2010");
scoped_nsobject<AutoFillCreditCardModel> model(
diff --git a/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac_unittest.mm
index f6c01d5..6f943ea 100644
--- a/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac_unittest.mm
@@ -17,7 +17,7 @@ typedef CocoaTest AutoFillCreditCardSheetControllerTest;
TEST(AutoFillCreditCardSheetControllerTest, Basic) {
// A basic test that creates a new instance and releases.
// Aids valgrind leak detection.
- CreditCard credit_card(ASCIIToUTF16("myCC"), 0);
+ CreditCard credit_card;
scoped_nsobject<AutoFillCreditCardSheetController> controller(
[[AutoFillCreditCardSheetController alloc]
initWithCreditCard:credit_card
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.h b/chrome/browser/autofill/autofill_dialog_controller_mac.h
index cd5eec1..4ebf2d6 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac.h
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac.h
@@ -160,12 +160,6 @@ class Profile;
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;
-// Creates an array of labels and populates a vector of corresponding IDs
-// representing the addresses and associated billing address IDs in the
-// |profiles_| member.
-// Only returns labels and IDs for which there exists address information.
-- (void)addressLabels:(NSArray**)labels addressIDs:(std::vector<int>*)ids;
-
@end
// Interface exposed for unit testing.
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
index 4d47df1..c1f193c 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
@@ -281,8 +281,7 @@ class PreferenceObserver : public NotificationObserver {
DCHECK(!addressSheetController.get());
// Create a new default address.
- string16 newName = l10n_util::GetStringUTF16(IDS_AUTOFILL_NEW_ADDRESS);
- AutoFillProfile newAddress(newName, 0);
+ AutoFillProfile newAddress;
// Create a new address sheet controller in "Add" mode.
addressSheetController.reset(
@@ -304,8 +303,7 @@ class PreferenceObserver : public NotificationObserver {
DCHECK(!creditCardSheetController.get());
// Create a new default credit card.
- string16 newName = l10n_util::GetStringUTF16(IDS_AUTOFILL_NEW_CREDITCARD);
- CreditCard newCreditCard(newName, 0);
+ CreditCard newCreditCard;
// Create a new address sheet controller in "Add" mode.
creditCardSheetController.reset(
@@ -329,7 +327,7 @@ class PreferenceObserver : public NotificationObserver {
if (returnCode) {
// Create a new address and save it to the |profiles_| list.
- AutoFillProfile newAddress(string16(), 0);
+ AutoFillProfile newAddress;
[addressSheetController copyModelToProfile:&newAddress];
if (!newAddress.IsEmpty()) {
profiles_.push_back(newAddress);
@@ -356,7 +354,7 @@ class PreferenceObserver : public NotificationObserver {
if (returnCode) {
// Create a new credit card and save it to the |creditCards_| list.
- CreditCard newCreditCard(string16(), 0);
+ CreditCard newCreditCard;
[creditCardSheetController copyModelToCreditCard:&newCreditCard];
if (!newCreditCard.IsEmpty()) {
creditCards_.push_back(newCreditCard);
@@ -603,33 +601,6 @@ class PreferenceObserver : public NotificationObserver {
return 0;
}
-- (void)addressLabels:(NSArray**)labels addressIDs:(std::vector<int>*)ids {
- NSUInteger capacity = profiles_.size();
- NSMutableArray* array = [NSMutableArray arrayWithCapacity:capacity];
- ids->clear();
-
- std::vector<AutoFillProfile>::iterator i;
- for (i = profiles_.begin(); i != profiles_.end(); ++i) {
- FieldTypeSet fields;
- i->GetAvailableFieldTypes(&fields);
- if (fields.find(ADDRESS_HOME_LINE1) == fields.end() &&
- fields.find(ADDRESS_HOME_LINE2) == fields.end() &&
- fields.find(ADDRESS_HOME_APT_NUM) == fields.end() &&
- fields.find(ADDRESS_HOME_CITY) == fields.end() &&
- fields.find(ADDRESS_HOME_STATE) == fields.end() &&
- fields.find(ADDRESS_HOME_ZIP) == fields.end() &&
- fields.find(ADDRESS_HOME_COUNTRY) == fields.end()) {
- // No address information in this profile; it's useless as a billing
- // address.
- continue;
- }
- [array addObject:SysUTF16ToNSString(i->Label())];
- ids->push_back(i->unique_id());
- }
-
- *labels = array;
-}
-
// Accessor for |autoFillEnabled| preference state. Note: a checkbox in Nib
// is bound to this via KVO.
- (BOOL)autoFillEnabled {
@@ -917,7 +888,7 @@ class PreferenceObserver : public NotificationObserver {
// TODO(dhollowa): Using SetInfo() call to validate phone number. Should
// have explicit validation method. More robust validation is needed as
// well eventually.
- AutoFillProfile profile(string16(), 0);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER),
base::SysNSStringToUTF16(string));
if (profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
index 0e6eeab..a3359db 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
@@ -191,7 +191,7 @@ TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverProfiles) {
}
TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverCreditCards) {
- CreditCard credit_card(ASCIIToUTF16("myCC"), 345);
+ CreditCard credit_card;
credit_cards().push_back(&credit_card);
LoadDialog();
[controller_ closeDialog];
@@ -204,7 +204,7 @@ TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverCreditCards) {
}
TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
- AutoFillProfile profile(ASCIIToUTF16("Home"), 17);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John"));
profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("C"));
profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith"));
@@ -249,15 +249,11 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
ASSERT_TRUE(observer_.hit_);
ASSERT_TRUE(observer_.profiles_.size() == 1);
- profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id());
- // Do not compare labels. Label is a derived field.
- observer_.profiles_[0].set_label(string16());
- profiles()[0]->set_label(string16());
- ASSERT_EQ(observer_.profiles_[0], *profiles()[0]);
+ ASSERT_EQ(0, observer_.profiles_[0].Compare(*profiles()[0]));
}
TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
- CreditCard credit_card(ASCIIToUTF16("myCC"), 345);
+ CreditCard credit_card;
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("DCH"));
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER),
ASCIIToUTF16("1234 5678 9101 1121"));
@@ -289,17 +285,14 @@ TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
ASSERT_TRUE(observer_.hit_);
ASSERT_TRUE(observer_.credit_cards_.size() == 1);
-
- // Don't compare unique ids.
- credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
- ASSERT_EQ(observer_.credit_cards_[0], *credit_cards()[0]);
+ ASSERT_EQ(0, observer_.credit_cards_[0].Compare(*credit_cards()[0]));
}
TEST_F(AutoFillDialogControllerTest, TwoProfiles) {
- AutoFillProfile profile1(ASCIIToUTF16("One"), 1);
+ AutoFillProfile profile1;
profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
profiles().push_back(&profile1);
- AutoFillProfile profile2(ASCIIToUTF16("Two"), 2);
+ AutoFillProfile profile2;
profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
profiles().push_back(&profile2);
LoadDialog();
@@ -314,20 +307,15 @@ TEST_F(AutoFillDialogControllerTest, TwoProfiles) {
// 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([controller_ profiles][i].unique_id());
-
- // Do not compare labels. Label is a derived field.
- [controller_ profiles][i].set_label(string16());
- profiles()[i]->set_label(string16());
- ASSERT_EQ([controller_ profiles][i], *profiles()[i]);
+ ASSERT_EQ(0, [controller_ profiles][i].Compare(*profiles()[i]));
}
}
TEST_F(AutoFillDialogControllerTest, TwoCreditCards) {
- CreditCard credit_card1(ASCIIToUTF16("Visa"), 1);
+ CreditCard credit_card1;
credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
credit_cards().push_back(&credit_card1);
- CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2);
+ CreditCard credit_card2;
credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
credit_cards().push_back(&credit_card2);
LoadDialog();
@@ -342,13 +330,12 @@ TEST_F(AutoFillDialogControllerTest, TwoCreditCards) {
// 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([controller_ creditCards][i].unique_id());
- ASSERT_EQ([controller_ creditCards][i], *credit_cards()[i]);
+ ASSERT_EQ(0, [controller_ creditCards][i].Compare(*credit_cards()[i]));
}
}
TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
- AutoFillProfile profile(ASCIIToUTF16("One"), 1);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
profiles().push_back(&profile);
LoadDialog();
@@ -376,7 +363,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
}
TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
- CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
+ CreditCard credit_card;
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
credit_cards().push_back(&credit_card);
LoadDialog();
@@ -405,7 +392,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
}
TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) {
- AutoFillProfile profile(string16(), 1);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
profiles().push_back(&profile);
LoadDialog();
@@ -423,7 +410,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) {
}
TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) {
- CreditCard credit_card(string16(), 1);
+ CreditCard credit_card;
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
credit_cards().push_back(&credit_card);
LoadDialog();
@@ -442,7 +429,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) {
}
TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
- AutoFillProfile profile(ASCIIToUTF16("One"), 1);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
profiles().push_back(&profile);
LoadDialog();
@@ -459,7 +446,7 @@ TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
}
TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) {
- CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
+ CreditCard credit_card;
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
credit_cards().push_back(&credit_card);
LoadDialog();
@@ -476,10 +463,10 @@ TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) {
}
TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) {
- AutoFillProfile profile(ASCIIToUTF16("One"), 1);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
profiles().push_back(&profile);
- AutoFillProfile profile2(ASCIIToUTF16("Two"), 2);
+ AutoFillProfile profile2;
profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
profiles().push_back(&profile2);
LoadDialog();
@@ -493,21 +480,14 @@ TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) {
// Sizes should be different. New size should be 1.
ASSERT_NE(observer_.profiles_.size(), profiles().size());
ASSERT_EQ(observer_.profiles_.size(), 1UL);
-
- // First address should match.
- profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id());
-
- // Do not compare labels. Label is a derived field.
- observer_.profiles_[0].set_label(string16());
- profile.set_label(string16());
- ASSERT_EQ(observer_.profiles_[0], profile);
+ ASSERT_EQ(0, observer_.profiles_[0].Compare(profile));
}
TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) {
- CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
+ CreditCard credit_card;
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
credit_cards().push_back(&credit_card);
- CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2);
+ CreditCard credit_card2;
credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
credit_cards().push_back(&credit_card2);
LoadDialog();
@@ -523,22 +503,21 @@ TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) {
ASSERT_EQ(observer_.credit_cards_.size(), 1UL);
// First credit card should match.
- credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
- ASSERT_EQ(observer_.credit_cards_[0], credit_card);
+ ASSERT_EQ(0, observer_.credit_cards_[0].Compare(credit_card));
}
TEST_F(AutoFillDialogControllerTest, DeleteMultiple) {
- AutoFillProfile profile(ASCIIToUTF16("One"), 1);
+ AutoFillProfile profile;
profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
profiles().push_back(&profile);
- AutoFillProfile profile2(ASCIIToUTF16("Two"), 2);
+ AutoFillProfile profile2;
profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
profiles().push_back(&profile2);
- CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
+ CreditCard credit_card;
credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
credit_cards().push_back(&credit_card);
- CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2);
+ CreditCard credit_card2;
credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
credit_cards().push_back(&credit_card2);
@@ -562,17 +541,11 @@ TEST_F(AutoFillDialogControllerTest, DeleteMultiple) {
ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size());
ASSERT_EQ(observer_.credit_cards_.size(), 1UL);
- // First address should match.
- profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id());
-
- // Do not compare labels. Label is a derived field.
- observer_.profiles_[0].set_label(string16());
- profile.set_label(string16());
- ASSERT_EQ(observer_.profiles_[0], profile);
+ // Profiles should match.
+ ASSERT_EQ(0, observer_.profiles_[0].Compare(profile));
// Second credit card should match.
- credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
- ASSERT_EQ(observer_.credit_cards_[0], credit_card2);
+ ASSERT_EQ(0, observer_.credit_cards_[0].Compare(credit_card2));
}
// Auxilliary profiles are enabled by default.
@@ -618,9 +591,9 @@ TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesChanged) {
}
TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) {
- AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
+ AutoFillProfile profile;
profiles().push_back(&profile);
- CreditCard credit_card(ASCIIToUTF16("Visa"), 0);
+ CreditCard credit_card;
credit_cards().push_back(&credit_card);
helper_.test_profile_->test_manager_->test_data_is_loaded_ = false;
LoadDialog();
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc
index c26af93..76ac13c 100644
--- a/chrome/browser/autofill/autofill_profile.cc
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -171,7 +171,7 @@ FormGroup* AutoFillProfile::Clone() const {
return profile;
}
-const string16& AutoFillProfile::Label() const {
+const string16 AutoFillProfile::Label() const {
return label_;
}
@@ -398,34 +398,10 @@ int AutoFillProfile::Compare(const AutoFillProfile& profile) const {
}
bool AutoFillProfile::operator==(const AutoFillProfile& profile) const {
- // The following AutoFill field types are the only types we store in the WebDB
- // so far, so we're only concerned with matching these types in the profile.
- const AutoFillFieldType types[] = { NAME_FIRST,
- NAME_MIDDLE,
- NAME_LAST,
- EMAIL_ADDRESS,
- COMPANY_NAME,
- ADDRESS_HOME_LINE1,
- ADDRESS_HOME_LINE2,
- ADDRESS_HOME_CITY,
- ADDRESS_HOME_STATE,
- ADDRESS_HOME_ZIP,
- ADDRESS_HOME_COUNTRY,
- PHONE_HOME_NUMBER,
- PHONE_FAX_NUMBER };
-
- if (label_ != profile.label_ ||
- unique_id_ != profile.unique_id_) {
+ if (label_ != profile.label_ || unique_id_ != profile.unique_id_)
return false;
- }
-
- for (size_t index = 0; index < arraysize(types); ++index) {
- if (GetFieldText(AutoFillType(types[index])) !=
- profile.GetFieldText(AutoFillType(types[index])))
- return false;
- }
- return true;
+ return Compare(profile) == 0;
}
bool AutoFillProfile::operator!=(const AutoFillProfile& profile) const {
diff --git a/chrome/browser/autofill/autofill_profile.h b/chrome/browser/autofill/autofill_profile.h
index cff668c..91b08fe 100644
--- a/chrome/browser/autofill/autofill_profile.h
+++ b/chrome/browser/autofill/autofill_profile.h
@@ -49,7 +49,7 @@ class AutoFillProfile : public FormGroup {
// The user-visible label of the profile, generated in relation to other
// profiles. Shows at least 2 fields that differentiate profile from other
// profiles. See AdjustInferredLabels() further down for more description.
- virtual const string16& Label() const;
+ virtual const string16 Label() const;
int unique_id() const { return unique_id_; }
void set_unique_id(int id) { unique_id_ = id; }
@@ -91,7 +91,8 @@ class AutoFillProfile : public FormGroup {
// Comparison for Sync. Returns 0 if the profile is the same as |this|,
// or < 0, or > 0 if it is different. The implied ordering can be used for
- // culling duplicates.
+ // culling duplicates. The ordering is based on collation order of the
+ // textual contents of the fields.
// GUIDs, labels, and unique IDs are not compared, only the values of the
// profiles themselves.
int Compare(const AutoFillProfile& profile) const;
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc
index 67382b7..5fe1e38 100644
--- a/chrome/browser/autofill/credit_card.cc
+++ b/chrome/browser/autofill/credit_card.cc
@@ -35,14 +35,14 @@ const int kAutoFillCreditCardLength = arraysize(kAutoFillCreditCardTypes);
// These values must match the values in WebKitClientImpl in webkit/glue. We
// send these strings to WK, which then asks WebKitClientImpl to load the image
// data.
-const char* kAmericanExpressCard = "americanExpressCC";
-const char* kDinersCard = "dinersCC";
-const char* kDiscoverCard = "discoverCC";
-const char* kGenericCard = "genericCC";
-const char* kJCBCard = "jcbCC";
-const char* kMasterCard = "masterCardCC";
-const char* kSoloCard = "soloCC";
-const char* kVisaCard = "visaCC";
+const char* const kAmericanExpressCard = "americanExpressCC";
+const char* const kDinersCard = "dinersCC";
+const char* const kDiscoverCard = "discoverCC";
+const char* const kGenericCard = "genericCC";
+const char* const kJCBCard = "jcbCC";
+const char* const kMasterCard = "masterCardCC";
+const char* const kSoloCard = "soloCC";
+const char* const kVisaCard = "visaCC";
std::string GetCreditCardType(const string16& number) {
// Credit card number specifications taken from:
@@ -149,8 +149,8 @@ CreditCard::CreditCard()
guid_(guid::GenerateGUID()) {
}
-CreditCard::CreditCard(const CreditCard& card) : FormGroup() {
- operator=(card);
+CreditCard::CreditCard(const CreditCard& credit_card) : FormGroup() {
+ operator=(credit_card);
}
CreditCard::~CreditCard() {}
@@ -372,43 +372,45 @@ string16 CreditCard::LastFourDigits() const {
return number().substr(number().size() - kNumLastDigits, kNumLastDigits);
}
-void CreditCard::operator=(const CreditCard& source) {
- number_ = source.number_;
- name_on_card_ = source.name_on_card_;
- type_ = source.type_;
- last_four_digits_ = source.last_four_digits_;
- expiration_month_ = source.expiration_month_;
- expiration_year_ = source.expiration_year_;
- label_ = source.label_;
- unique_id_ = source.unique_id_;
- guid_ = source.guid_;
+void CreditCard::operator=(const CreditCard& credit_card) {
+ number_ = credit_card.number_;
+ name_on_card_ = credit_card.name_on_card_;
+ type_ = credit_card.type_;
+ last_four_digits_ = credit_card.last_four_digits_;
+ expiration_month_ = credit_card.expiration_month_;
+ expiration_year_ = credit_card.expiration_year_;
+ label_ = credit_card.label_;
+ unique_id_ = credit_card.unique_id_;
+ guid_ = credit_card.guid_;
}
-bool CreditCard::operator==(const CreditCard& creditcard) const {
+int CreditCard::Compare(const CreditCard& credit_card) const {
// The following CreditCard field types are the only types we store in the
// WebDB so far, so we're only concerned with matching these types in the
- // profile.
+ // credit card.
const AutoFillFieldType types[] = { CREDIT_CARD_NAME,
- CREDIT_CARD_TYPE,
CREDIT_CARD_NUMBER,
CREDIT_CARD_EXP_MONTH,
CREDIT_CARD_EXP_4_DIGIT_YEAR };
-
- if ((label_ != creditcard.label_) || (unique_id_ != creditcard.unique_id_)) {
- return false;
- }
-
for (size_t index = 0; index < arraysize(types); ++index) {
- if (GetFieldText(AutoFillType(types[index])) !=
- creditcard.GetFieldText(AutoFillType(types[index])))
- return false;
+ int comparison = GetFieldText(AutoFillType(types[index])).compare(
+ credit_card.GetFieldText(AutoFillType(types[index])));
+ if (comparison != 0)
+ return comparison;
}
- return true;
+ return 0;
}
-bool CreditCard::operator!=(const CreditCard& creditcard) const {
- return !operator==(creditcard);
+bool CreditCard::operator==(const CreditCard& credit_card) const {
+ if (label_ != credit_card.label_ || unique_id_ != credit_card.unique_id_)
+ return false;
+
+ return Compare(credit_card) == 0;
+}
+
+bool CreditCard::operator!=(const CreditCard& credit_card) const {
+ return !operator==(credit_card);
}
// Use the Luhn formula to validate the number.
@@ -443,7 +445,6 @@ bool CreditCard::IsEmpty() const {
return types.empty();
}
-
string16 CreditCard::ExpirationMonthAsString() const {
if (expiration_month_ == 0)
return string16();
@@ -610,23 +611,23 @@ bool CreditCard::ConvertDate(const string16& date, int* num) const {
}
// So we can compare CreditCards with EXPECT_EQ().
-std::ostream& operator<<(std::ostream& os, const CreditCard& creditcard) {
+std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) {
return os
- << UTF16ToUTF8(creditcard.Label())
+ << UTF16ToUTF8(credit_card.Label())
<< " "
- << creditcard.unique_id()
+ << credit_card.unique_id()
<< " "
- << creditcard.guid()
+ << credit_card.guid()
<< " "
- << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NAME)))
+ << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME)))
<< " "
- << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)))
+ << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)))
<< " "
- << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)))
+ << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)))
<< " "
- << UTF16ToUTF8(creditcard.GetFieldText(
+ << UTF16ToUTF8(credit_card.GetFieldText(
AutoFillType(CREDIT_CARD_EXP_MONTH)))
<< " "
- << UTF16ToUTF8(creditcard.GetFieldText(
+ << UTF16ToUTF8(credit_card.GetFieldText(
AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)));
}
diff --git a/chrome/browser/autofill/credit_card.h b/chrome/browser/autofill/credit_card.h
index 67bfa2f..be7579f 100644
--- a/chrome/browser/autofill/credit_card.h
+++ b/chrome/browser/autofill/credit_card.h
@@ -21,7 +21,7 @@ class CreditCard : public FormGroup {
// For use in STL containers.
CreditCard();
- CreditCard(const CreditCard& card);
+ CreditCard(const CreditCard& credit_card);
virtual ~CreditCard();
// FormGroup implementation:
@@ -35,7 +35,7 @@ class CreditCard : public FormGroup {
virtual string16 GetFieldText(const AutoFillType& type) const;
virtual string16 GetPreviewText(const AutoFillType& type) const;
virtual void SetInfo(const AutoFillType& type, const string16& value);
- const string16& Label() const { return label_; }
+ virtual const string16 Label() const { return label_; }
// The number altered for display, for example: ******1234
string16 ObfuscatedNumber() const;
@@ -54,11 +54,19 @@ class CreditCard : public FormGroup {
void set_guid(const std::string& guid) { guid_ = guid; }
// For use in STL containers.
- void operator=(const CreditCard&);
+ void operator=(const CreditCard& credit_card);
+
+ // Comparison for Sync. Returns 0 if the credit card is the same as |this|,
+ // or < 0, or > 0 if it is different. The implied ordering can be used for
+ // culling duplicates. The ordering is based on collation order of the
+ // textual contents of the fields.
+ // GUIDs, labels, and unique IDs are not compared, only the values of the
+ // credit cards themselves.
+ int Compare(const CreditCard& credit_card) const;
// Used by tests.
- bool operator==(const CreditCard& creditcard) const;
- bool operator!=(const CreditCard& creditcard) const;
+ bool operator==(const CreditCard& credit_card) const;
+ bool operator!=(const CreditCard& credit_card) const;
void set_label(const string16& label) { label_ = label; }
// Returns true if |value| is a credit card number. Uses the Luhn formula to
@@ -149,6 +157,6 @@ class CreditCard : public FormGroup {
};
// So we can compare CreditCards with EXPECT_EQ().
-std::ostream& operator<<(std::ostream& os, const CreditCard& creditcard);
+std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card);
#endif // CHROME_BROWSER_AUTOFILL_CREDIT_CARD_H_
diff --git a/chrome/browser/autofill/form_group.cc b/chrome/browser/autofill/form_group.cc
index e99059b..7e91bc3 100644
--- a/chrome/browser/autofill/form_group.cc
+++ b/chrome/browser/autofill/form_group.cc
@@ -8,7 +8,7 @@ string16 FormGroup::GetPreviewText(const AutoFillType& type) const {
return GetFieldText(type);
}
-const string16& FormGroup::Label() const { return EmptyString16(); }
+const string16 FormGroup::Label() const { return string16(); }
bool FormGroup::operator!=(const FormGroup& form_group) const {
FieldTypeSet a, b, symmetric_difference;
diff --git a/chrome/browser/autofill/form_group.h b/chrome/browser/autofill/form_group.h
index 68a7d3a..5f16276 100644
--- a/chrome/browser/autofill/form_group.h
+++ b/chrome/browser/autofill/form_group.h
@@ -53,7 +53,7 @@ class FormGroup {
// Returns the label for this FormGroup item. This should be overridden for
// form group items that implement a label.
- virtual const string16& Label() const;
+ virtual const string16 Label() const;
// Returns true if the field data in |form_group| does not match the field
// data in this FormGroup.