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

Side by Side Diff: components/autofill/core/browser/phone_number_unittest.cc

Issue 374053007: Change PhoneNumber::SetInfo to only apply formatting where there is none (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/string16.h" 5 #include "base/strings/string16.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "components/autofill/core/browser/autofill_profile.h" 7 #include "components/autofill/core/browser/autofill_profile.h"
8 #include "components/autofill/core/browser/autofill_type.h" 8 #include "components/autofill/core/browser/autofill_type.h"
9 #include "components/autofill/core/browser/field_types.h" 9 #include "components/autofill/core/browser/field_types.h"
10 #include "components/autofill/core/browser/phone_number.h" 10 #include "components/autofill/core/browser/phone_number.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ASCIIToUTF16("(650) 234-5678"), "US")); 98 ASCIIToUTF16("(650) 234-5678"), "US"));
99 EXPECT_EQ(ASCIIToUTF16("(650) 234-5678"), 99 EXPECT_EQ(ASCIIToUTF16("(650) 234-5678"),
100 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 100 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
101 101
102 // Unformatted numbers should be formatted. 102 // Unformatted numbers should be formatted.
103 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), 103 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
104 ASCIIToUTF16("8887776666"), "US")); 104 ASCIIToUTF16("8887776666"), "US"));
105 EXPECT_EQ(ASCIIToUTF16("(888) 777-6666"), 105 EXPECT_EQ(ASCIIToUTF16("(888) 777-6666"),
106 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 106 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
107 107
108 // Differently formatted numbers should be re-formatted. 108 // Differently formatted numbers should be left alone.
109 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), 109 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
110 ASCIIToUTF16("800-432-8765"), "US")); 110 ASCIIToUTF16("800-432-8765"), "US"));
111 EXPECT_EQ(ASCIIToUTF16("(800) 432-8765"), 111 EXPECT_EQ(ASCIIToUTF16("800-432-8765"),
112 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
113
114 // SetRawInfo should not try to format.
115 phone.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("8004328765"));
116 EXPECT_EQ(ASCIIToUTF16("8004328765"),
112 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 117 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
113 118
114 // Invalid numbers should not be stored. In the US, phone numbers cannot 119 // Invalid numbers should not be stored. In the US, phone numbers cannot
115 // start with the digit '1'. 120 // start with the digit '1'.
116 EXPECT_FALSE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), 121 EXPECT_FALSE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
117 ASCIIToUTF16("650111111"), "US")); 122 ASCIIToUTF16("650111111"), "US"));
118 EXPECT_EQ(base::string16(), phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 123 EXPECT_EQ(base::string16(), phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
119 } 124 }
120 125
121 // Test that cached phone numbers are correctly invalidated and updated. 126 // Test that cached phone numbers are correctly invalidated and updated.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ASCIIToUTF16("650"))); 210 ASCIIToUTF16("650")));
206 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER), 211 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER),
207 ASCIIToUTF16("234"))); 212 ASCIIToUTF16("234")));
208 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER), 213 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER),
209 ASCIIToUTF16("5682"))); 214 ASCIIToUTF16("5682")));
210 EXPECT_TRUE(number7.ParseNumber(AutofillProfile(), "en-US", &parsed_phone)); 215 EXPECT_TRUE(number7.ParseNumber(AutofillProfile(), "en-US", &parsed_phone));
211 EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone); 216 EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone);
212 } 217 }
213 218
214 } // namespace autofill 219 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698