Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/string16.h" | 7 #include "base/string16.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autofill/address.h" | 9 #include "chrome/browser/autofill/address.h" |
| 10 #include "chrome/browser/autofill/autofill_type.h" | 10 #include "chrome/browser/autofill/autofill_type.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 address.set_country_code("CA"); | 21 address.set_country_code("CA"); |
| 22 EXPECT_EQ("CA", address.country_code()); | 22 EXPECT_EQ("CA", address.country_code()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Test that country codes are properly decoded as country names. | 25 // Test that country codes are properly decoded as country names. |
| 26 TEST(AddressTest, GetCountry) { | 26 TEST(AddressTest, GetCountry) { |
| 27 Address address; | 27 Address address; |
| 28 EXPECT_EQ(std::string(), address.country_code()); | 28 EXPECT_EQ(std::string(), address.country_code()); |
| 29 | 29 |
| 30 // Make sure that nothing breaks when the country code is missing. | 30 // Make sure that nothing breaks when the country code is missing. |
| 31 string16 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 31 string16 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 32 EXPECT_EQ(string16(), country); | 32 EXPECT_EQ(string16(), country); |
| 33 | 33 |
| 34 address.set_country_code("US"); | 34 address.set_country_code("US"); |
| 35 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 35 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 36 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 36 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 37 | 37 |
| 38 address.set_country_code("CA"); | 38 address.set_country_code("CA"); |
| 39 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 39 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 40 EXPECT_EQ(ASCIIToUTF16("Canada"), country); | 40 EXPECT_EQ(ASCIIToUTF16("Canada"), country); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Test that we properly detect country codes appropriate for each country. | 43 // Test that we properly detect country codes appropriate for each country. |
| 44 TEST(AddressTest, SetCountry) { | 44 TEST(AddressTest, SetCountry) { |
| 45 Address address; | 45 Address address; |
| 46 EXPECT_EQ(std::string(), address.country_code()); | 46 EXPECT_EQ(std::string(), address.country_code()); |
| 47 | 47 |
| 48 // Test basic conversion. | 48 // Test basic conversion. |
| 49 address.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | 49 address.SetInfo(ADDRESS_HOME_COUNTRY, |
| 50 ASCIIToUTF16("United States")); | 50 ASCIIToUTF16("United States")); |
|
dhollowa
2011/03/16 17:07:11
nit: indent.
Ilya Sherman
2011/03/17 03:42:29
Done.
| |
| 51 string16 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 51 string16 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 52 EXPECT_EQ("US", address.country_code()); | 52 EXPECT_EQ("US", address.country_code()); |
| 53 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 53 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 54 | 54 |
| 55 // Test basic synonym detection. | 55 // Test basic synonym detection. |
| 56 address.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA")); | 56 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("USA")); |
| 57 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 57 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 58 EXPECT_EQ("US", address.country_code()); | 58 EXPECT_EQ("US", address.country_code()); |
| 59 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 59 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 60 | 60 |
| 61 // Test case-insensitivity. | 61 // Test case-insensitivity. |
| 62 address.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("canADA")); | 62 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("canADA")); |
| 63 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 63 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 64 EXPECT_EQ("CA", address.country_code()); | 64 EXPECT_EQ("CA", address.country_code()); |
| 65 EXPECT_EQ(ASCIIToUTF16("Canada"), country); | 65 EXPECT_EQ(ASCIIToUTF16("Canada"), country); |
| 66 | 66 |
| 67 // Test country code detection. | 67 // Test country code detection. |
| 68 address.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("JP")); | 68 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP")); |
| 69 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 69 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 70 EXPECT_EQ("JP", address.country_code()); | 70 EXPECT_EQ("JP", address.country_code()); |
| 71 EXPECT_EQ(ASCIIToUTF16("Japan"), country); | 71 EXPECT_EQ(ASCIIToUTF16("Japan"), country); |
| 72 | 72 |
| 73 // Test that we ignore unknown countries. | 73 // Test that we ignore unknown countries. |
| 74 address.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("Unknown")); | 74 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown")); |
| 75 country = address.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 75 country = address.GetFieldText(ADDRESS_HOME_COUNTRY); |
| 76 EXPECT_EQ(std::string(), address.country_code()); | 76 EXPECT_EQ(std::string(), address.country_code()); |
| 77 EXPECT_EQ(string16(), country); | 77 EXPECT_EQ(string16(), country); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Test that we properly match typed values to stored country data. | 80 // Test that we properly match typed values to stored country data. |
| 81 TEST(AddressTest, IsCountry) { | 81 TEST(AddressTest, IsCountry) { |
| 82 Address address; | 82 Address address; |
| 83 address.set_country_code("US"); | 83 address.set_country_code("US"); |
| 84 | 84 |
| 85 const char* const kValidMatches[] = { | 85 const char* const kValidMatches[] = { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Make sure that garbage values don't match when the country code is empty. | 112 // Make sure that garbage values don't match when the country code is empty. |
| 113 address.set_country_code(""); | 113 address.set_country_code(""); |
| 114 EXPECT_EQ(std::string(), address.country_code()); | 114 EXPECT_EQ(std::string(), address.country_code()); |
| 115 FieldTypeSet possible_field_types; | 115 FieldTypeSet possible_field_types; |
| 116 address.GetPossibleFieldTypes(ASCIIToUTF16("Garbage"), | 116 address.GetPossibleFieldTypes(ASCIIToUTF16("Garbage"), |
| 117 &possible_field_types); | 117 &possible_field_types); |
| 118 EXPECT_EQ(0U, possible_field_types.size()); | 118 EXPECT_EQ(0U, possible_field_types.size()); |
| 119 } | 119 } |
| OLD | NEW |