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

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

Issue 10533143: Revert 142048 - Move thread checking from autofill_country.cc to browser_process_impl.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 | « no previous file | chrome/browser/autofill/autofill_country.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) 2012 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"
11 #include "chrome/browser/autofill/autofill_type.h" 11 #include "chrome/browser/autofill/autofill_type.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using content::BrowserThread; 15 using content::BrowserThread;
16 16
17 class AddressTest : public testing::Test {
18 public:
19 // In order to access the application locale -- which the tested functions do
20 // internally -- this test must run on the UI thread.
21 AddressTest() : ui_thread_(BrowserThread::UI, &message_loop_) {}
22
23 private:
24 MessageLoopForUI message_loop_;
25 content::TestBrowserThread ui_thread_;
26
27 DISALLOW_COPY_AND_ASSIGN(AddressTest);
28 };
29
17 // Test that the getters and setters for country code are working. 30 // Test that the getters and setters for country code are working.
18 TEST(AddressTest, CountryCode) { 31 TEST_F(AddressTest, CountryCode) {
19 Address address; 32 Address address;
20 EXPECT_EQ(std::string(), address.country_code()); 33 EXPECT_EQ(std::string(), address.country_code());
21 34
22 address.set_country_code("US"); 35 address.set_country_code("US");
23 EXPECT_EQ("US", address.country_code()); 36 EXPECT_EQ("US", address.country_code());
24 37
25 address.set_country_code("CA"); 38 address.set_country_code("CA");
26 EXPECT_EQ("CA", address.country_code()); 39 EXPECT_EQ("CA", address.country_code());
27 } 40 }
28 41
29 // Test that country codes are properly decoded as country names. 42 // Test that country codes are properly decoded as country names.
30 TEST(AddressTest, GetCountry) { 43 TEST_F(AddressTest, GetCountry) {
31 Address address; 44 Address address;
32 EXPECT_EQ(std::string(), address.country_code()); 45 EXPECT_EQ(std::string(), address.country_code());
33 46
34 // Make sure that nothing breaks when the country code is missing. 47 // Make sure that nothing breaks when the country code is missing.
35 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY); 48 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
36 EXPECT_EQ(string16(), country); 49 EXPECT_EQ(string16(), country);
37 50
38 address.set_country_code("US"); 51 address.set_country_code("US");
39 country = address.GetInfo(ADDRESS_HOME_COUNTRY); 52 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
40 EXPECT_EQ(ASCIIToUTF16("United States"), country); 53 EXPECT_EQ(ASCIIToUTF16("United States"), country);
41 54
42 address.set_country_code("CA"); 55 address.set_country_code("CA");
43 country = address.GetInfo(ADDRESS_HOME_COUNTRY); 56 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
44 EXPECT_EQ(ASCIIToUTF16("Canada"), country); 57 EXPECT_EQ(ASCIIToUTF16("Canada"), country);
45 } 58 }
46 59
47 // Test that we properly detect country codes appropriate for each country. 60 // Test that we properly detect country codes appropriate for each country.
48 TEST(AddressTest, SetCountry) { 61 TEST_F(AddressTest, SetCountry) {
49 Address address; 62 Address address;
50 EXPECT_EQ(std::string(), address.country_code()); 63 EXPECT_EQ(std::string(), address.country_code());
51 64
52 // Test basic conversion. 65 // Test basic conversion.
53 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); 66 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"));
54 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY); 67 string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
55 EXPECT_EQ("US", address.country_code()); 68 EXPECT_EQ("US", address.country_code());
56 EXPECT_EQ(ASCIIToUTF16("United States"), country); 69 EXPECT_EQ(ASCIIToUTF16("United States"), country);
57 70
58 // Test basic synonym detection. 71 // Test basic synonym detection.
(...skipping 15 matching lines...) Expand all
74 EXPECT_EQ(ASCIIToUTF16("Japan"), country); 87 EXPECT_EQ(ASCIIToUTF16("Japan"), country);
75 88
76 // Test that we ignore unknown countries. 89 // Test that we ignore unknown countries.
77 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown")); 90 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown"));
78 country = address.GetInfo(ADDRESS_HOME_COUNTRY); 91 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
79 EXPECT_EQ(std::string(), address.country_code()); 92 EXPECT_EQ(std::string(), address.country_code());
80 EXPECT_EQ(string16(), country); 93 EXPECT_EQ(string16(), country);
81 } 94 }
82 95
83 // Test that we properly match typed values to stored country data. 96 // Test that we properly match typed values to stored country data.
84 TEST(AddressTest, IsCountry) { 97 TEST_F(AddressTest, IsCountry) {
85 Address address; 98 Address address;
86 address.set_country_code("US"); 99 address.set_country_code("US");
87 100
88 const char* const kValidMatches[] = { 101 const char* const kValidMatches[] = {
89 "United States", 102 "United States",
90 "USA", 103 "USA",
91 "US", 104 "US",
92 "United states", 105 "United states",
93 "us" 106 "us"
94 }; 107 };
(...skipping 15 matching lines...) Expand all
110 EXPECT_EQ(0U, matching_types.size()); 123 EXPECT_EQ(0U, matching_types.size());
111 } 124 }
112 125
113 // Make sure that garbage values don't match when the country code is empty. 126 // Make sure that garbage values don't match when the country code is empty.
114 address.set_country_code(""); 127 address.set_country_code("");
115 EXPECT_EQ(std::string(), address.country_code()); 128 EXPECT_EQ(std::string(), address.country_code());
116 FieldTypeSet matching_types; 129 FieldTypeSet matching_types;
117 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), &matching_types); 130 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), &matching_types);
118 EXPECT_EQ(0U, matching_types.size()); 131 EXPECT_EQ(0U, matching_types.size());
119 } 132 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_country.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698