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

Side by Side Diff: components/sync/driver/glue/ui_model_worker_unittest.cc

Issue 2503423004: [Sync] Move sync's ModelSafeWorker implementations to engine/. (Closed)
Patch Set: Rebase. Created 4 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/sync/driver/glue/ui_model_worker.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/run_loop.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace syncer {
17 namespace {
18
19 // Makes a Closure into a WorkCallback.
20 // Does |work| and checks that we're on the |thread_verifier| thread.
21 SyncerError DoWork(
22 const scoped_refptr<base::SingleThreadTaskRunner>& thread_verifier,
23 base::Closure work) {
24 DCHECK(thread_verifier->BelongsToCurrentThread());
25 work.Run();
26 return SYNCER_OK;
27 }
28
29 // Converts |work| to a WorkCallback that will verify that it's run on the
30 // thread it was constructed on.
31 WorkCallback ClosureToWorkCallback(base::Closure work) {
32 return base::Bind(&DoWork, base::ThreadTaskRunnerHandle::Get(), work);
33 }
34
35 class SyncUIModelWorkerTest : public testing::Test {
36 public:
37 SyncUIModelWorkerTest() : sync_thread_("SyncThreadForTest") {
38 sync_thread_.Start();
39 worker_ = new UIModelWorker(base::ThreadTaskRunnerHandle::Get());
40 }
41
42 void PostWorkToSyncThread(WorkCallback work) {
43 sync_thread_.task_runner()->PostTask(
44 FROM_HERE,
45 base::Bind(base::IgnoreResult(&UIModelWorker::DoWorkAndWaitUntilDone),
46 worker_, work));
47 }
48
49 private:
50 base::MessageLoop ui_loop_;
51 base::Thread sync_thread_;
52 scoped_refptr<UIModelWorker> worker_;
53 };
54
55 TEST_F(SyncUIModelWorkerTest, ScheduledWorkRunsOnUILoop) {
56 base::RunLoop run_loop;
57 PostWorkToSyncThread(ClosureToWorkCallback(run_loop.QuitClosure()));
58 // This won't quit until the QuitClosure is run.
59 run_loop.Run();
60 }
61
62 } // namespace
63 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/glue/ui_model_worker.cc ('k') | components/sync/engine/browser_thread_model_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698