| 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" |
| 11 #include "chrome/test/testing_browser_process_test.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 14 typedef TestingBrowserProcessTest AddressTest; |
| 15 |
| 13 // Test that the getters and setters for country code are working. | 16 // Test that the getters and setters for country code are working. |
| 14 TEST(AddressTest, CountryCode) { | 17 TEST_F(AddressTest, CountryCode) { |
| 15 Address address; | 18 Address address; |
| 16 EXPECT_EQ(std::string(), address.country_code()); | 19 EXPECT_EQ(std::string(), address.country_code()); |
| 17 | 20 |
| 18 address.set_country_code("US"); | 21 address.set_country_code("US"); |
| 19 EXPECT_EQ("US", address.country_code()); | 22 EXPECT_EQ("US", address.country_code()); |
| 20 | 23 |
| 21 address.set_country_code("CA"); | 24 address.set_country_code("CA"); |
| 22 EXPECT_EQ("CA", address.country_code()); | 25 EXPECT_EQ("CA", address.country_code()); |
| 23 } | 26 } |
| 24 | 27 |
| 25 // Test that country codes are properly decoded as country names. | 28 // Test that country codes are properly decoded as country names. |
| 26 TEST(AddressTest, GetCountry) { | 29 TEST_F(AddressTest, GetCountry) { |
| 27 Address address; | 30 Address address; |
| 28 EXPECT_EQ(std::string(), address.country_code()); | 31 EXPECT_EQ(std::string(), address.country_code()); |
| 29 | 32 |
| 30 // Make sure that nothing breaks when the country code is missing. | 33 // Make sure that nothing breaks when the country code is missing. |
| 31 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY); | 34 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY); |
| 32 EXPECT_EQ(string16(), country); | 35 EXPECT_EQ(string16(), country); |
| 33 | 36 |
| 34 address.set_country_code("US"); | 37 address.set_country_code("US"); |
| 35 country = address.GetInfo(ADDRESS_HOME_COUNTRY); | 38 country = address.GetInfo(ADDRESS_HOME_COUNTRY); |
| 36 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 39 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 37 | 40 |
| 38 address.set_country_code("CA"); | 41 address.set_country_code("CA"); |
| 39 country = address.GetInfo(ADDRESS_HOME_COUNTRY); | 42 country = address.GetInfo(ADDRESS_HOME_COUNTRY); |
| 40 EXPECT_EQ(ASCIIToUTF16("Canada"), country); | 43 EXPECT_EQ(ASCIIToUTF16("Canada"), country); |
| 41 } | 44 } |
| 42 | 45 |
| 43 // Test that we properly detect country codes appropriate for each country. | 46 // Test that we properly detect country codes appropriate for each country. |
| 44 TEST(AddressTest, SetCountry) { | 47 TEST_F(AddressTest, SetCountry) { |
| 45 Address address; | 48 Address address; |
| 46 EXPECT_EQ(std::string(), address.country_code()); | 49 EXPECT_EQ(std::string(), address.country_code()); |
| 47 | 50 |
| 48 // Test basic conversion. | 51 // Test basic conversion. |
| 49 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); | 52 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); |
| 50 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY); | 53 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY); |
| 51 EXPECT_EQ("US", address.country_code()); | 54 EXPECT_EQ("US", address.country_code()); |
| 52 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 55 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 53 | 56 |
| 54 // Test basic synonym detection. | 57 // Test basic synonym detection. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 EXPECT_EQ(ASCIIToUTF16("Japan"), country); | 73 EXPECT_EQ(ASCIIToUTF16("Japan"), country); |
| 71 | 74 |
| 72 // Test that we ignore unknown countries. | 75 // Test that we ignore unknown countries. |
| 73 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown")); | 76 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown")); |
| 74 country = address.GetInfo(ADDRESS_HOME_COUNTRY); | 77 country = address.GetInfo(ADDRESS_HOME_COUNTRY); |
| 75 EXPECT_EQ(std::string(), address.country_code()); | 78 EXPECT_EQ(std::string(), address.country_code()); |
| 76 EXPECT_EQ(string16(), country); | 79 EXPECT_EQ(string16(), country); |
| 77 } | 80 } |
| 78 | 81 |
| 79 // Test that we properly match typed values to stored country data. | 82 // Test that we properly match typed values to stored country data. |
| 80 TEST(AddressTest, IsCountry) { | 83 TEST_F(AddressTest, IsCountry) { |
| 81 Address address; | 84 Address address; |
| 82 address.set_country_code("US"); | 85 address.set_country_code("US"); |
| 83 | 86 |
| 84 const char* const kValidMatches[] = { | 87 const char* const kValidMatches[] = { |
| 85 "United States", | 88 "United States", |
| 86 "USA", | 89 "USA", |
| 87 "US", | 90 "US", |
| 88 "United states", | 91 "United states", |
| 89 "us" | 92 "us" |
| 90 }; | 93 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 EXPECT_EQ(0U, matching_types.size()); | 109 EXPECT_EQ(0U, matching_types.size()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 // 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. |
| 110 address.set_country_code(""); | 113 address.set_country_code(""); |
| 111 EXPECT_EQ(std::string(), address.country_code()); | 114 EXPECT_EQ(std::string(), address.country_code()); |
| 112 FieldTypeSet matching_types; | 115 FieldTypeSet matching_types; |
| 113 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), &matching_types); | 116 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), &matching_types); |
| 114 EXPECT_EQ(0U, matching_types.size()); | 117 EXPECT_EQ(0U, matching_types.size()); |
| 115 } | 118 } |
| OLD | NEW |