OLD | NEW |
---|---|
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/scoped_temp_dir.h" | |
8 #include "base/guid.h" | 9 #include "base/guid.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
14 #include "chrome/test/base/testing_profile.h" | |
15 #include "components/autofill/core/browser/autofill_metrics.h" | 15 #include "components/autofill/core/browser/autofill_metrics.h" |
16 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
17 #include "components/autofill/core/browser/autofill_test_utils.h" | 17 #include "components/autofill/core/browser/autofill_test_utils.h" |
18 #include "components/autofill/core/browser/form_structure.h" | 18 #include "components/autofill/core/browser/form_structure.h" |
19 #include "components/autofill/core/browser/personal_data_manager.h" | 19 #include "components/autofill/core/browser/personal_data_manager.h" |
20 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 20 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
21 #include "components/autofill/core/browser/webdata/autofill_table.h" | 21 #include "components/autofill/core/browser/webdata/autofill_table.h" |
22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
23 #include "components/autofill/core/common/autofill_pref_names.h" | 23 #include "components/autofill/core/common/autofill_pref_names.h" |
24 #include "components/autofill/core/common/form_data.h" | 24 #include "components/autofill/core/common/form_data.h" |
25 #include "components/webdata/common/web_data_service_base.h" | 25 #include "components/webdata/common/web_data_service_base.h" |
26 #include "components/webdata/common/web_database_service.h" | 26 #include "components/webdata/common/web_database_service.h" |
27 #include "content/public/test/test_browser_thread.h" | |
28 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
30 | 29 |
31 using base::ASCIIToUTF16; | 30 using base::ASCIIToUTF16; |
32 | 31 |
33 using content::BrowserThread; | |
34 | |
35 namespace autofill { | 32 namespace autofill { |
36 namespace { | 33 namespace { |
37 | 34 |
38 ACTION(QuitUIMessageLoop) { | 35 ACTION(QuitUIMessageLoop) { |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
blundell
2014/03/05 15:55:01
Is it important to preserve this DCHECK in some wa
Ilya Sherman
2014/03/05 23:59:44
Nah, though it might be worth renaming the action
blundell
2014/03/06 09:32:32
Done.
| |
40 base::MessageLoop::current()->Quit(); | 36 base::MessageLoop::current()->Quit(); |
41 } | 37 } |
42 | 38 |
43 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { | 39 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { |
44 public: | 40 public: |
45 PersonalDataLoadedObserverMock() {} | 41 PersonalDataLoadedObserverMock() {} |
46 virtual ~PersonalDataLoadedObserverMock() {} | 42 virtual ~PersonalDataLoadedObserverMock() {} |
47 | 43 |
48 MOCK_METHOD0(OnPersonalDataChanged, void()); | 44 MOCK_METHOD0(OnPersonalDataChanged, void()); |
49 }; | 45 }; |
50 | 46 |
51 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, | 47 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, |
52 // which are handy for briefer test code. The AutofillMetrics class is | 48 // which are handy for briefer test code. The AutofillMetrics class is |
53 // stateless, so this is safe. | 49 // stateless, so this is safe. |
54 class TestAutofillMetrics : public AutofillMetrics { | 50 class TestAutofillMetrics : public AutofillMetrics { |
55 public: | 51 public: |
56 TestAutofillMetrics() {} | 52 TestAutofillMetrics() {} |
57 virtual ~TestAutofillMetrics() {} | 53 virtual ~TestAutofillMetrics() {} |
58 }; | 54 }; |
59 | 55 |
60 } // anonymous namespace | 56 } // anonymous namespace |
61 | 57 |
62 class PersonalDataManagerTest : public testing::Test { | 58 class PersonalDataManagerTest : public testing::Test { |
63 protected: | 59 protected: |
64 PersonalDataManagerTest() | 60 PersonalDataManagerTest() {} |
65 : ui_thread_(BrowserThread::UI, &message_loop_), | |
66 db_thread_(BrowserThread::DB) { | |
67 } | |
68 | 61 |
69 virtual void SetUp() { | 62 virtual void SetUp() { |
70 db_thread_.Start(); | |
71 | 63 |
64 prefs_ = test::PrefServiceForTesting(); | |
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 65 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
73 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); | 66 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); |
74 web_database_ = new WebDatabaseService( | 67 web_database_ = new WebDatabaseService(path, |
75 path, | 68 base::MessageLoopProxy::current(), |
76 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 69 base::MessageLoopProxy::current()); |
77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)); | |
78 web_database_->AddTable( | 70 web_database_->AddTable( |
79 scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); | 71 scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); |
80 web_database_->LoadDatabase(); | 72 web_database_->LoadDatabase(); |
81 autofill_database_service_ = new AutofillWebDataService( | 73 autofill_database_service_ = |
82 web_database_, | 74 new AutofillWebDataService(web_database_, |
83 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 75 base::MessageLoopProxy::current(), |
84 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 76 base::MessageLoopProxy::current(), |
85 WebDataServiceBase::ProfileErrorCallback()); | 77 WebDataServiceBase::ProfileErrorCallback()); |
86 autofill_database_service_->Init(); | 78 autofill_database_service_->Init(); |
87 | 79 |
88 profile_.reset(new TestingProfile); | 80 ResetPersonalDataManager(false); |
89 profile_->CreateWebDataService(); | |
90 | |
91 test::DisableSystemServices(profile_.get()); | |
92 ResetPersonalDataManager(); | |
93 } | 81 } |
94 | 82 |
95 virtual void TearDown() { | 83 virtual void TearDown() { |
96 // Destruction order is imposed explicitly here. | 84 // Destruction order is imposed explicitly here. |
97 personal_data_.reset(NULL); | 85 personal_data_.reset(NULL); |
98 profile_.reset(NULL); | |
99 | 86 |
100 autofill_database_service_->ShutdownOnUIThread(); | 87 autofill_database_service_->ShutdownOnUIThread(); |
101 web_database_->ShutdownDatabase(); | 88 web_database_->ShutdownDatabase(); |
102 autofill_database_service_ = NULL; | 89 autofill_database_service_ = NULL; |
103 web_database_ = NULL; | 90 web_database_ = NULL; |
104 | |
105 // Schedule another task on the DB thread to notify us that it's safe to | |
blundell
2014/03/05 15:55:01
Related to the question that I have below, this co
Ilya Sherman
2014/03/05 23:59:44
No, this is a test pattern that's discouraged thes
| |
106 // stop the thread. | |
107 base::WaitableEvent done(false, false); | |
108 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
109 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | |
110 done.Wait(); | |
111 base::MessageLoop::current()->PostTask(FROM_HERE, | |
112 base::MessageLoop::QuitClosure()); | |
113 base::MessageLoop::current()->Run(); | |
114 db_thread_.Stop(); | |
115 } | 91 } |
116 | 92 |
117 void ResetPersonalDataManager() { | 93 void ResetPersonalDataManager(bool is_incognito) { |
Ilya Sherman
2014/03/05 23:59:44
nit: Please define an enum for this parameter, rat
blundell
2014/03/06 09:32:32
Done.
| |
118 personal_data_.reset(new PersonalDataManager("en-US")); | 94 personal_data_.reset(new PersonalDataManager("en-US")); |
119 personal_data_->Init( | 95 personal_data_->Init( |
120 scoped_refptr<AutofillWebDataService>(autofill_database_service_), | 96 scoped_refptr<AutofillWebDataService>(autofill_database_service_), |
121 profile_->GetPrefs(), | 97 prefs_.get(), |
122 profile_->IsOffTheRecord()); | 98 is_incognito); |
123 personal_data_->AddObserver(&personal_data_observer_); | 99 personal_data_->AddObserver(&personal_data_observer_); |
124 | 100 |
125 // Verify that the web database has been updated and the notification sent. | 101 // Verify that the web database has been updated and the notification sent. |
126 EXPECT_CALL(personal_data_observer_, | 102 EXPECT_CALL(personal_data_observer_, |
127 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 103 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
128 base::MessageLoop::current()->Run(); | 104 base::MessageLoop::current()->Run(); |
129 } | 105 } |
130 | 106 |
131 void MakeProfileIncognito() { | |
132 // Switch to an incognito profile. | |
133 profile_->ForceIncognito(true); | |
134 DCHECK(profile_->IsOffTheRecord()); | |
135 } | |
136 | |
137 base::MessageLoopForUI message_loop_; | 107 base::MessageLoopForUI message_loop_; |
138 content::TestBrowserThread ui_thread_; | 108 scoped_ptr<PrefService> prefs_; |
139 content::TestBrowserThread db_thread_; | |
blundell
2014/03/05 15:55:01
I can't remember how TestBrowserThread works off t
Ilya Sherman
2014/03/05 23:59:44
These were previously different message loops, but
blundell
2014/03/06 09:32:32
I can't use TestBrowserThreadBundle here in any ca
| |
140 scoped_ptr<TestingProfile> profile_; | |
141 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 109 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
142 scoped_refptr<WebDatabaseService> web_database_; | 110 scoped_refptr<WebDatabaseService> web_database_; |
143 base::ScopedTempDir temp_dir_; | 111 base::ScopedTempDir temp_dir_; |
144 scoped_ptr<PersonalDataManager> personal_data_; | 112 scoped_ptr<PersonalDataManager> personal_data_; |
145 PersonalDataLoadedObserverMock personal_data_observer_; | 113 PersonalDataLoadedObserverMock personal_data_observer_; |
146 }; | 114 }; |
147 | 115 |
148 TEST_F(PersonalDataManagerTest, AddProfile) { | 116 TEST_F(PersonalDataManagerTest, AddProfile) { |
149 // Add profile0 to the database. | 117 // Add profile0 to the database. |
150 AutofillProfile profile0(autofill::test::GetFullProfile()); | 118 AutofillProfile profile0(autofill::test::GetFullProfile()); |
151 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 119 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
152 personal_data_->AddProfile(profile0); | 120 personal_data_->AddProfile(profile0); |
153 | 121 |
154 // Reload the database. | 122 // Reload the database. |
155 ResetPersonalDataManager(); | 123 ResetPersonalDataManager(false); |
156 | 124 |
157 // Verify the addition. | 125 // Verify the addition. |
158 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | 126 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
159 ASSERT_EQ(1U, results1.size()); | 127 ASSERT_EQ(1U, results1.size()); |
160 EXPECT_EQ(0, profile0.Compare(*results1[0])); | 128 EXPECT_EQ(0, profile0.Compare(*results1[0])); |
161 | 129 |
162 // Add profile with identical values. Duplicates should not get saved. | 130 // Add profile with identical values. Duplicates should not get saved. |
163 AutofillProfile profile0a = profile0; | 131 AutofillProfile profile0a = profile0; |
164 profile0a.set_guid(base::GenerateGUID()); | 132 profile0a.set_guid(base::GenerateGUID()); |
165 personal_data_->AddProfile(profile0a); | 133 personal_data_->AddProfile(profile0a); |
166 | 134 |
167 // Reload the database. | 135 // Reload the database. |
168 ResetPersonalDataManager(); | 136 ResetPersonalDataManager(false); |
169 | 137 |
170 // Verify the non-addition. | 138 // Verify the non-addition. |
171 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 139 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
172 ASSERT_EQ(1U, results2.size()); | 140 ASSERT_EQ(1U, results2.size()); |
173 EXPECT_EQ(0, profile0.Compare(*results2[0])); | 141 EXPECT_EQ(0, profile0.Compare(*results2[0])); |
174 | 142 |
175 // New profile with different email. | 143 // New profile with different email. |
176 AutofillProfile profile1 = profile0; | 144 AutofillProfile profile1 = profile0; |
177 profile1.set_guid(base::GenerateGUID()); | 145 profile1.set_guid(base::GenerateGUID()); |
178 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); | 146 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); |
179 | 147 |
180 // Add the different profile. This should save as a separate profile. | 148 // Add the different profile. This should save as a separate profile. |
181 // Note that if this same profile was "merged" it would collapse to one | 149 // Note that if this same profile was "merged" it would collapse to one |
182 // profile with a multi-valued entry for email. | 150 // profile with a multi-valued entry for email. |
183 personal_data_->AddProfile(profile1); | 151 personal_data_->AddProfile(profile1); |
184 | 152 |
185 // Reload the database. | 153 // Reload the database. |
186 ResetPersonalDataManager(); | 154 ResetPersonalDataManager(false); |
187 | 155 |
188 // Verify the addition. | 156 // Verify the addition. |
189 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | 157 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
190 ASSERT_EQ(2U, results3.size()); | 158 ASSERT_EQ(2U, results3.size()); |
191 EXPECT_EQ(0, profile0.Compare(*results3[0])); | 159 EXPECT_EQ(0, profile0.Compare(*results3[0])); |
192 EXPECT_EQ(0, profile1.Compare(*results3[1])); | 160 EXPECT_EQ(0, profile1.Compare(*results3[1])); |
193 } | 161 } |
194 | 162 |
195 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { | 163 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { |
196 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 164 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 base::MessageLoop::current()->Run(); | 205 base::MessageLoop::current()->Run(); |
238 | 206 |
239 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 207 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
240 ASSERT_EQ(2U, results2.size()); | 208 ASSERT_EQ(2U, results2.size()); |
241 EXPECT_EQ(0, profile0.Compare(*results2[0])); | 209 EXPECT_EQ(0, profile0.Compare(*results2[0])); |
242 EXPECT_EQ(0, profile2.Compare(*results2[1])); | 210 EXPECT_EQ(0, profile2.Compare(*results2[1])); |
243 | 211 |
244 // Reset the PersonalDataManager. This tests that the personal data was saved | 212 // Reset the PersonalDataManager. This tests that the personal data was saved |
245 // to the web database, and that we can load the profiles from the web | 213 // to the web database, and that we can load the profiles from the web |
246 // database. | 214 // database. |
247 ResetPersonalDataManager(); | 215 ResetPersonalDataManager(false); |
248 | 216 |
249 // Verify that we've loaded the profiles from the web database. | 217 // Verify that we've loaded the profiles from the web database. |
250 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | 218 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
251 ASSERT_EQ(2U, results3.size()); | 219 ASSERT_EQ(2U, results3.size()); |
252 EXPECT_EQ(0, profile0.Compare(*results3[0])); | 220 EXPECT_EQ(0, profile0.Compare(*results3[0])); |
253 EXPECT_EQ(0, profile2.Compare(*results3[1])); | 221 EXPECT_EQ(0, profile2.Compare(*results3[1])); |
254 } | 222 } |
255 | 223 |
256 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { | 224 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
257 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 225 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 base::MessageLoop::current()->Run(); | 260 base::MessageLoop::current()->Run(); |
293 | 261 |
294 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 262 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
295 ASSERT_EQ(2U, results2.size()); | 263 ASSERT_EQ(2U, results2.size()); |
296 EXPECT_EQ(credit_card0, *results2[0]); | 264 EXPECT_EQ(credit_card0, *results2[0]); |
297 EXPECT_EQ(credit_card2, *results2[1]); | 265 EXPECT_EQ(credit_card2, *results2[1]); |
298 | 266 |
299 // Reset the PersonalDataManager. This tests that the personal data was saved | 267 // Reset the PersonalDataManager. This tests that the personal data was saved |
300 // to the web database, and that we can load the credit cards from the web | 268 // to the web database, and that we can load the credit cards from the web |
301 // database. | 269 // database. |
302 ResetPersonalDataManager(); | 270 ResetPersonalDataManager(false); |
303 | 271 |
304 // Verify that we've loaded the credit cards from the web database. | 272 // Verify that we've loaded the credit cards from the web database. |
305 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | 273 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
306 ASSERT_EQ(2U, results3.size()); | 274 ASSERT_EQ(2U, results3.size()); |
307 EXPECT_EQ(credit_card0, *results3[0]); | 275 EXPECT_EQ(credit_card0, *results3[0]); |
308 EXPECT_EQ(credit_card2, *results3[1]); | 276 EXPECT_EQ(credit_card2, *results3[1]); |
309 } | 277 } |
310 | 278 |
311 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { | 279 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { |
312 // Start with unverified data. | 280 // Start with unverified data. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 "", "", "", "", "", "", "", "", "", "", "", ""); | 458 "", "", "", "", "", "", "", "", "", "", "", ""); |
491 | 459 |
492 // Add the empty profile to the database. | 460 // Add the empty profile to the database. |
493 personal_data_->AddProfile(profile0); | 461 personal_data_->AddProfile(profile0); |
494 | 462 |
495 // Note: no refresh here. | 463 // Note: no refresh here. |
496 | 464 |
497 // Reset the PersonalDataManager. This tests that the personal data was saved | 465 // Reset the PersonalDataManager. This tests that the personal data was saved |
498 // to the web database, and that we can load the profiles from the web | 466 // to the web database, and that we can load the profiles from the web |
499 // database. | 467 // database. |
500 ResetPersonalDataManager(); | 468 ResetPersonalDataManager(false); |
501 | 469 |
502 // Verify that we've loaded the profiles from the web database. | 470 // Verify that we've loaded the profiles from the web database. |
503 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 471 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
504 ASSERT_EQ(0U, results2.size()); | 472 ASSERT_EQ(0U, results2.size()); |
505 } | 473 } |
506 | 474 |
507 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { | 475 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { |
508 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 476 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
509 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); | 477 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); |
510 | 478 |
511 // Add the empty credit card to the database. | 479 // Add the empty credit card to the database. |
512 personal_data_->AddCreditCard(credit_card0); | 480 personal_data_->AddCreditCard(credit_card0); |
513 | 481 |
514 // Note: no refresh here. | 482 // Note: no refresh here. |
515 | 483 |
516 // Reset the PersonalDataManager. This tests that the personal data was saved | 484 // Reset the PersonalDataManager. This tests that the personal data was saved |
517 // to the web database, and that we can load the credit cards from the web | 485 // to the web database, and that we can load the credit cards from the web |
518 // database. | 486 // database. |
519 ResetPersonalDataManager(); | 487 ResetPersonalDataManager(false); |
520 | 488 |
521 // Verify that we've loaded the credit cards from the web database. | 489 // Verify that we've loaded the credit cards from the web database. |
522 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 490 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
523 ASSERT_EQ(0U, results2.size()); | 491 ASSERT_EQ(0U, results2.size()); |
524 } | 492 } |
525 | 493 |
526 TEST_F(PersonalDataManagerTest, Refresh) { | 494 TEST_F(PersonalDataManagerTest, Refresh) { |
527 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 495 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
528 test::SetProfileInfo(&profile0, | 496 test::SetProfileInfo(&profile0, |
529 "Marion", "Mitchell", "Morrison", | 497 "Marion", "Mitchell", "Morrison", |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 personal_data_->AddCreditCard(credit_card0); | 915 personal_data_->AddCreditCard(credit_card0); |
948 personal_data_->AddCreditCard(credit_card1); | 916 personal_data_->AddCreditCard(credit_card1); |
949 personal_data_->AddCreditCard(credit_card2); | 917 personal_data_->AddCreditCard(credit_card2); |
950 personal_data_->AddCreditCard(credit_card3); | 918 personal_data_->AddCreditCard(credit_card3); |
951 personal_data_->AddCreditCard(credit_card4); | 919 personal_data_->AddCreditCard(credit_card4); |
952 personal_data_->AddCreditCard(credit_card5); | 920 personal_data_->AddCreditCard(credit_card5); |
953 | 921 |
954 // Reset the PersonalDataManager. This tests that the personal data was saved | 922 // Reset the PersonalDataManager. This tests that the personal data was saved |
955 // to the web database, and that we can load the credit cards from the web | 923 // to the web database, and that we can load the credit cards from the web |
956 // database. | 924 // database. |
957 ResetPersonalDataManager(); | 925 ResetPersonalDataManager(false); |
958 | 926 |
959 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 927 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
960 ASSERT_EQ(6U, results.size()); | 928 ASSERT_EQ(6U, results.size()); |
961 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); | 929 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); |
962 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); | 930 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); |
963 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); | 931 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); |
964 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); | 932 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); |
965 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); | 933 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); |
966 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); | 934 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); |
967 } | 935 } |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1429 | 1397 |
1430 FormStructure form_structure1(form1); | 1398 FormStructure form_structure1(form1); |
1431 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1399 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
1432 scoped_ptr<CreditCard> imported_credit_card; | 1400 scoped_ptr<CreditCard> imported_credit_card; |
1433 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, | 1401 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, |
1434 &imported_credit_card)); | 1402 &imported_credit_card)); |
1435 ASSERT_FALSE(imported_credit_card); | 1403 ASSERT_FALSE(imported_credit_card); |
1436 | 1404 |
1437 // Since no refresh is expected, reload the data from the database to make | 1405 // Since no refresh is expected, reload the data from the database to make |
1438 // sure no changes were written out. | 1406 // sure no changes were written out. |
1439 ResetPersonalDataManager(); | 1407 ResetPersonalDataManager(false); |
1440 | 1408 |
1441 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 1409 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
1442 ASSERT_EQ(0U, profiles.size()); | 1410 ASSERT_EQ(0U, profiles.size()); |
1443 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); | 1411 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); |
1444 ASSERT_EQ(0U, cards.size()); | 1412 ASSERT_EQ(0U, cards.size()); |
1445 } | 1413 } |
1446 | 1414 |
1447 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { | 1415 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { |
1448 // Simulate having access to an auxiliary profile. | 1416 // Simulate having access to an auxiliary profile. |
1449 // |auxiliary_profile| will be owned by |personal_data_|. | 1417 // |auxiliary_profile| will be owned by |personal_data_|. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1617 form2.fields.push_back(field); | 1585 form2.fields.push_back(field); |
1618 | 1586 |
1619 FormStructure form_structure2(form2); | 1587 FormStructure form_structure2(form2); |
1620 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1588 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1621 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | 1589 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
1622 &imported_credit_card)); | 1590 &imported_credit_card)); |
1623 ASSERT_FALSE(imported_credit_card); | 1591 ASSERT_FALSE(imported_credit_card); |
1624 | 1592 |
1625 // Since no refresh is expected, reload the data from the database to make | 1593 // Since no refresh is expected, reload the data from the database to make |
1626 // sure no changes were written out. | 1594 // sure no changes were written out. |
1627 ResetPersonalDataManager(); | 1595 ResetPersonalDataManager(false); |
1628 | 1596 |
1629 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1597 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1630 ASSERT_EQ(1U, results2.size()); | 1598 ASSERT_EQ(1U, results2.size()); |
1631 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1599 EXPECT_EQ(0, expected.Compare(*results2[0])); |
1632 } | 1600 } |
1633 | 1601 |
1634 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { | 1602 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { |
1635 FormData form1; | 1603 FormData form1; |
1636 | 1604 |
1637 // Start with a single valid credit card form. | 1605 // Start with a single valid credit card form. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1749 form2.fields.push_back(field); | 1717 form2.fields.push_back(field); |
1750 | 1718 |
1751 FormStructure form_structure2(form2); | 1719 FormStructure form_structure2(form2); |
1752 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1720 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1753 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | 1721 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
1754 &imported_credit_card)); | 1722 &imported_credit_card)); |
1755 EXPECT_FALSE(imported_credit_card); | 1723 EXPECT_FALSE(imported_credit_card); |
1756 | 1724 |
1757 // Since no refresh is expected, reload the data from the database to make | 1725 // Since no refresh is expected, reload the data from the database to make |
1758 // sure no changes were written out. | 1726 // sure no changes were written out. |
1759 ResetPersonalDataManager(); | 1727 ResetPersonalDataManager(false); |
1760 | 1728 |
1761 // No change is expected. | 1729 // No change is expected. |
1762 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1730 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1763 test::SetCreditCardInfo(&expected2, | 1731 test::SetCreditCardInfo(&expected2, |
1764 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1732 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1765 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1733 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1766 ASSERT_EQ(1U, results2.size()); | 1734 ASSERT_EQ(1U, results2.size()); |
1767 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1735 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
1768 } | 1736 } |
1769 | 1737 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1816 form2.fields.push_back(field); | 1784 form2.fields.push_back(field); |
1817 | 1785 |
1818 FormStructure form_structure2(form2); | 1786 FormStructure form_structure2(form2); |
1819 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1787 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
1820 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | 1788 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
1821 &imported_credit_card)); | 1789 &imported_credit_card)); |
1822 EXPECT_FALSE(imported_credit_card); | 1790 EXPECT_FALSE(imported_credit_card); |
1823 | 1791 |
1824 // Since no refresh is expected, reload the data from the database to make | 1792 // Since no refresh is expected, reload the data from the database to make |
1825 // sure no changes were written out. | 1793 // sure no changes were written out. |
1826 ResetPersonalDataManager(); | 1794 ResetPersonalDataManager(false); |
1827 | 1795 |
1828 // No change is expected. | 1796 // No change is expected. |
1829 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 1797 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
1830 test::SetCreditCardInfo(&expected2, | 1798 test::SetCreditCardInfo(&expected2, |
1831 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1799 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1832 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1800 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1833 ASSERT_EQ(1U, results2.size()); | 1801 ASSERT_EQ(1U, results2.size()); |
1834 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1802 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
1835 | 1803 |
1836 // Add a third credit card where the expiration date is missing. | 1804 // Add a third credit card where the expiration date is missing. |
1837 FormData form3; | 1805 FormData form3; |
1838 test::CreateTestFormField( | 1806 test::CreateTestFormField( |
1839 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); | 1807 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); |
1840 form3.fields.push_back(field); | 1808 form3.fields.push_back(field); |
1841 test::CreateTestFormField( | 1809 test::CreateTestFormField( |
1842 "Card Number:", "card_number", "5555555555554444", "text", &field); | 1810 "Card Number:", "card_number", "5555555555554444", "text", &field); |
1843 form3.fields.push_back(field); | 1811 form3.fields.push_back(field); |
1844 // Note missing expiration month and year.. | 1812 // Note missing expiration month and year.. |
1845 | 1813 |
1846 FormStructure form_structure3(form3); | 1814 FormStructure form_structure3(form3); |
1847 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); | 1815 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); |
1848 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, | 1816 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, |
1849 &imported_credit_card)); | 1817 &imported_credit_card)); |
1850 ASSERT_FALSE(imported_credit_card); | 1818 ASSERT_FALSE(imported_credit_card); |
1851 | 1819 |
1852 // Since no refresh is expected, reload the data from the database to make | 1820 // Since no refresh is expected, reload the data from the database to make |
1853 // sure no changes were written out. | 1821 // sure no changes were written out. |
1854 ResetPersonalDataManager(); | 1822 ResetPersonalDataManager(false); |
1855 | 1823 |
1856 // No change is expected. | 1824 // No change is expected. |
1857 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | 1825 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); |
1858 test::SetCreditCardInfo(&expected3, | 1826 test::SetCreditCardInfo(&expected3, |
1859 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1827 "Biggie Smalls", "4111111111111111", "01", "2011"); |
1860 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | 1828 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
1861 ASSERT_EQ(1U, results3.size()); | 1829 ASSERT_EQ(1U, results3.size()); |
1862 EXPECT_EQ(0, expected3.Compare(*results3[0])); | 1830 EXPECT_EQ(0, expected3.Compare(*results3[0])); |
1863 } | 1831 } |
1864 | 1832 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1952 | 1920 |
1953 FormStructure form_structure(form); | 1921 FormStructure form_structure(form); |
1954 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 1922 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
1955 scoped_ptr<CreditCard> imported_credit_card; | 1923 scoped_ptr<CreditCard> imported_credit_card; |
1956 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 1924 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
1957 &imported_credit_card)); | 1925 &imported_credit_card)); |
1958 EXPECT_FALSE(imported_credit_card); | 1926 EXPECT_FALSE(imported_credit_card); |
1959 | 1927 |
1960 // Since no refresh is expected, reload the data from the database to make | 1928 // Since no refresh is expected, reload the data from the database to make |
1961 // sure no changes were written out. | 1929 // sure no changes were written out. |
1962 ResetPersonalDataManager(); | 1930 ResetPersonalDataManager(false); |
1963 | 1931 |
1964 // Expect that no new card is saved. | 1932 // Expect that no new card is saved. |
1965 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 1933 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
1966 ASSERT_EQ(1U, results2.size()); | 1934 ASSERT_EQ(1U, results2.size()); |
1967 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 1935 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); |
1968 } | 1936 } |
1969 | 1937 |
1970 // Ensure that if a verified profile already exists, aggregated profiles cannot | 1938 // Ensure that if a verified profile already exists, aggregated profiles cannot |
1971 // modify it in any way. | 1939 // modify it in any way. |
1972 TEST_F(PersonalDataManagerTest, AggregateExistingVerifiedProfileWithConflict) { | 1940 TEST_F(PersonalDataManagerTest, AggregateExistingVerifiedProfileWithConflict) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2060 | 2028 |
2061 FormStructure form_structure(form); | 2029 FormStructure form_structure(form); |
2062 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 2030 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
2063 scoped_ptr<CreditCard> imported_credit_card; | 2031 scoped_ptr<CreditCard> imported_credit_card; |
2064 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 2032 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
2065 &imported_credit_card)); | 2033 &imported_credit_card)); |
2066 ASSERT_FALSE(imported_credit_card); | 2034 ASSERT_FALSE(imported_credit_card); |
2067 | 2035 |
2068 // Since no refresh is expected, reload the data from the database to make | 2036 // Since no refresh is expected, reload the data from the database to make |
2069 // sure no changes were written out. | 2037 // sure no changes were written out. |
2070 ResetPersonalDataManager(); | 2038 ResetPersonalDataManager(false); |
2071 | 2039 |
2072 // Expect that the saved credit card is not modified. | 2040 // Expect that the saved credit card is not modified. |
2073 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2041 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
2074 ASSERT_EQ(1U, results.size()); | 2042 ASSERT_EQ(1U, results.size()); |
2075 EXPECT_EQ(0, credit_card.Compare(*results[0])); | 2043 EXPECT_EQ(0, credit_card.Compare(*results[0])); |
2076 } | 2044 } |
2077 | 2045 |
2078 // Ensure that verified profiles can be saved via SaveImportedProfile, | 2046 // Ensure that verified profiles can be saved via SaveImportedProfile, |
2079 // overwriting existing unverified profiles. | 2047 // overwriting existing unverified profiles. |
2080 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { | 2048 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2419 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", | 2387 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", |
2420 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", | 2388 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", |
2421 "US", "(800) 275-2273"); | 2389 "US", "(800) 275-2273"); |
2422 personal_data_->AddProfile(steve_jobs); | 2390 personal_data_->AddProfile(steve_jobs); |
2423 | 2391 |
2424 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); | 2392 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); |
2425 test::SetCreditCardInfo( | 2393 test::SetCreditCardInfo( |
2426 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); | 2394 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); |
2427 personal_data_->AddCreditCard(bill_gates); | 2395 personal_data_->AddCreditCard(bill_gates); |
2428 | 2396 |
2429 MakeProfileIncognito(); | |
2430 | |
2431 // The personal data manager should be able to read existing profiles in an | 2397 // The personal data manager should be able to read existing profiles in an |
2432 // off-the-record context. | 2398 // off-the-record context. |
2433 ResetPersonalDataManager(); | 2399 ResetPersonalDataManager(true); |
2434 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); | 2400 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); |
2435 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 2401 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
2436 | 2402 |
2437 // No adds, saves, or updates should take effect. | 2403 // No adds, saves, or updates should take effect. |
2438 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); | 2404 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
2439 | 2405 |
2440 // Add profiles or credit card shouldn't work. | 2406 // Add profiles or credit card shouldn't work. |
2441 personal_data_->AddProfile(test::GetFullProfile()); | 2407 personal_data_->AddProfile(test::GetFullProfile()); |
2442 | 2408 |
2443 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); | 2409 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); |
2444 test::SetCreditCardInfo( | 2410 test::SetCreditCardInfo( |
2445 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); | 2411 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); |
2446 personal_data_->AddCreditCard(larry_page); | 2412 personal_data_->AddCreditCard(larry_page); |
2447 | 2413 |
2448 ResetPersonalDataManager(); | 2414 ResetPersonalDataManager(true); |
2449 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2415 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
2450 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 2416 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
2451 | 2417 |
2452 // Saving or creating profiles from imported profiles shouldn't work. | 2418 // Saving or creating profiles from imported profiles shouldn't work. |
2453 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | 2419 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); |
2454 personal_data_->SaveImportedProfile(steve_jobs); | 2420 personal_data_->SaveImportedProfile(steve_jobs); |
2455 | 2421 |
2456 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | 2422 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); |
2457 personal_data_->SaveImportedCreditCard(bill_gates); | 2423 personal_data_->SaveImportedCreditCard(bill_gates); |
2458 | 2424 |
2459 ResetPersonalDataManager(); | 2425 ResetPersonalDataManager(true); |
2460 EXPECT_EQ(ASCIIToUTF16("Steven"), | 2426 EXPECT_EQ(ASCIIToUTF16("Steven"), |
2461 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | 2427 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); |
2462 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | 2428 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), |
2463 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2429 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); |
2464 | 2430 |
2465 // Updating existing profiles shouldn't work. | 2431 // Updating existing profiles shouldn't work. |
2466 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | 2432 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); |
2467 personal_data_->UpdateProfile(steve_jobs); | 2433 personal_data_->UpdateProfile(steve_jobs); |
2468 | 2434 |
2469 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | 2435 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); |
2470 personal_data_->UpdateCreditCard(bill_gates); | 2436 personal_data_->UpdateCreditCard(bill_gates); |
2471 | 2437 |
2472 ResetPersonalDataManager(); | 2438 ResetPersonalDataManager(true); |
2473 EXPECT_EQ(ASCIIToUTF16("Steven"), | 2439 EXPECT_EQ(ASCIIToUTF16("Steven"), |
2474 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | 2440 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); |
2475 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | 2441 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), |
2476 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2442 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); |
2477 | 2443 |
2478 // Removing shouldn't work. | 2444 // Removing shouldn't work. |
2479 personal_data_->RemoveByGUID(steve_jobs.guid()); | 2445 personal_data_->RemoveByGUID(steve_jobs.guid()); |
2480 personal_data_->RemoveByGUID(bill_gates.guid()); | 2446 personal_data_->RemoveByGUID(bill_gates.guid()); |
2481 | 2447 |
2482 ResetPersonalDataManager(); | 2448 ResetPersonalDataManager(true); |
2483 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2449 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
2484 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 2450 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
2485 } | 2451 } |
2486 | 2452 |
2487 TEST_F(PersonalDataManagerTest, DefaultCountryCodeIsCached) { | 2453 TEST_F(PersonalDataManagerTest, DefaultCountryCodeIsCached) { |
2488 // The return value should always be some country code, no matter what. | 2454 // The return value should always be some country code, no matter what. |
2489 std::string default_country = | 2455 std::string default_country = |
2490 personal_data_->GetDefaultCountryCodeForNewAddress(); | 2456 personal_data_->GetDefaultCountryCodeForNewAddress(); |
2491 EXPECT_EQ(2U, default_country.size()); | 2457 EXPECT_EQ(2U, default_country.size()); |
2492 | 2458 |
2493 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); | 2459 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); |
2494 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", | 2460 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", |
2495 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", | 2461 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", |
2496 "CA", "(800) 555-9000"); | 2462 "CA", "(800) 555-9000"); |
2497 personal_data_->AddProfile(moose); | 2463 personal_data_->AddProfile(moose); |
2498 EXPECT_CALL(personal_data_observer_, | 2464 EXPECT_CALL(personal_data_observer_, |
2499 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 2465 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
2500 base::MessageLoop::current()->Run(); | 2466 base::MessageLoop::current()->Run(); |
2501 // The value is cached and doesn't change even after adding an address. | 2467 // The value is cached and doesn't change even after adding an address. |
2502 EXPECT_EQ(default_country, | 2468 EXPECT_EQ(default_country, |
2503 personal_data_->GetDefaultCountryCodeForNewAddress()); | 2469 personal_data_->GetDefaultCountryCodeForNewAddress()); |
2504 | 2470 |
2505 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); | 2471 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); |
2506 | 2472 |
2507 // Disabling Autofill blows away this cache and shouldn't account for Autofill | 2473 // Disabling Autofill blows away this cache and shouldn't account for Autofill |
2508 // profiles. | 2474 // profiles. |
2509 profile_->GetPrefs()->SetBoolean(prefs::kAutofillEnabled, false); | 2475 prefs_->SetBoolean(prefs::kAutofillEnabled, false); |
2510 EXPECT_EQ(default_country, | 2476 EXPECT_EQ(default_country, |
2511 personal_data_->GetDefaultCountryCodeForNewAddress()); | 2477 personal_data_->GetDefaultCountryCodeForNewAddress()); |
2512 | 2478 |
2513 // Enabling Autofill blows away the cached value and should reflect the new | 2479 // Enabling Autofill blows away the cached value and should reflect the new |
2514 // value (accounting for profiles). | 2480 // value (accounting for profiles). |
2515 profile_->GetPrefs()->SetBoolean(prefs::kAutofillEnabled, true); | 2481 prefs_->SetBoolean(prefs::kAutofillEnabled, true); |
2516 EXPECT_EQ(base::UTF16ToUTF8(moose.GetRawInfo(ADDRESS_HOME_COUNTRY)), | 2482 EXPECT_EQ(base::UTF16ToUTF8(moose.GetRawInfo(ADDRESS_HOME_COUNTRY)), |
2517 personal_data_->GetDefaultCountryCodeForNewAddress()); | 2483 personal_data_->GetDefaultCountryCodeForNewAddress()); |
2518 } | 2484 } |
2519 | 2485 |
2520 TEST_F(PersonalDataManagerTest, DefaultCountryCodeComesFromProfiles) { | 2486 TEST_F(PersonalDataManagerTest, DefaultCountryCodeComesFromProfiles) { |
2521 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); | 2487 AutofillProfile moose(base::GenerateGUID(), "Chrome settings"); |
2522 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", | 2488 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", |
2523 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", | 2489 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", |
2524 "CA", "(800) 555-9000"); | 2490 "CA", "(800) 555-9000"); |
2525 personal_data_->AddProfile(moose); | 2491 personal_data_->AddProfile(moose); |
2526 ResetPersonalDataManager(); | 2492 ResetPersonalDataManager(false); |
2527 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2493 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2528 | 2494 |
2529 // Multiple profiles cast votes. | 2495 // Multiple profiles cast votes. |
2530 AutofillProfile armadillo(base::GenerateGUID(), "Chrome settings"); | 2496 AutofillProfile armadillo(base::GenerateGUID(), "Chrome settings"); |
2531 test::SetProfileInfo(&armadillo, "Armin", "Dill", "Oh", "ado@example.com", | 2497 test::SetProfileInfo(&armadillo, "Armin", "Dill", "Oh", "ado@example.com", |
2532 "", "1 Speed Bump", "", "Lubbock", "TX", "77500", | 2498 "", "1 Speed Bump", "", "Lubbock", "TX", "77500", |
2533 "MX", "(800) 555-9000"); | 2499 "MX", "(800) 555-9000"); |
2534 AutofillProfile armadillo2(base::GenerateGUID(), "Chrome settings"); | 2500 AutofillProfile armadillo2(base::GenerateGUID(), "Chrome settings"); |
2535 test::SetProfileInfo(&armadillo2, "Armin", "Dill", "Oh", "ado@example.com", | 2501 test::SetProfileInfo(&armadillo2, "Armin", "Dill", "Oh", "ado@example.com", |
2536 "", "2 Speed Bump", "", "Lubbock", "TX", "77500", | 2502 "", "2 Speed Bump", "", "Lubbock", "TX", "77500", |
2537 "MX", "(800) 555-9000"); | 2503 "MX", "(800) 555-9000"); |
2538 personal_data_->AddProfile(armadillo); | 2504 personal_data_->AddProfile(armadillo); |
2539 personal_data_->AddProfile(armadillo2); | 2505 personal_data_->AddProfile(armadillo2); |
2540 ResetPersonalDataManager(); | 2506 ResetPersonalDataManager(false); |
2541 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2507 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2542 | 2508 |
2543 personal_data_->RemoveByGUID(armadillo.guid()); | 2509 personal_data_->RemoveByGUID(armadillo.guid()); |
2544 personal_data_->RemoveByGUID(armadillo2.guid()); | 2510 personal_data_->RemoveByGUID(armadillo2.guid()); |
2545 ResetPersonalDataManager(); | 2511 ResetPersonalDataManager(false); |
2546 // Verified profiles count more. | 2512 // Verified profiles count more. |
2547 armadillo.set_origin("http://randomwebsite.com"); | 2513 armadillo.set_origin("http://randomwebsite.com"); |
2548 armadillo2.set_origin("http://randomwebsite.com"); | 2514 armadillo2.set_origin("http://randomwebsite.com"); |
2549 personal_data_->AddProfile(armadillo); | 2515 personal_data_->AddProfile(armadillo); |
2550 personal_data_->AddProfile(armadillo2); | 2516 personal_data_->AddProfile(armadillo2); |
2551 ResetPersonalDataManager(); | 2517 ResetPersonalDataManager(false); |
2552 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2518 EXPECT_EQ("CA", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2553 | 2519 |
2554 personal_data_->RemoveByGUID(armadillo.guid()); | 2520 personal_data_->RemoveByGUID(armadillo.guid()); |
2555 ResetPersonalDataManager(); | 2521 ResetPersonalDataManager(false); |
2556 // But unverified profiles can be a tie breaker. | 2522 // But unverified profiles can be a tie breaker. |
2557 armadillo.set_origin("Chrome settings"); | 2523 armadillo.set_origin("Chrome settings"); |
2558 personal_data_->AddProfile(armadillo); | 2524 personal_data_->AddProfile(armadillo); |
2559 ResetPersonalDataManager(); | 2525 ResetPersonalDataManager(false); |
2560 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2526 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2561 | 2527 |
2562 // Invalid country codes are ignored. | 2528 // Invalid country codes are ignored. |
2563 personal_data_->RemoveByGUID(armadillo.guid()); | 2529 personal_data_->RemoveByGUID(armadillo.guid()); |
2564 personal_data_->RemoveByGUID(moose.guid()); | 2530 personal_data_->RemoveByGUID(moose.guid()); |
2565 AutofillProfile space_invader(base::GenerateGUID(), "Chrome settings"); | 2531 AutofillProfile space_invader(base::GenerateGUID(), "Chrome settings"); |
2566 test::SetProfileInfo(&space_invader, "Marty", "", "Martian", | 2532 test::SetProfileInfo(&space_invader, "Marty", "", "Martian", |
2567 "mm@example.com", "", "1 Flying Object", "", "Valles Marineris", "", | 2533 "mm@example.com", "", "1 Flying Object", "", "Valles Marineris", "", |
2568 "", "XX", ""); | 2534 "", "XX", ""); |
2569 personal_data_->AddProfile(moose); | 2535 personal_data_->AddProfile(moose); |
2570 ResetPersonalDataManager(); | 2536 ResetPersonalDataManager(false); |
2571 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); | 2537 EXPECT_EQ("MX", personal_data_->GetDefaultCountryCodeForNewAddress()); |
2572 } | 2538 } |
2573 | 2539 |
2574 } // namespace autofill | 2540 } // namespace autofill |
OLD | NEW |