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

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: better way 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
« no previous file with comments | « components/autofill/core/browser/phone_number_i18n_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), 97 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
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 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
108 ASCIIToUTF16("+18887776666"),
109 "US"));
110 EXPECT_EQ(ASCIIToUTF16("+1 888-777-6666"),
111 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
107 112
108 // Differently formatted numbers should be re-formatted. 113 // Differently formatted numbers should be left alone.
109 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), 114 EXPECT_TRUE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
110 ASCIIToUTF16("800-432-8765"), "US")); 115 ASCIIToUTF16("800-432-8765"), "US"));
111 EXPECT_EQ(ASCIIToUTF16("(800) 432-8765"), 116 EXPECT_EQ(ASCIIToUTF16("800-432-8765"),
117 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
118
119 // SetRawInfo should not try to format.
120 phone.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("8004328765"));
121 EXPECT_EQ(ASCIIToUTF16("8004328765"),
112 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 122 phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
113 123
114 // Invalid numbers should not be stored. In the US, phone numbers cannot 124 // Invalid numbers should not be stored. In the US, phone numbers cannot
115 // start with the digit '1'. 125 // start with the digit '1'.
116 EXPECT_FALSE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), 126 EXPECT_FALSE(phone.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER),
117 ASCIIToUTF16("650111111"), "US")); 127 ASCIIToUTF16("650111111"), "US"));
118 EXPECT_EQ(base::string16(), phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 128 EXPECT_EQ(base::string16(), phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
119 } 129 }
120 130
121 // Test that cached phone numbers are correctly invalidated and updated. 131 // 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"))); 215 ASCIIToUTF16("650")));
206 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER), 216 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER),
207 ASCIIToUTF16("234"))); 217 ASCIIToUTF16("234")));
208 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER), 218 EXPECT_TRUE(number7.SetInfo(AutofillType(PHONE_HOME_NUMBER),
209 ASCIIToUTF16("5682"))); 219 ASCIIToUTF16("5682")));
210 EXPECT_TRUE(number7.ParseNumber(AutofillProfile(), "en-US", &parsed_phone)); 220 EXPECT_TRUE(number7.ParseNumber(AutofillProfile(), "en-US", &parsed_phone));
211 EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone); 221 EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone);
212 } 222 }
213 223
214 } // namespace autofill 224 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/phone_number_i18n_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698