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

Side by Side Diff: components/autofill/core/browser/webdata/autofill_data_type_controller_unittest.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 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
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 "components/autofill/core/browser/webdata/autofill_data_type_controller .h" 5 #include "components/autofill/core/browser/webdata/autofill_data_type_controller .h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; 106 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_;
107 base::Callback<void(void)> db_loaded_callback_; 107 base::Callback<void(void)> db_loaded_callback_;
108 108
109 DISALLOW_COPY_AND_ASSIGN(FakeWebDataService); 109 DISALLOW_COPY_AND_ASSIGN(FakeWebDataService);
110 }; 110 };
111 111
112 class SyncAutofillDataTypeControllerTest : public testing::Test { 112 class SyncAutofillDataTypeControllerTest : public testing::Test {
113 public: 113 public:
114 SyncAutofillDataTypeControllerTest() 114 SyncAutofillDataTypeControllerTest()
115 : db_thread_("DB_Thread"), 115 : db_thread_("DB_Thread"),
116 last_start_result_(sync_driver::DataTypeController::OK), 116 last_start_result_(syncer::DataTypeController::OK),
117 weak_ptr_factory_(this) {} 117 weak_ptr_factory_(this) {}
118 ~SyncAutofillDataTypeControllerTest() override {} 118 ~SyncAutofillDataTypeControllerTest() override {}
119 119
120 void SetUp() override { 120 void SetUp() override {
121 db_thread_.Start(); 121 db_thread_.Start();
122 web_data_service_ = new FakeWebDataService( 122 web_data_service_ = new FakeWebDataService(
123 base::ThreadTaskRunnerHandle::Get(), db_thread_.task_runner()); 123 base::ThreadTaskRunnerHandle::Get(), db_thread_.task_runner());
124 autofill_dtc_ = base::MakeUnique<AutofillDataTypeController>( 124 autofill_dtc_ = base::MakeUnique<AutofillDataTypeController>(
125 db_thread_.task_runner(), base::Bind(&base::DoNothing), &sync_client_, 125 db_thread_.task_runner(), base::Bind(&base::DoNothing), &sync_client_,
126 web_data_service_); 126 web_data_service_);
127 } 127 }
128 128
129 void TearDown() override { 129 void TearDown() override {
130 web_data_service_->ShutdownOnUIThread(); 130 web_data_service_->ShutdownOnUIThread();
131 131
132 // Make sure WebDataService is shutdown properly on DB thread before we 132 // Make sure WebDataService is shutdown properly on DB thread before we
133 // destroy it. 133 // destroy it.
134 base::RunLoop run_loop; 134 base::RunLoop run_loop;
135 ASSERT_TRUE(db_thread_.task_runner()->PostTaskAndReply( 135 ASSERT_TRUE(db_thread_.task_runner()->PostTaskAndReply(
136 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure())); 136 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure()));
137 run_loop.Run(); 137 run_loop.Run();
138 } 138 }
139 139
140 // Passed to AutofillDTC::Start(). 140 // Passed to AutofillDTC::Start().
141 void OnStartFinished(sync_driver::DataTypeController::ConfigureResult result, 141 void OnStartFinished(syncer::DataTypeController::ConfigureResult result,
142 const syncer::SyncMergeResult& local_merge_result, 142 const syncer::SyncMergeResult& local_merge_result,
143 const syncer::SyncMergeResult& syncer_merge_result) { 143 const syncer::SyncMergeResult& syncer_merge_result) {
144 last_start_result_ = result; 144 last_start_result_ = result;
145 last_start_error_ = local_merge_result.error(); 145 last_start_error_ = local_merge_result.error();
146 } 146 }
147 147
148 void OnLoadFinished(syncer::ModelType type, const syncer::SyncError& error) { 148 void OnLoadFinished(syncer::ModelType type, const syncer::SyncError& error) {
149 EXPECT_FALSE(error.IsSet()); 149 EXPECT_FALSE(error.IsSet());
150 EXPECT_EQ(type, syncer::AUTOFILL); 150 EXPECT_EQ(type, syncer::AUTOFILL);
151 } 151 }
152 152
153 void BlockForDBThread() { 153 void BlockForDBThread() {
154 base::RunLoop run_loop; 154 base::RunLoop run_loop;
155 ASSERT_TRUE(db_thread_.task_runner()->PostTaskAndReply( 155 ASSERT_TRUE(db_thread_.task_runner()->PostTaskAndReply(
156 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure())); 156 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure()));
157 run_loop.Run(); 157 run_loop.Run();
158 } 158 }
159 159
160 protected: 160 protected:
161 base::MessageLoop message_loop_; 161 base::MessageLoop message_loop_;
162 base::Thread db_thread_; 162 base::Thread db_thread_;
163 sync_driver::FakeSyncClient sync_client_; 163 syncer::FakeSyncClient sync_client_;
164 std::unique_ptr<AutofillDataTypeController> autofill_dtc_; 164 std::unique_ptr<AutofillDataTypeController> autofill_dtc_;
165 scoped_refptr<FakeWebDataService> web_data_service_; 165 scoped_refptr<FakeWebDataService> web_data_service_;
166 166
167 // Stores arguments of most recent call of OnStartFinished(). 167 // Stores arguments of most recent call of OnStartFinished().
168 sync_driver::DataTypeController::ConfigureResult last_start_result_; 168 syncer::DataTypeController::ConfigureResult last_start_result_;
169 syncer::SyncError last_start_error_; 169 syncer::SyncError last_start_error_;
170 base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_; 170 base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_;
171 }; 171 };
172 172
173 // Load the WDS's database, then start the Autofill DTC. It should 173 // Load the WDS's database, then start the Autofill DTC. It should
174 // immediately try to start association and fail (due to missing DB 174 // immediately try to start association and fail (due to missing DB
175 // thread). 175 // thread).
176 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSReady) { 176 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSReady) {
177 web_data_service_->LoadDatabase(); 177 web_data_service_->LoadDatabase();
178 autofill_dtc_->LoadModels( 178 autofill_dtc_->LoadModels(
179 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished, 179 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished,
180 weak_ptr_factory_.GetWeakPtr())); 180 weak_ptr_factory_.GetWeakPtr()));
181 181
182 autofill_dtc_->StartAssociating( 182 autofill_dtc_->StartAssociating(
183 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished, 183 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished,
184 weak_ptr_factory_.GetWeakPtr())); 184 weak_ptr_factory_.GetWeakPtr()));
185 BlockForDBThread(); 185 BlockForDBThread();
186 186
187 EXPECT_EQ(sync_driver::DataTypeController::ASSOCIATION_FAILED, 187 EXPECT_EQ(syncer::DataTypeController::ASSOCIATION_FAILED, last_start_result_);
188 last_start_result_);
189 EXPECT_TRUE(last_start_error_.IsSet()); 188 EXPECT_TRUE(last_start_error_.IsSet());
190 EXPECT_EQ(sync_driver::DataTypeController::DISABLED, autofill_dtc_->state()); 189 EXPECT_EQ(syncer::DataTypeController::DISABLED, autofill_dtc_->state());
191 } 190 }
192 191
193 // Start the autofill DTC without the WDS's database loaded, then 192 // Start the autofill DTC without the WDS's database loaded, then
194 // start the DB. The Autofill DTC should be in the MODEL_STARTING 193 // start the DB. The Autofill DTC should be in the MODEL_STARTING
195 // state until the database in loaded, when it should try to start 194 // state until the database in loaded, when it should try to start
196 // association and fail (due to missing DB thread). 195 // association and fail (due to missing DB thread).
197 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) { 196 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) {
198 autofill_dtc_->LoadModels( 197 autofill_dtc_->LoadModels(
199 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished, 198 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished,
200 weak_ptr_factory_.GetWeakPtr())); 199 weak_ptr_factory_.GetWeakPtr()));
201 200
202 EXPECT_EQ(sync_driver::DataTypeController::OK, last_start_result_); 201 EXPECT_EQ(syncer::DataTypeController::OK, last_start_result_);
203 EXPECT_FALSE(last_start_error_.IsSet()); 202 EXPECT_FALSE(last_start_error_.IsSet());
204 EXPECT_EQ(sync_driver::DataTypeController::MODEL_STARTING, 203 EXPECT_EQ(syncer::DataTypeController::MODEL_STARTING, autofill_dtc_->state());
205 autofill_dtc_->state());
206 204
207 web_data_service_->LoadDatabase(); 205 web_data_service_->LoadDatabase();
208 206
209 autofill_dtc_->StartAssociating( 207 autofill_dtc_->StartAssociating(
210 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished, 208 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished,
211 weak_ptr_factory_.GetWeakPtr())); 209 weak_ptr_factory_.GetWeakPtr()));
212 BlockForDBThread(); 210 BlockForDBThread();
213 211
214 EXPECT_EQ(sync_driver::DataTypeController::ASSOCIATION_FAILED, 212 EXPECT_EQ(syncer::DataTypeController::ASSOCIATION_FAILED, last_start_result_);
215 last_start_result_);
216 EXPECT_TRUE(last_start_error_.IsSet()); 213 EXPECT_TRUE(last_start_error_.IsSet());
217 214
218 EXPECT_EQ(sync_driver::DataTypeController::DISABLED, autofill_dtc_->state()); 215 EXPECT_EQ(syncer::DataTypeController::DISABLED, autofill_dtc_->state());
219 } 216 }
220 217
221 } // namespace 218 } // namespace
222 219
223 } // namespace browser_sync 220 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698