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

Side by Side Diff: components/sync_driver/glue/browser_thread_model_worker_unittest.cc

Issue 2082333002: Remove calls to deprecated MessageLoop methods in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 (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/sync_driver/glue/browser_thread_model_worker.h" 5 #include "components/sync_driver/glue/browser_thread_model_worker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using base::Thread; 20 using base::Thread;
20 using base::TimeDelta; 21 using base::TimeDelta;
21 22
(...skipping 21 matching lines...) Expand all
43 &SyncBrowserThreadModelWorkerTest::DoWork, base::Unretained(this)); 44 &SyncBrowserThreadModelWorkerTest::DoWork, base::Unretained(this));
44 timer()->Start(FROM_HERE, TestTimeouts::action_timeout(), this, 45 timer()->Start(FROM_HERE, TestTimeouts::action_timeout(), this,
45 &SyncBrowserThreadModelWorkerTest::Timeout); 46 &SyncBrowserThreadModelWorkerTest::Timeout);
46 worker()->DoWorkAndWaitUntilDone(c); 47 worker()->DoWorkAndWaitUntilDone(c);
47 } 48 }
48 49
49 // This is the work that will be scheduled to be done on the DB thread. 50 // This is the work that will be scheduled to be done on the DB thread.
50 syncer::SyncerError DoWork() { 51 syncer::SyncerError DoWork() {
51 EXPECT_TRUE(db_thread_.task_runner()->BelongsToCurrentThread()); 52 EXPECT_TRUE(db_thread_.task_runner()->BelongsToCurrentThread());
52 timer_.Stop(); // Stop the failure timer so the test succeeds. 53 timer_.Stop(); // Stop the failure timer so the test succeeds.
53 main_message_loop_.PostTask(FROM_HERE, 54 main_message_loop_.task_runner()->PostTask(
54 base::MessageLoop::QuitWhenIdleClosure()); 55 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
55 did_do_work_ = true; 56 did_do_work_ = true;
56 return syncer::SYNCER_OK; 57 return syncer::SYNCER_OK;
57 } 58 }
58 59
59 // This will be called by the OneShotTimer and make the test fail unless 60 // This will be called by the OneShotTimer and make the test fail unless
60 // DoWork is called first. 61 // DoWork is called first.
61 void Timeout() { 62 void Timeout() {
62 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; 63 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread.";
63 main_message_loop_.PostTask(FROM_HERE, 64 main_message_loop_.task_runner()->PostTask(
64 base::MessageLoop::QuitWhenIdleClosure()); 65 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
65 } 66 }
66 67
67 protected: 68 protected:
68 void SetUp() override { 69 void SetUp() override {
69 db_thread_.Start(); 70 db_thread_.Start();
70 worker_ = new BrowserThreadModelWorker(db_thread_.task_runner(), 71 worker_ = new BrowserThreadModelWorker(db_thread_.task_runner(),
71 syncer::GROUP_DB, NULL); 72 syncer::GROUP_DB, NULL);
72 } 73 }
73 74
74 virtual void Teardown() { 75 virtual void Teardown() {
75 worker_ = NULL; 76 worker_ = NULL;
76 db_thread_.Stop(); 77 db_thread_.Stop();
77 } 78 }
78 79
79 private: 80 private:
80 base::MessageLoop main_message_loop_; 81 base::MessageLoop main_message_loop_;
81 Thread db_thread_; 82 Thread db_thread_;
82 bool did_do_work_; 83 bool did_do_work_;
83 scoped_refptr<BrowserThreadModelWorker> worker_; 84 scoped_refptr<BrowserThreadModelWorker> worker_;
84 base::OneShotTimer timer_; 85 base::OneShotTimer timer_;
85 86
86 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_; 87 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_;
87 }; 88 };
88 89
89 TEST_F(SyncBrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) { 90 TEST_F(SyncBrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) {
90 base::ThreadTaskRunnerHandle::Get()->PostTask( 91 base::ThreadTaskRunnerHandle::Get()->PostTask(
91 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, 92 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork,
92 factory()->GetWeakPtr())); 93 factory()->GetWeakPtr()));
93 base::MessageLoop::current()->Run(); 94 base::RunLoop().Run();
94 EXPECT_TRUE(did_do_work()); 95 EXPECT_TRUE(did_do_work());
95 } 96 }
96 97
97 } // namespace 98 } // namespace
98 99
99 } // namespace browser_sync 100 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/storage_monitor/storage_monitor_unittest.cc ('k') | components/sync_driver/glue/sync_backend_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698