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

Side by Side Diff: components/autofill/browser/webdata/web_data_service_unittest.cc

Issue 16154031: Un-refcount AutofillWebData and TokenWebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on ToT Created 7 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
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"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 virtual void SetUp() { 69 virtual void SetUp() {
70 db_thread_.Start(); 70 db_thread_.Start();
71 71
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
73 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); 73 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB");
74 74
75 wdbs_ = new WebDatabaseService(path); 75 wdbs_ = new WebDatabaseService(path);
76 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); 76 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US")));
77 wdbs_->LoadDatabase(); 77 wdbs_->LoadDatabase();
78 78
79 wds_ = new AutofillWebDataService( 79 wds_.reset(new AutofillWebDataService(
80 wdbs_, WebDataServiceBase::ProfileErrorCallback()); 80 wdbs_, WebDataServiceBase::ProfileErrorCallback()));
81 wds_->Init(); 81 wds_->Init();
82 } 82 }
83 83
84 virtual void TearDown() { 84 virtual void TearDown() {
85 wds_->ShutdownOnUIThread(); 85 wds_->ShutdownOnUIThread();
86 wdbs_->ShutdownDatabase(); 86 wdbs_->ShutdownDatabase();
87 wds_ = NULL; 87 wds_.reset();
88 wdbs_ = NULL; 88 wdbs_ = NULL;
89 WaitForDatabaseThread(); 89 WaitForDatabaseThread();
90 90
91 base::MessageLoop::current()->PostTask(FROM_HERE, 91 base::MessageLoop::current()->PostTask(FROM_HERE,
92 base::MessageLoop::QuitClosure()); 92 base::MessageLoop::QuitClosure());
93 base::MessageLoop::current()->Run(); 93 base::MessageLoop::current()->Run();
94 db_thread_.Stop(); 94 db_thread_.Stop();
95 } 95 }
96 96
97 void WaitForDatabaseThread() { 97 void WaitForDatabaseThread() {
98 base::WaitableEvent done(false, false); 98 base::WaitableEvent done(false, false);
99 BrowserThread::PostTask( 99 BrowserThread::PostTask(
100 BrowserThread::DB, 100 BrowserThread::DB,
101 FROM_HERE, 101 FROM_HERE,
102 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 102 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
103 done.Wait(); 103 done.Wait();
104 } 104 }
105 105
106 base::MessageLoopForUI message_loop_; 106 base::MessageLoopForUI message_loop_;
107 content::TestBrowserThread ui_thread_; 107 content::TestBrowserThread ui_thread_;
108 content::TestBrowserThread db_thread_; 108 content::TestBrowserThread db_thread_;
109 base::FilePath profile_dir_; 109 base::FilePath profile_dir_;
110 scoped_refptr<AutofillWebDataService> wds_; 110 scoped_ptr<AutofillWebDataService> wds_;
111 scoped_refptr<WebDatabaseService> wdbs_; 111 scoped_refptr<WebDatabaseService> wdbs_;
112 base::ScopedTempDir temp_dir_; 112 base::ScopedTempDir temp_dir_;
113 }; 113 };
114 114
115 class WebDataServiceAutofillTest : public WebDataServiceTest { 115 class WebDataServiceAutofillTest : public WebDataServiceTest {
116 public: 116 public:
117 WebDataServiceAutofillTest() 117 WebDataServiceAutofillTest()
118 : WebDataServiceTest(), 118 : WebDataServiceTest(),
119 unique_id1_(1), 119 unique_id1_(1),
120 unique_id2_(2), 120 unique_id2_(2),
121 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)), 121 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)),
122 done_event_(false, false) {} 122 done_event_(false, false) {}
123 123
124 protected: 124 protected:
125 virtual void SetUp() { 125 virtual void SetUp() {
126 WebDataServiceTest::SetUp(); 126 WebDataServiceTest::SetUp();
127 name1_ = ASCIIToUTF16("name1"); 127 name1_ = ASCIIToUTF16("name1");
128 name2_ = ASCIIToUTF16("name2"); 128 name2_ = ASCIIToUTF16("name2");
129 value1_ = ASCIIToUTF16("value1"); 129 value1_ = ASCIIToUTF16("value1");
130 value2_ = ASCIIToUTF16("value2"); 130 value2_ = ASCIIToUTF16("value2");
131 131
132 void(AutofillWebDataService::*add_observer_func)( 132 void(AutofillWebDataService::*add_observer_func)(
133 AutofillWebDataServiceObserverOnDBThread*) = 133 AutofillWebDataServiceObserverOnDBThread*) =
134 &AutofillWebDataService::AddObserver; 134 &AutofillWebDataService::AddObserver;
135 BrowserThread::PostTask( 135 BrowserThread::PostTask(
136 BrowserThread::DB, 136 BrowserThread::DB,
137 FROM_HERE, 137 FROM_HERE,
138 base::Bind(add_observer_func, wds_, &observer_)); 138 base::Bind(add_observer_func,
139 base::Unretained(wds_.get()), &observer_));
139 WaitForDatabaseThread(); 140 WaitForDatabaseThread();
140 } 141 }
141 142
142 virtual void TearDown() { 143 virtual void TearDown() {
143 void(AutofillWebDataService::*remove_observer_func)( 144 void(AutofillWebDataService::*remove_observer_func)(
144 AutofillWebDataServiceObserverOnDBThread*) = 145 AutofillWebDataServiceObserverOnDBThread*) =
145 &AutofillWebDataService::RemoveObserver; 146 &AutofillWebDataService::RemoveObserver;
146 BrowserThread::PostTask( 147 BrowserThread::PostTask(
147 BrowserThread::DB, 148 BrowserThread::DB,
148 FROM_HERE, 149 FROM_HERE,
149 base::Bind(remove_observer_func, wds_, &observer_)); 150 base::Bind(remove_observer_func,
151 base::Unretained(wds_.get()), &observer_));
150 WaitForDatabaseThread(); 152 WaitForDatabaseThread();
151 153
152 WebDataServiceTest::TearDown(); 154 WebDataServiceTest::TearDown();
153 } 155 }
154 156
155 void AppendFormField(const base::string16& name, 157 void AppendFormField(const base::string16& name,
156 const base::string16& value, 158 const base::string16& value,
157 std::vector<FormFieldData>* form_fields) { 159 std::vector<FormFieldData>* form_fields) {
158 FormFieldData field; 160 FormFieldData field;
159 field.name = name; 161 field.name = name;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 530
529 // Check that the credit card was removed. 531 // Check that the credit card was removed.
530 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; 532 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2;
531 handle2 = wds_->GetCreditCards(&card_consumer2); 533 handle2 = wds_->GetCreditCards(&card_consumer2);
532 base::MessageLoop::current()->Run(); 534 base::MessageLoop::current()->Run();
533 EXPECT_EQ(handle2, card_consumer2.handle()); 535 EXPECT_EQ(handle2, card_consumer2.handle());
534 ASSERT_EQ(0U, card_consumer2.result().size()); 536 ASSERT_EQ(0U, card_consumer2.result().size());
535 } 537 }
536 538
537 } // namespace autofill 539 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/webdata/autofill_webdata_service.h ('k') | components/webdata/common/web_data_service_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698