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

Side by Side Diff: components/sync_driver/non_ui_data_type_controller_unittest.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sync_driver/non_ui_data_type_controller.h" 5 #include "components/sync_driver/non_ui_data_type_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "base/test/test_timeouts.h" 15 #include "base/test/test_timeouts.h"
16 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
16 #include "base/tracked_objects.h" 18 #include "base/tracked_objects.h"
17 #include "components/sync_driver/data_type_controller_mock.h" 19 #include "components/sync_driver/data_type_controller_mock.h"
18 #include "components/sync_driver/generic_change_processor_factory.h" 20 #include "components/sync_driver/generic_change_processor_factory.h"
19 #include "components/sync_driver/non_ui_data_type_controller_mock.h" 21 #include "components/sync_driver/non_ui_data_type_controller_mock.h"
20 #include "sync/api/fake_syncable_service.h" 22 #include "sync/api/fake_syncable_service.h"
21 #include "sync/api/sync_change.h" 23 #include "sync/api/sync_change.h"
22 #include "sync/internal_api/public/engine/model_safe_worker.h" 24 #include "sync/internal_api/public/engine/model_safe_worker.h"
23 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessorMock); 91 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessorMock);
90 }; 92 };
91 93
92 class NonUIDataTypeControllerFake 94 class NonUIDataTypeControllerFake
93 : public NonUIDataTypeController { 95 : public NonUIDataTypeController {
94 public: 96 public:
95 NonUIDataTypeControllerFake( 97 NonUIDataTypeControllerFake(
96 SyncApiComponentFactory* sync_factory, 98 SyncApiComponentFactory* sync_factory,
97 NonUIDataTypeControllerMock* mock, 99 NonUIDataTypeControllerMock* mock,
98 SharedChangeProcessor* change_processor, 100 SharedChangeProcessor* change_processor,
99 scoped_refptr<base::MessageLoopProxy> backend_loop) 101 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner)
100 : NonUIDataTypeController( 102 : NonUIDataTypeController(base::ThreadTaskRunnerHandle::Get(),
101 base::MessageLoopProxy::current(), 103 base::Closure(),
102 base::Closure(), 104 sync_factory),
103 sync_factory),
104 blocked_(false), 105 blocked_(false),
105 mock_(mock), 106 mock_(mock),
106 change_processor_(change_processor), 107 change_processor_(change_processor),
107 backend_loop_(backend_loop) {} 108 backend_task_runner_(backend_task_runner) {}
108 109
109 syncer::ModelType type() const override { return AUTOFILL_PROFILE; } 110 syncer::ModelType type() const override { return AUTOFILL_PROFILE; }
110 syncer::ModelSafeGroup model_safe_group() const override { 111 syncer::ModelSafeGroup model_safe_group() const override {
111 return syncer::GROUP_DB; 112 return syncer::GROUP_DB;
112 } 113 }
113 114
114 // Prevent tasks from being posted on the backend thread until 115 // Prevent tasks from being posted on the backend thread until
115 // UnblockBackendTasks() is called. 116 // UnblockBackendTasks() is called.
116 void BlockBackendTasks() { 117 void BlockBackendTasks() {
117 blocked_ = true; 118 blocked_ = true;
(...skipping 14 matching lines...) Expand all
132 return change_processor_.get(); 133 return change_processor_.get();
133 } 134 }
134 135
135 protected: 136 protected:
136 bool PostTaskOnBackendThread(const tracked_objects::Location& from_here, 137 bool PostTaskOnBackendThread(const tracked_objects::Location& from_here,
137 const base::Closure& task) override { 138 const base::Closure& task) override {
138 if (blocked_) { 139 if (blocked_) {
139 pending_tasks_.push_back(PendingTask(from_here, task)); 140 pending_tasks_.push_back(PendingTask(from_here, task));
140 return true; 141 return true;
141 } else { 142 } else {
142 return backend_loop_->PostTask(from_here, task); 143 return backend_task_runner_->PostTask(from_here, task);
143 } 144 }
144 } 145 }
145 146
146 // We mock the following methods because their default implementations do 147 // We mock the following methods because their default implementations do
147 // nothing, but we still want to make sure they're called appropriately. 148 // nothing, but we still want to make sure they're called appropriately.
148 bool StartModels() override { return mock_->StartModels(); } 149 bool StartModels() override { return mock_->StartModels(); }
149 void StopModels() override { mock_->StopModels(); } 150 void StopModels() override { mock_->StopModels(); }
150 void RecordAssociationTime(base::TimeDelta time) override { 151 void RecordAssociationTime(base::TimeDelta time) override {
151 mock_->RecordAssociationTime(time); 152 mock_->RecordAssociationTime(time);
152 } 153 }
(...skipping 12 matching lines...) Expand all
165 : from_here(from_here), task(task) {} 166 : from_here(from_here), task(task) {}
166 167
167 tracked_objects::Location from_here; 168 tracked_objects::Location from_here;
168 base::Closure task; 169 base::Closure task;
169 }; 170 };
170 171
171 bool blocked_; 172 bool blocked_;
172 std::vector<PendingTask> pending_tasks_; 173 std::vector<PendingTask> pending_tasks_;
173 NonUIDataTypeControllerMock* mock_; 174 NonUIDataTypeControllerMock* mock_;
174 scoped_refptr<SharedChangeProcessor> change_processor_; 175 scoped_refptr<SharedChangeProcessor> change_processor_;
175 scoped_refptr<base::MessageLoopProxy> backend_loop_; 176 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_;
176 }; 177 };
177 178
178 class SyncNonUIDataTypeControllerTest : public testing::Test { 179 class SyncNonUIDataTypeControllerTest : public testing::Test {
179 public: 180 public:
180 SyncNonUIDataTypeControllerTest() 181 SyncNonUIDataTypeControllerTest()
181 : backend_thread_("dbthread") {} 182 : backend_thread_("dbthread") {}
182 183
183 void SetUp() override { 184 void SetUp() override {
184 backend_thread_.Start(); 185 backend_thread_.Start();
185 change_processor_ = new SharedChangeProcessorMock(); 186 change_processor_ = new SharedChangeProcessorMock();
186 // All of these are refcounted, so don't need to be released. 187 // All of these are refcounted, so don't need to be released.
187 dtc_mock_ = new StrictMock<NonUIDataTypeControllerMock>(); 188 dtc_mock_ = new StrictMock<NonUIDataTypeControllerMock>();
188 non_ui_dtc_ = 189 non_ui_dtc_ = new NonUIDataTypeControllerFake(
189 new NonUIDataTypeControllerFake(NULL, 190 NULL, dtc_mock_.get(), change_processor_.get(),
190 dtc_mock_.get(), 191 backend_thread_.task_runner());
191 change_processor_.get(),
192 backend_thread_.message_loop_proxy());
193 } 192 }
194 193
195 void TearDown() override { backend_thread_.Stop(); } 194 void TearDown() override { backend_thread_.Stop(); }
196 195
197 void WaitForDTC() { 196 void WaitForDTC() {
198 WaitableEvent done(true, false); 197 WaitableEvent done(true, false);
199 backend_thread_.message_loop_proxy()->PostTask( 198 backend_thread_.task_runner()->PostTask(
200 FROM_HERE, 199 FROM_HERE,
201 base::Bind(&SyncNonUIDataTypeControllerTest::SignalDone, 200 base::Bind(&SyncNonUIDataTypeControllerTest::SignalDone, &done));
202 &done));
203 done.TimedWait(TestTimeouts::action_timeout()); 201 done.TimedWait(TestTimeouts::action_timeout());
204 if (!done.IsSignaled()) { 202 if (!done.IsSignaled()) {
205 ADD_FAILURE() << "Timed out waiting for DB thread to finish."; 203 ADD_FAILURE() << "Timed out waiting for DB thread to finish.";
206 } 204 }
207 base::MessageLoop::current()->RunUntilIdle(); 205 base::MessageLoop::current()->RunUntilIdle();
208 } 206 }
209 207
210 protected: 208 protected:
211 void SetStartExpectations() { 209 void SetStartExpectations() {
212 EXPECT_CALL(*dtc_mock_.get(), StartModels()).WillOnce(Return(true)); 210 EXPECT_CALL(*dtc_mock_.get(), StartModels()).WillOnce(Return(true));
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 Start(); 472 Start();
475 WaitForDTC(); 473 WaitForDTC();
476 EXPECT_EQ(DataTypeController::RUNNING, non_ui_dtc_->state()); 474 EXPECT_EQ(DataTypeController::RUNNING, non_ui_dtc_->state());
477 475
478 testing::Mock::VerifyAndClearExpectations(&start_callback_); 476 testing::Mock::VerifyAndClearExpectations(&start_callback_);
479 EXPECT_CALL(model_load_callback_, Run(_, _)); 477 EXPECT_CALL(model_load_callback_, Run(_, _));
480 syncer::SyncError error(FROM_HERE, 478 syncer::SyncError error(FROM_HERE,
481 syncer::SyncError::DATATYPE_ERROR, 479 syncer::SyncError::DATATYPE_ERROR,
482 "error", 480 "error",
483 non_ui_dtc_->type()); 481 non_ui_dtc_->type());
484 backend_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( 482 backend_thread_.task_runner()->PostTask(
485 &NonUIDataTypeControllerFake:: 483 FROM_HERE,
486 OnSingleDataTypeUnrecoverableError, 484 base::Bind(
487 non_ui_dtc_.get(), 485 &NonUIDataTypeControllerFake::OnSingleDataTypeUnrecoverableError,
488 error)); 486 non_ui_dtc_.get(), error));
489 WaitForDTC(); 487 WaitForDTC();
490 } 488 }
491 489
492 } // namespace 490 } // namespace
493 491
494 } // namespace sync_driver 492 } // namespace sync_driver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698