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

Side by Side Diff: chrome/browser/webdata/web_data_service_unittest.cc

Issue 12987023: Rip autofill code out of webdataservice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change method name in AutofillTable Created 7 years, 9 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 | « chrome/browser/webdata/web_data_service_test_util.cc ('k') | no next file » | 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) 2012 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 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/webdata/autofill_change.h" 20 #include "chrome/browser/webdata/autofill_change.h"
21 #include "chrome/browser/webdata/autofill_entry.h" 21 #include "chrome/browser/webdata/autofill_entry.h"
22 #include "chrome/browser/webdata/autofill_table.h" 22 #include "chrome/browser/webdata/autofill_table.h"
23 #include "chrome/browser/webdata/web_data_service.h" 23 #include "chrome/browser/webdata/autofill_web_data_service_impl.h"
24 #include "chrome/browser/webdata/web_data_service_test_util.h" 24 #include "chrome/browser/webdata/web_data_service_test_util.h"
25 #include "chrome/browser/webdata/web_database_service.h" 25 #include "chrome/browser/webdata/web_database_service.h"
26 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/test/base/thread_observer_helper.h" 27 #include "chrome/test/base/thread_observer_helper.h"
28 #include "components/autofill/browser/autofill_profile.h" 28 #include "components/autofill/browser/autofill_profile.h"
29 #include "components/autofill/browser/credit_card.h" 29 #include "components/autofill/browser/credit_card.h"
30 #include "components/autofill/common/form_field_data.h" 30 #include "components/autofill/common/form_field_data.h"
31 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 virtual void SetUp() { 76 virtual void SetUp() {
77 db_thread_.Start(); 77 db_thread_.Start();
78 78
79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
80 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); 80 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB");
81 81
82 wdbs_ = new WebDatabaseService(path); 82 wdbs_ = new WebDatabaseService(path);
83 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable())); 83 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable()));
84 wdbs_->LoadDatabase(WebDatabaseService::InitCallback()); 84 wdbs_->LoadDatabase(WebDatabaseService::InitCallback());
85 85
86 wds_ = new WebDataService(wdbs_, 86 wds_ = new AutofillWebDataServiceImpl(wdbs_,
87 WebDataServiceBase::ProfileErrorCallback()); 87 WebDataServiceBase::ProfileErrorCallback());
88 wds_->Init(); 88 wds_->Init();
89 } 89 }
90 90
91 virtual void TearDown() { 91 virtual void TearDown() {
92 wds_->ShutdownOnUIThread(); 92 wds_->ShutdownOnUIThread();
93 wdbs_->ShutdownDatabase(); 93 wdbs_->ShutdownDatabase();
94 wds_ = NULL; 94 wds_ = NULL;
95 wdbs_ = NULL; 95 wdbs_ = NULL;
96 WaitForDatabaseThread(); 96 WaitForDatabaseThread();
97 97
98 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 98 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
99 MessageLoop::current()->Run(); 99 MessageLoop::current()->Run();
100 db_thread_.Stop(); 100 db_thread_.Stop();
101 } 101 }
102 102
103 void WaitForDatabaseThread() { 103 void WaitForDatabaseThread() {
104 base::WaitableEvent done(false, false); 104 base::WaitableEvent done(false, false);
105 BrowserThread::PostTask( 105 BrowserThread::PostTask(
106 BrowserThread::DB, 106 BrowserThread::DB,
107 FROM_HERE, 107 FROM_HERE,
108 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 108 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
109 done.Wait(); 109 done.Wait();
110 } 110 }
111 111
112 MessageLoopForUI message_loop_; 112 MessageLoopForUI message_loop_;
113 content::TestBrowserThread ui_thread_; 113 content::TestBrowserThread ui_thread_;
114 content::TestBrowserThread db_thread_; 114 content::TestBrowserThread db_thread_;
115 base::FilePath profile_dir_; 115 base::FilePath profile_dir_;
116 scoped_refptr<WebDataService> wds_; 116 scoped_refptr<AutofillWebDataService> wds_;
117 scoped_refptr<WebDatabaseService> wdbs_; 117 scoped_refptr<WebDatabaseService> wdbs_;
118 base::ScopedTempDir temp_dir_; 118 base::ScopedTempDir temp_dir_;
119 }; 119 };
120 120
121 class WebDataServiceAutofillTest : public WebDataServiceTest { 121 class WebDataServiceAutofillTest : public WebDataServiceTest {
122 public: 122 public:
123 WebDataServiceAutofillTest() 123 WebDataServiceAutofillTest()
124 : WebDataServiceTest(), 124 : WebDataServiceTest(),
125 unique_id1_(1), 125 unique_id1_(1),
126 unique_id2_(2), 126 unique_id2_(2),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const AutofillChange expected_changes[] = { 194 const AutofillChange expected_changes[] = {
195 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), 195 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)),
196 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) 196 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_))
197 }; 197 };
198 198
199 // This will verify that the correct notification is triggered, 199 // This will verify that the correct notification is triggered,
200 // passing the correct list of autofill keys in the details. 200 // passing the correct list of autofill keys in the details.
201 EXPECT_CALL( 201 EXPECT_CALL(
202 *observer_helper_->observer(), 202 *observer_helper_->observer(),
203 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), 203 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED),
204 content::Source<WebDataService>(wds_.get()), 204 content::Source<AutofillWebDataService>(wds_.get()),
205 Property(&content::Details<const AutofillChangeList>::ptr, 205 Property(&content::Details<const AutofillChangeList>::ptr,
206 Pointee(ElementsAreArray(expected_changes))))). 206 Pointee(ElementsAreArray(expected_changes))))).
207 WillOnce(SignalEvent(&done_event_)); 207 WillOnce(SignalEvent(&done_event_));
208 208
209 std::vector<FormFieldData> form_fields; 209 std::vector<FormFieldData> form_fields;
210 AppendFormField(name1_, value1_, &form_fields); 210 AppendFormField(name1_, value1_, &form_fields);
211 AppendFormField(name2_, value2_, &form_fields); 211 AppendFormField(name2_, value2_, &form_fields);
212 wds_->AddFormFields(form_fields); 212 wds_->AddFormFields(form_fields);
213 213
214 // The event will be signaled when the mock observer is notified. 214 // The event will be signaled when the mock observer is notified.
(...skipping 25 matching lines...) Expand all
240 done_event_.TimedWait(test_timeout_); 240 done_event_.TimedWait(test_timeout_);
241 241
242 // This will verify that the correct notification is triggered, 242 // This will verify that the correct notification is triggered,
243 // passing the correct list of autofill keys in the details. 243 // passing the correct list of autofill keys in the details.
244 const AutofillChange expected_changes[] = { 244 const AutofillChange expected_changes[] = {
245 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) 245 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_))
246 }; 246 };
247 EXPECT_CALL( 247 EXPECT_CALL(
248 *observer_helper_->observer(), 248 *observer_helper_->observer(),
249 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), 249 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED),
250 content::Source<WebDataService>(wds_.get()), 250 content::Source<AutofillWebDataService>(wds_.get()),
251 Property(&content::Details<const AutofillChangeList>::ptr, 251 Property(&content::Details<const AutofillChangeList>::ptr,
252 Pointee(ElementsAreArray(expected_changes))))). 252 Pointee(ElementsAreArray(expected_changes))))).
253 WillOnce(SignalEvent(&done_event_)); 253 WillOnce(SignalEvent(&done_event_));
254 wds_->RemoveFormValueForElementName(name1_, value1_); 254 wds_->RemoveFormValueForElementName(name1_, value1_);
255 255
256 // The event will be signaled when the mock observer is notified. 256 // The event will be signaled when the mock observer is notified.
257 done_event_.TimedWait(test_timeout_); 257 done_event_.TimedWait(test_timeout_);
258 } 258 }
259 259
260 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { 260 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) {
(...skipping 12 matching lines...) Expand all
273 273
274 // This will verify that the correct notification is triggered, 274 // This will verify that the correct notification is triggered,
275 // passing the correct list of autofill keys in the details. 275 // passing the correct list of autofill keys in the details.
276 const AutofillChange expected_changes[] = { 276 const AutofillChange expected_changes[] = {
277 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)), 277 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)),
278 AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_)) 278 AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_))
279 }; 279 };
280 EXPECT_CALL( 280 EXPECT_CALL(
281 *observer_helper_->observer(), 281 *observer_helper_->observer(),
282 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), 282 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED),
283 content::Source<WebDataService>(wds_.get()), 283 content::Source<AutofillWebDataService>(wds_.get()),
284 Property(&content::Details<const AutofillChangeList>::ptr, 284 Property(&content::Details<const AutofillChangeList>::ptr,
285 Pointee(ElementsAreArray(expected_changes))))). 285 Pointee(ElementsAreArray(expected_changes))))).
286 WillOnce(SignalEvent(&done_event_)); 286 WillOnce(SignalEvent(&done_event_));
287 wds_->RemoveFormElementsAddedBetween(t, t + one_day); 287 wds_->RemoveFormElementsAddedBetween(t, t + one_day);
288 288
289 // The event will be signaled when the mock observer is notified. 289 // The event will be signaled when the mock observer is notified.
290 done_event_.TimedWait(test_timeout_); 290 done_event_.TimedWait(test_timeout_);
291 } 291 }
292 292
293 TEST_F(WebDataServiceAutofillTest, ProfileAdd) { 293 TEST_F(WebDataServiceAutofillTest, ProfileAdd) {
294 AutofillProfile profile; 294 AutofillProfile profile;
295 295
296 // Check that GUID-based notification was sent. 296 // Check that GUID-based notification was sent.
297 const AutofillProfileChange expected_change( 297 const AutofillProfileChange expected_change(
298 AutofillProfileChange::ADD, profile.guid(), &profile); 298 AutofillProfileChange::ADD, profile.guid(), &profile);
299 EXPECT_CALL( 299 EXPECT_CALL(
300 *observer_helper_->observer(), 300 *observer_helper_->observer(),
301 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), 301 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
302 content::Source<WebDataService>(wds_.get()), 302 content::Source<AutofillWebDataService>(wds_.get()),
303 Property(&content::Details<const AutofillProfileChange>::ptr, 303 Property(&content::Details<const AutofillProfileChange>::ptr,
304 Pointee(expected_change)))). 304 Pointee(expected_change)))).
305 WillOnce(SignalEvent(&done_event_)); 305 WillOnce(SignalEvent(&done_event_));
306 306
307 wds_->AddAutofillProfile(profile); 307 wds_->AddAutofillProfile(profile);
308 done_event_.TimedWait(test_timeout_); 308 done_event_.TimedWait(test_timeout_);
309 309
310 // Check that it was added. 310 // Check that it was added.
311 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; 311 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer;
312 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); 312 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer);
(...skipping 22 matching lines...) Expand all
335 ASSERT_EQ(1U, consumer.result().size()); 335 ASSERT_EQ(1U, consumer.result().size());
336 EXPECT_EQ(profile, *consumer.result()[0]); 336 EXPECT_EQ(profile, *consumer.result()[0]);
337 STLDeleteElements(&consumer.result()); 337 STLDeleteElements(&consumer.result());
338 338
339 // Check that GUID-based notification was sent. 339 // Check that GUID-based notification was sent.
340 const AutofillProfileChange expected_change( 340 const AutofillProfileChange expected_change(
341 AutofillProfileChange::REMOVE, profile.guid(), NULL); 341 AutofillProfileChange::REMOVE, profile.guid(), NULL);
342 EXPECT_CALL( 342 EXPECT_CALL(
343 *observer_helper_->observer(), 343 *observer_helper_->observer(),
344 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), 344 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
345 content::Source<WebDataService>(wds_.get()), 345 content::Source<AutofillWebDataService>(wds_.get()),
346 Property(&content::Details<const AutofillProfileChange>::ptr, 346 Property(&content::Details<const AutofillProfileChange>::ptr,
347 Pointee(expected_change)))). 347 Pointee(expected_change)))).
348 WillOnce(SignalEvent(&done_event_)); 348 WillOnce(SignalEvent(&done_event_));
349 349
350 // Remove the profile. 350 // Remove the profile.
351 wds_->RemoveAutofillProfile(profile.guid()); 351 wds_->RemoveAutofillProfile(profile.guid());
352 done_event_.TimedWait(test_timeout_); 352 done_event_.TimedWait(test_timeout_);
353 353
354 // Check that it was removed. 354 // Check that it was removed.
355 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; 355 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2;
(...skipping 27 matching lines...) Expand all
383 STLDeleteElements(&consumer.result()); 383 STLDeleteElements(&consumer.result());
384 384
385 AutofillProfile profile1_changed(profile1); 385 AutofillProfile profile1_changed(profile1);
386 profile1_changed.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bill")); 386 profile1_changed.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bill"));
387 const AutofillProfileChange expected_change( 387 const AutofillProfileChange expected_change(
388 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); 388 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed);
389 389
390 EXPECT_CALL( 390 EXPECT_CALL(
391 *observer_helper_->observer(), 391 *observer_helper_->observer(),
392 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), 392 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
393 content::Source<WebDataService>(wds_.get()), 393 content::Source<AutofillWebDataService>(wds_.get()),
394 Property(&content::Details<const AutofillProfileChange>::ptr, 394 Property(&content::Details<const AutofillProfileChange>::ptr,
395 Pointee(expected_change)))). 395 Pointee(expected_change)))).
396 WillOnce(SignalEvent(&done_event_)); 396 WillOnce(SignalEvent(&done_event_));
397 397
398 // Update the profile. 398 // Update the profile.
399 wds_->UpdateAutofillProfile(profile1_changed); 399 wds_->UpdateAutofillProfile(profile1_changed);
400 done_event_.TimedWait(test_timeout_); 400 done_event_.TimedWait(test_timeout_);
401 401
402 // Check that the updates were made. 402 // Check that the updates were made.
403 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; 403 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 ASSERT_EQ(1U, card_consumer.result().size()); 524 ASSERT_EQ(1U, card_consumer.result().size());
525 EXPECT_EQ(credit_card, *card_consumer.result()[0]); 525 EXPECT_EQ(credit_card, *card_consumer.result()[0]);
526 STLDeleteElements(&card_consumer.result()); 526 STLDeleteElements(&card_consumer.result());
527 527
528 // Check that GUID-based notification was sent for the profile. 528 // Check that GUID-based notification was sent for the profile.
529 const AutofillProfileChange expected_profile_change( 529 const AutofillProfileChange expected_profile_change(
530 AutofillProfileChange::REMOVE, profile.guid(), NULL); 530 AutofillProfileChange::REMOVE, profile.guid(), NULL);
531 EXPECT_CALL( 531 EXPECT_CALL(
532 *observer_helper_->observer(), 532 *observer_helper_->observer(),
533 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), 533 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
534 content::Source<WebDataService>(wds_.get()), 534 content::Source<AutofillWebDataService>(wds_.get()),
535 Property(&content::Details<const AutofillProfileChange>::ptr, 535 Property(&content::Details<const AutofillProfileChange>::ptr,
536 Pointee(expected_profile_change)))). 536 Pointee(expected_profile_change)))).
537 WillOnce(SignalEvent(&done_event_)); 537 WillOnce(SignalEvent(&done_event_));
538 538
539 // Remove the profile using time range of "all time". 539 // Remove the profile using time range of "all time".
540 wds_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(Time(), Time()); 540 wds_->RemoveAutofillDataModifiedBetween(Time(), Time());
541 done_event_.TimedWait(test_timeout_); 541 done_event_.TimedWait(test_timeout_);
542 WaitForDatabaseThread(); 542 WaitForDatabaseThread();
543 543
544 // Check that the profile was removed. 544 // Check that the profile was removed.
545 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > 545 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> >
546 profile_consumer2; 546 profile_consumer2;
547 WebDataService::Handle handle2 = 547 WebDataService::Handle handle2 =
548 wds_->GetAutofillProfiles(&profile_consumer2); 548 wds_->GetAutofillProfiles(&profile_consumer2);
549 MessageLoop::current()->Run(); 549 MessageLoop::current()->Run();
550 EXPECT_EQ(handle2, profile_consumer2.handle()); 550 EXPECT_EQ(handle2, profile_consumer2.handle());
551 ASSERT_EQ(0U, profile_consumer2.result().size()); 551 ASSERT_EQ(0U, profile_consumer2.result().size());
552 552
553 // Check that the credit card was removed. 553 // Check that the credit card was removed.
554 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; 554 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2;
555 handle2 = wds_->GetCreditCards(&card_consumer2); 555 handle2 = wds_->GetCreditCards(&card_consumer2);
556 MessageLoop::current()->Run(); 556 MessageLoop::current()->Run();
557 EXPECT_EQ(handle2, card_consumer2.handle()); 557 EXPECT_EQ(handle2, card_consumer2.handle());
558 ASSERT_EQ(0U, card_consumer2.result().size()); 558 ASSERT_EQ(0U, card_consumer2.result().size());
559 } 559 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698