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

Side by Side Diff: components/sync/driver/async_directory_type_controller_unittest.cc

Issue 2846723005: Use ScopedTaskEnvironment instead of MessageLoopForUI in components tests. (Closed)
Patch Set: fix-test-errors Created 3 years, 7 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/async_directory_type_controller.h" 5 #include "components/sync/driver/async_directory_type_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/test/scoped_task_environment.h"
19 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
20 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/tracked_objects.h" 23 #include "base/tracked_objects.h"
23 #include "components/sync/driver/async_directory_type_controller_mock.h" 24 #include "components/sync/driver/async_directory_type_controller_mock.h"
24 #include "components/sync/driver/data_type_controller_mock.h" 25 #include "components/sync/driver/data_type_controller_mock.h"
25 #include "components/sync/driver/fake_sync_client.h" 26 #include "components/sync/driver/fake_sync_client.h"
26 #include "components/sync/driver/generic_change_processor_factory.h" 27 #include "components/sync/driver/generic_change_processor_factory.h"
27 #include "components/sync/engine/model_safe_worker.h" 28 #include "components/sync/engine/model_safe_worker.h"
28 #include "components/sync/model/fake_syncable_service.h" 29 #include "components/sync/model/fake_syncable_service.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 AsyncDirectoryTypeControllerMock* mock_; 171 AsyncDirectoryTypeControllerMock* mock_;
171 scoped_refptr<SharedChangeProcessor> change_processor_; 172 scoped_refptr<SharedChangeProcessor> change_processor_;
172 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_; 173 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_;
173 174
174 DISALLOW_COPY_AND_ASSIGN(AsyncDirectoryTypeControllerFake); 175 DISALLOW_COPY_AND_ASSIGN(AsyncDirectoryTypeControllerFake);
175 }; 176 };
176 177
177 class SyncAsyncDirectoryTypeControllerTest : public testing::Test, 178 class SyncAsyncDirectoryTypeControllerTest : public testing::Test,
178 public FakeSyncClient { 179 public FakeSyncClient {
179 public: 180 public:
180 SyncAsyncDirectoryTypeControllerTest() : backend_thread_("dbthread") {} 181 SyncAsyncDirectoryTypeControllerTest()
182 : scoped_task_environment_(
183 base::test::ScopedTaskEnvironment::MainThreadType::UI),
184 backend_thread_("dbthread") {}
181 185
182 void SetUp() override { 186 void SetUp() override {
183 backend_thread_.Start(); 187 backend_thread_.Start();
184 change_processor_ = new SharedChangeProcessorMock(kType); 188 change_processor_ = new SharedChangeProcessorMock(kType);
185 // All of these are refcounted, so don't need to be released. 189 // All of these are refcounted, so don't need to be released.
186 dtc_mock_ = 190 dtc_mock_ =
187 base::MakeUnique<StrictMock<AsyncDirectoryTypeControllerMock>>(); 191 base::MakeUnique<StrictMock<AsyncDirectoryTypeControllerMock>>();
188 non_ui_dtc_ = base::MakeUnique<AsyncDirectoryTypeControllerFake>( 192 non_ui_dtc_ = base::MakeUnique<AsyncDirectoryTypeControllerFake>(
189 this, dtc_mock_.get(), change_processor_.get(), 193 this, dtc_mock_.get(), change_processor_.get(),
190 backend_thread_.task_runner()); 194 backend_thread_.task_runner());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 250
247 void Start() { 251 void Start() {
248 non_ui_dtc_->LoadModels(base::Bind( 252 non_ui_dtc_->LoadModels(base::Bind(
249 &ModelLoadCallbackMock::Run, base::Unretained(&model_load_callback_))); 253 &ModelLoadCallbackMock::Run, base::Unretained(&model_load_callback_)));
250 non_ui_dtc_->StartAssociating(base::Bind( 254 non_ui_dtc_->StartAssociating(base::Bind(
251 &StartCallbackMock::Run, base::Unretained(&start_callback_))); 255 &StartCallbackMock::Run, base::Unretained(&start_callback_)));
252 } 256 }
253 257
254 static void SignalDone(WaitableEvent* done) { done->Signal(); } 258 static void SignalDone(WaitableEvent* done) { done->Signal(); }
255 259
256 base::MessageLoopForUI message_loop_; 260 base::test::ScopedTaskEnvironment scoped_task_environment_;
257 base::Thread backend_thread_; 261 base::Thread backend_thread_;
258 262
259 StartCallbackMock start_callback_; 263 StartCallbackMock start_callback_;
260 ModelLoadCallbackMock model_load_callback_; 264 ModelLoadCallbackMock model_load_callback_;
261 // Must be destroyed after non_ui_dtc_. 265 // Must be destroyed after non_ui_dtc_.
262 FakeSyncableService syncable_service_; 266 FakeSyncableService syncable_service_;
263 std::unique_ptr<AsyncDirectoryTypeControllerFake> non_ui_dtc_; 267 std::unique_ptr<AsyncDirectoryTypeControllerFake> non_ui_dtc_;
264 std::unique_ptr<AsyncDirectoryTypeControllerMock> dtc_mock_; 268 std::unique_ptr<AsyncDirectoryTypeControllerMock> dtc_mock_;
265 scoped_refptr<SharedChangeProcessorMock> change_processor_; 269 scoped_refptr<SharedChangeProcessorMock> change_processor_;
266 std::unique_ptr<SyncChangeProcessor> saved_change_processor_; 270 std::unique_ptr<SyncChangeProcessor> saved_change_processor_;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 backend_thread_.task_runner()->PostTask( 473 backend_thread_.task_runner()->PostTask(
470 FROM_HERE, 474 FROM_HERE,
471 base::Bind(&DataTypeErrorHandler::OnUnrecoverableError, 475 base::Bind(&DataTypeErrorHandler::OnUnrecoverableError,
472 base::Passed(non_ui_dtc_->CreateErrorHandler()), error)); 476 base::Passed(non_ui_dtc_->CreateErrorHandler()), error));
473 WaitForDTC(); 477 WaitForDTC();
474 } 478 }
475 479
476 } // namespace 480 } // namespace
477 481
478 } // namespace syncer 482 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698