summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-07 05:57:34 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-07 05:57:34 +0000
commit1ea7f9f632c1d5e523a066d37dffb55f617f621b (patch)
tree5835c9207222dccefda34392c6236863a6849f6a /chrome
parent19fe26da9f6361e4f686817ed4881969cdc3f9ac (diff)
downloadchromium_src-1ea7f9f632c1d5e523a066d37dffb55f617f621b.zip
chromium_src-1ea7f9f632c1d5e523a066d37dffb55f617f621b.tar.gz
chromium_src-1ea7f9f632c1d5e523a066d37dffb55f617f621b.tar.bz2
AutoFillProfile: Don't clobber data on self-assignment
BUG=none TEST=unit_test --gtest_filter=AutoFillProfileTest.AssignmentOperator:CreditCardTest.AssignmentOperator Review URL: http://codereview.chromium.org/5521005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68449 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/autofill_profile.cc3
-rw-r--r--chrome/browser/autofill/autofill_profile_unittest.cc16
-rw-r--r--chrome/browser/autofill/credit_card.cc3
-rw-r--r--chrome/browser/autofill/credit_card_unittest.cc14
4 files changed, 36 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc
index 40a749b..b269865 100644
--- a/chrome/browser/autofill/autofill_profile.cc
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -379,6 +379,9 @@ bool AutoFillProfile::IsEmpty() const {
}
void AutoFillProfile::operator=(const AutoFillProfile& source) {
+ if (this == &source)
+ return;
+
label_ = source.label_;
guid_ = source.guid_;
diff --git a/chrome/browser/autofill/autofill_profile_unittest.cc b/chrome/browser/autofill/autofill_profile_unittest.cc
index 3c500a3..033fa57 100644
--- a/chrome/browser/autofill/autofill_profile_unittest.cc
+++ b/chrome/browser/autofill/autofill_profile_unittest.cc
@@ -495,6 +495,22 @@ TEST(AutoFillProfileTest, MergeWith) {
EXPECT_EQ(0, expected_b.Compare(*b));
}
+TEST(AutoFillProfileTest, AssignmentOperator){
+ AutoFillProfile a, b;
+
+ // Result of assignment should be logically equal to the original profile.
+ autofill_test::SetProfileInfo(&a, "Billing", "Marion", "Mitchell", "Morrison",
+ "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
+ "Hollywood", "CA", "91601", "US", "12345678910",
+ "01987654321");
+ b = a;
+ EXPECT_TRUE(a == b);
+
+ // Assignment to self should not change the profile value.
+ a = a;
+ EXPECT_TRUE(a == b);
+}
+
TEST(AutoFillProfileTest, Compare) {
AutoFillProfile a, b;
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc
index b85e538..1cd0c13 100644
--- a/chrome/browser/autofill/credit_card.cc
+++ b/chrome/browser/autofill/credit_card.cc
@@ -375,6 +375,9 @@ string16 CreditCard::LastFourDigits() const {
}
void CreditCard::operator=(const CreditCard& credit_card) {
+ if (this == &credit_card)
+ return;
+
number_ = credit_card.number_;
name_on_card_ = credit_card.name_on_card_;
type_ = credit_card.type_;
diff --git a/chrome/browser/autofill/credit_card_unittest.cc b/chrome/browser/autofill/credit_card_unittest.cc
index 507379b..89e73d7 100644
--- a/chrome/browser/autofill/credit_card_unittest.cc
+++ b/chrome/browser/autofill/credit_card_unittest.cc
@@ -67,5 +67,19 @@ TEST(CreditCardTest, PreviewSummaryAndObfuscatedNumberStrings) {
EXPECT_EQ(string16(ASCIIToUTF16("************9012")), obfuscated4);
}
+TEST(CreditCardTest, AssignmentOperator){
+ CreditCard a, b;
+
+ // Result of assignment should be logically equal to the original profile.
+ autofill_test::SetCreditCardInfo(&a, "Corporate", "John Dillinger",
+ "123456789012", "01", "2010");
+ b = a;
+ EXPECT_TRUE(a == b);
+
+ // Assignment to self should not change the profile value.
+ a = a;
+ EXPECT_TRUE(a == b);
+}
+
} // namespace