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

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

Issue 12695015: Split Autofill webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win build 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
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/web_data_service.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/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/test/base/thread_observer_helper.h" 27 #include "chrome/test/base/thread_observer_helper.h"
27 #include "components/autofill/browser/autofill_profile.h" 28 #include "components/autofill/browser/autofill_profile.h"
28 #include "components/autofill/browser/credit_card.h" 29 #include "components/autofill/browser/credit_card.h"
29 #include "components/autofill/common/form_field_data.h" 30 #include "components/autofill/common/form_field_data.h"
30 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
32 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
33 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 WebDataServiceTest() 71 WebDataServiceTest()
71 : ui_thread_(BrowserThread::UI, &message_loop_), 72 : ui_thread_(BrowserThread::UI, &message_loop_),
72 db_thread_(BrowserThread::DB) {} 73 db_thread_(BrowserThread::DB) {}
73 74
74 protected: 75 protected:
75 virtual void SetUp() { 76 virtual void SetUp() {
76 db_thread_.Start(); 77 db_thread_.Start();
77 78
78 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
79 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); 80 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB");
80 wds_ = new WebDataService(path, WebDataServiceBase::ProfileErrorCallback()); 81
81 // Need to add at least one table so the database gets created. 82 wdbs_ = new WebDatabaseService(path);
82 wds_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable).Pass()); 83 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable()));
84 wdbs_->LoadDatabase(WebDatabaseService::InitCallback());
85
86 wds_ = new WebDataService(wdbs_,
87 WebDataServiceBase::ProfileErrorCallback());
83 wds_->Init(); 88 wds_->Init();
84 } 89 }
85 90
86 virtual void TearDown() { 91 virtual void TearDown() {
87 wds_->ShutdownOnUIThread(); 92 wds_->ShutdownOnUIThread();
93 wdbs_->ShutdownDatabase();
88 wds_ = NULL; 94 wds_ = NULL;
95 wdbs_ = NULL;
89 WaitForDatabaseThread(); 96 WaitForDatabaseThread();
90 97
91 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 98 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
92 MessageLoop::current()->Run(); 99 MessageLoop::current()->Run();
93 db_thread_.Stop(); 100 db_thread_.Stop();
94 } 101 }
95 102
96 void WaitForDatabaseThread() { 103 void WaitForDatabaseThread() {
97 base::WaitableEvent done(false, false); 104 base::WaitableEvent done(false, false);
98 BrowserThread::PostTask( 105 BrowserThread::PostTask(
99 BrowserThread::DB, 106 BrowserThread::DB,
100 FROM_HERE, 107 FROM_HERE,
101 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 108 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
102 done.Wait(); 109 done.Wait();
103 } 110 }
104 111
105 MessageLoopForUI message_loop_; 112 MessageLoopForUI message_loop_;
106 content::TestBrowserThread ui_thread_; 113 content::TestBrowserThread ui_thread_;
107 content::TestBrowserThread db_thread_; 114 content::TestBrowserThread db_thread_;
108 base::FilePath profile_dir_; 115 base::FilePath profile_dir_;
109 scoped_refptr<WebDataService> wds_; 116 scoped_refptr<WebDataService> wds_;
117 scoped_refptr<WebDatabaseService> wdbs_;
110 base::ScopedTempDir temp_dir_; 118 base::ScopedTempDir temp_dir_;
111 }; 119 };
112 120
113 class WebDataServiceAutofillTest : public WebDataServiceTest { 121 class WebDataServiceAutofillTest : public WebDataServiceTest {
114 public: 122 public:
115 WebDataServiceAutofillTest() 123 WebDataServiceAutofillTest()
116 : WebDataServiceTest(), 124 : WebDataServiceTest(),
117 unique_id1_(1), 125 unique_id1_(1),
118 unique_id2_(2), 126 unique_id2_(2),
119 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)), 127 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)),
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 EXPECT_EQ(handle2, profile_consumer2.handle()); 550 EXPECT_EQ(handle2, profile_consumer2.handle());
543 ASSERT_EQ(0U, profile_consumer2.result().size()); 551 ASSERT_EQ(0U, profile_consumer2.result().size());
544 552
545 // Check that the credit card was removed. 553 // Check that the credit card was removed.
546 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; 554 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2;
547 handle2 = wds_->GetCreditCards(&card_consumer2); 555 handle2 = wds_->GetCreditCards(&card_consumer2);
548 MessageLoop::current()->Run(); 556 MessageLoop::current()->Run();
549 EXPECT_EQ(handle2, card_consumer2.handle()); 557 EXPECT_EQ(handle2, card_consumer2.handle());
550 ASSERT_EQ(0U, card_consumer2.result().size()); 558 ASSERT_EQ(0U, card_consumer2.result().size());
551 } 559 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service_test_util.cc ('k') | chrome/browser/webdata/web_database_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698