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

Side by Side Diff: chrome/browser/autofill/address_unittest.cc

Issue 11635039: [Autofill] Update unit tests to use country codes when setting raw address info. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | « no previous file | chrome/browser/autofill/autofill_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autofill/address.h" 10 #include "chrome/browser/autofill/address.h"
(...skipping 27 matching lines...) Expand all
38 address.set_country_code("CA"); 38 address.set_country_code("CA");
39 EXPECT_EQ("CA", address.country_code()); 39 EXPECT_EQ("CA", address.country_code());
40 } 40 }
41 41
42 // Test that country codes are properly decoded as country names. 42 // Test that country codes are properly decoded as country names.
43 TEST_F(AddressTest, GetCountry) { 43 TEST_F(AddressTest, GetCountry) {
44 Address address; 44 Address address;
45 EXPECT_EQ(std::string(), address.country_code()); 45 EXPECT_EQ(std::string(), address.country_code());
46 46
47 // Make sure that nothing breaks when the country code is missing. 47 // Make sure that nothing breaks when the country code is missing.
48 string16 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 48 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
49 EXPECT_EQ(string16(), country); 49 EXPECT_EQ(string16(), country);
50 50
51 address.set_country_code("US"); 51 address.set_country_code("US");
52 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 52 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
53 EXPECT_EQ(ASCIIToUTF16("United States"), country); 53 EXPECT_EQ(ASCIIToUTF16("United States"), country);
54 54
55 address.set_country_code("CA"); 55 address.set_country_code("CA");
56 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 56 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
57 EXPECT_EQ(ASCIIToUTF16("Canada"), country); 57 EXPECT_EQ(ASCIIToUTF16("Canada"), country);
58 } 58 }
59 59
60 // Test that we properly detect country codes appropriate for each country. 60 // Test that we properly detect country codes appropriate for each country.
61 TEST_F(AddressTest, SetCountry) { 61 TEST_F(AddressTest, SetCountry) {
62 Address address; 62 Address address;
63 EXPECT_EQ(std::string(), address.country_code()); 63 EXPECT_EQ(std::string(), address.country_code());
64 64
65 // Test basic conversion. 65 // Test basic conversion.
66 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); 66 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"), "en-US");
67 string16 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 67 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
68 EXPECT_EQ("US", address.country_code()); 68 EXPECT_EQ("US", address.country_code());
69 EXPECT_EQ(ASCIIToUTF16("United States"), country); 69 EXPECT_EQ(ASCIIToUTF16("United States"), country);
70 70
71 // Test basic synonym detection. 71 // Test basic synonym detection.
72 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("USA")); 72 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("USA"), "en-US");
73 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 73 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
74 EXPECT_EQ("US", address.country_code()); 74 EXPECT_EQ("US", address.country_code());
75 EXPECT_EQ(ASCIIToUTF16("United States"), country); 75 EXPECT_EQ(ASCIIToUTF16("United States"), country);
76 76
77 // Test case-insensitivity. 77 // Test case-insensitivity.
78 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("canADA")); 78 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("canADA"), "en-US");
79 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 79 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
80 EXPECT_EQ("CA", address.country_code()); 80 EXPECT_EQ("CA", address.country_code());
81 EXPECT_EQ(ASCIIToUTF16("Canada"), country); 81 EXPECT_EQ(ASCIIToUTF16("Canada"), country);
82 82
83 // Test country code detection. 83 // Test country code detection.
84 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP")); 84 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP"), "en-US");
85 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 85 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
86 EXPECT_EQ("JP", address.country_code()); 86 EXPECT_EQ("JP", address.country_code());
87 EXPECT_EQ(ASCIIToUTF16("Japan"), country); 87 EXPECT_EQ(ASCIIToUTF16("Japan"), country);
88 88
89 // Test that we ignore unknown countries. 89 // Test that we ignore unknown countries.
90 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown")); 90 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown"), "en-US");
91 country = address.GetRawInfo(ADDRESS_HOME_COUNTRY); 91 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US");
92 EXPECT_EQ(std::string(), address.country_code()); 92 EXPECT_EQ(std::string(), address.country_code());
93 EXPECT_EQ(string16(), country); 93 EXPECT_EQ(string16(), country);
94 } 94 }
95 95
96 // Test that we properly match typed values to stored country data. 96 // Test that we properly match typed values to stored country data.
97 TEST_F(AddressTest, IsCountry) { 97 TEST_F(AddressTest, IsCountry) {
98 Address address; 98 Address address;
99 address.set_country_code("US"); 99 address.set_country_code("US");
100 100
101 const char* const kValidMatches[] = { 101 const char* const kValidMatches[] = {
(...skipping 23 matching lines...) Expand all
125 EXPECT_EQ(0U, matching_types.size()); 125 EXPECT_EQ(0U, matching_types.size());
126 } 126 }
127 127
128 // Make sure that garbage values don't match when the country code is empty. 128 // Make sure that garbage values don't match when the country code is empty.
129 address.set_country_code(""); 129 address.set_country_code("");
130 EXPECT_EQ(std::string(), address.country_code()); 130 EXPECT_EQ(std::string(), address.country_code());
131 FieldTypeSet matching_types; 131 FieldTypeSet matching_types;
132 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types); 132 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types);
133 EXPECT_EQ(0U, matching_types.size()); 133 EXPECT_EQ(0U, matching_types.size());
134 } 134 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698