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

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

Issue 14081043: Hook up Autofill Backend interface to SyncableServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 "components/autofill/browser/autofill_country.h" 20 #include "components/autofill/browser/autofill_country.h"
21 #include "components/autofill/browser/autofill_profile.h" 21 #include "components/autofill/browser/autofill_profile.h"
22 #include "components/autofill/browser/credit_card.h" 22 #include "components/autofill/browser/credit_card.h"
23 #include "components/autofill/browser/webdata/autofill_backend_delegate.h"
23 #include "components/autofill/browser/webdata/autofill_change.h" 24 #include "components/autofill/browser/webdata/autofill_change.h"
24 #include "components/autofill/browser/webdata/autofill_entry.h" 25 #include "components/autofill/browser/webdata/autofill_entry.h"
25 #include "components/autofill/browser/webdata/autofill_table.h" 26 #include "components/autofill/browser/webdata/autofill_table.h"
26 #include "components/autofill/browser/webdata/autofill_webdata_service.h" 27 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
27 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h" 28 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h"
28 #include "components/autofill/common/form_field_data.h" 29 #include "components/autofill/common/form_field_data.h"
29 #include "components/webdata/common/web_data_service_test_util.h" 30 #include "components/webdata/common/web_data_service_test_util.h"
30 #include "components/webdata/common/web_database_service.h" 31 #include "components/webdata/common/web_database_service.h"
31 #include "content/public/test/test_browser_thread.h" 32 #include "content/public/test/test_browser_thread.h"
32 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 done_event_(false, false) {} 122 done_event_(false, false) {}
122 123
123 protected: 124 protected:
124 virtual void SetUp() { 125 virtual void SetUp() {
125 WebDataServiceTest::SetUp(); 126 WebDataServiceTest::SetUp();
126 name1_ = ASCIIToUTF16("name1"); 127 name1_ = ASCIIToUTF16("name1");
127 name2_ = ASCIIToUTF16("name2"); 128 name2_ = ASCIIToUTF16("name2");
128 value1_ = ASCIIToUTF16("value1"); 129 value1_ = ASCIIToUTF16("value1");
129 value2_ = ASCIIToUTF16("value2"); 130 value2_ = ASCIIToUTF16("value2");
130 131
131 void(AutofillWebDataService::*add_observer_func)( 132 wds_->GetDelegateOnDB(
132 AutofillWebDataServiceObserverOnDBThread*) = 133 base::Bind(&WebDataServiceAutofillTest::OnGetDelegate,
133 &AutofillWebDataService::AddObserver; 134 base::Unretained(this)));
134 BrowserThread::PostTask(
135 BrowserThread::DB,
136 FROM_HERE,
137 base::Bind(add_observer_func, wds_, &observer_));
138 WaitForDatabaseThread(); 135 WaitForDatabaseThread();
139 } 136 }
140 137
141 virtual void TearDown() { 138 virtual void TearDown() {
142 void(AutofillWebDataService::*remove_observer_func)(
143 AutofillWebDataServiceObserverOnDBThread*) =
144 &AutofillWebDataService::RemoveObserver;
145 BrowserThread::PostTask( 139 BrowserThread::PostTask(
146 BrowserThread::DB, 140 BrowserThread::DB,
147 FROM_HERE, 141 FROM_HERE,
148 base::Bind(remove_observer_func, wds_, &observer_)); 142 base::Bind(&WebDataServiceAutofillTest::ClearDelegate,
143 base::Unretained(this)));
149 WaitForDatabaseThread(); 144 WaitForDatabaseThread();
150 145
151 WebDataServiceTest::TearDown(); 146 WebDataServiceTest::TearDown();
152 } 147 }
153 148
154 void AppendFormField(const base::string16& name, 149 void AppendFormField(const base::string16& name,
155 const base::string16& value, 150 const base::string16& value,
156 std::vector<FormFieldData>* form_fields) { 151 std::vector<FormFieldData>* form_fields) {
157 FormFieldData field; 152 FormFieldData field;
158 field.name = name; 153 field.name = name;
159 field.value = value; 154 field.value = value;
160 form_fields->push_back(field); 155 form_fields->push_back(field);
161 } 156 }
162 157
158 void OnGetDelegate(AutofillBackendDelegate* delegate) {
159 delegate_ = delegate;
160 delegate_->AddObserver(&observer_);
161 }
162
163 void ClearDelegate() {
164 delegate_->RemoveObserver(&observer_);
165 delegate_ = NULL;
166 }
167
163 base::string16 name1_; 168 base::string16 name1_;
164 base::string16 name2_; 169 base::string16 name2_;
165 base::string16 value1_; 170 base::string16 value1_;
166 base::string16 value2_; 171 base::string16 value2_;
167 int unique_id1_, unique_id2_; 172 int unique_id1_, unique_id2_;
168 const TimeDelta test_timeout_; 173 const TimeDelta test_timeout_;
169 testing::NiceMock<MockAutofillWebDataServiceObserver> observer_; 174 testing::NiceMock<MockAutofillWebDataServiceObserver> observer_;
175 AutofillBackendDelegate* delegate_;
170 WaitableEvent done_event_; 176 WaitableEvent done_event_;
171 }; 177 };
172 178
173 // Simple consumer for Keywords data. Stores the result data and quits UI 179 // Simple consumer for Keywords data. Stores the result data and quits UI
174 // message loop when callback is invoked. 180 // message loop when callback is invoked.
175 class KeywordsConsumer : public WebDataServiceConsumer { 181 class KeywordsConsumer : public WebDataServiceConsumer {
176 public: 182 public:
177 KeywordsConsumer() : load_succeeded(false) {} 183 KeywordsConsumer() : load_succeeded(false) {}
178 184
179 virtual void OnWebDataServiceRequestDone( 185 virtual void OnWebDataServiceRequestDone(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 533
528 // Check that the credit card was removed. 534 // Check that the credit card was removed.
529 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; 535 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2;
530 handle2 = wds_->GetCreditCards(&card_consumer2); 536 handle2 = wds_->GetCreditCards(&card_consumer2);
531 MessageLoop::current()->Run(); 537 MessageLoop::current()->Run();
532 EXPECT_EQ(handle2, card_consumer2.handle()); 538 EXPECT_EQ(handle2, card_consumer2.handle());
533 ASSERT_EQ(0U, card_consumer2.result().size()); 539 ASSERT_EQ(0U, card_consumer2.result().size());
534 } 540 }
535 541
536 } // namespace autofill 542 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698