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

Side by Side Diff: chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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 | Annotate | Revision Log
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 this, 51 this,
52 &SyncBrowserThreadModelWorkerTest::Timeout); 52 &SyncBrowserThreadModelWorkerTest::Timeout);
53 worker()->DoWorkAndWaitUntilDone(c); 53 worker()->DoWorkAndWaitUntilDone(c);
54 } 54 }
55 55
56 // This is the work that will be scheduled to be done on the DB thread. 56 // This is the work that will be scheduled to be done on the DB thread.
57 syncer::SyncerError DoWork() { 57 syncer::SyncerError DoWork() {
58 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 58 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
59 timer_.Stop(); // Stop the failure timer so the test succeeds. 59 timer_.Stop(); // Stop the failure timer so the test succeeds.
60 BrowserThread::PostTask( 60 BrowserThread::PostTask(
61 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); 61 BrowserThread::IO, FROM_HERE, base::MessageLoop::QuitClosure());
62 did_do_work_ = true; 62 did_do_work_ = true;
63 return syncer::SYNCER_OK; 63 return syncer::SYNCER_OK;
64 } 64 }
65 65
66 // This will be called by the OneShotTimer and make the test fail unless 66 // This will be called by the OneShotTimer and make the test fail unless
67 // DoWork is called first. 67 // DoWork is called first.
68 void Timeout() { 68 void Timeout() {
69 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; 69 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread.";
70 BrowserThread::PostTask( 70 BrowserThread::PostTask(
71 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); 71 BrowserThread::IO, FROM_HERE, base::MessageLoop::QuitClosure());
72 } 72 }
73 73
74 protected: 74 protected:
75 virtual void SetUp() { 75 virtual void SetUp() {
76 db_thread_.Start(); 76 db_thread_.Start();
77 worker_ = new DatabaseModelWorker(); 77 worker_ = new DatabaseModelWorker();
78 } 78 }
79 79
80 virtual void Teardown() { 80 virtual void Teardown() {
81 worker_ = NULL; 81 worker_ = NULL;
82 db_thread_.Stop(); 82 db_thread_.Stop();
83 } 83 }
84 84
85 private: 85 private:
86 bool did_do_work_; 86 bool did_do_work_;
87 scoped_refptr<BrowserThreadModelWorker> worker_; 87 scoped_refptr<BrowserThreadModelWorker> worker_;
88 OneShotTimer<SyncBrowserThreadModelWorkerTest> timer_; 88 OneShotTimer<SyncBrowserThreadModelWorkerTest> timer_;
89 89
90 content::TestBrowserThread db_thread_; 90 content::TestBrowserThread db_thread_;
91 MessageLoopForIO io_loop_; 91 base::MessageLoopForIO io_loop_;
92 content::TestBrowserThread io_thread_; 92 content::TestBrowserThread io_thread_;
93 93
94 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_; 94 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_;
95 }; 95 };
96 96
97 TEST_F(SyncBrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) { 97 TEST_F(SyncBrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) {
98 MessageLoop::current()->PostTask(FROM_HERE, 98 base::MessageLoop::current()->PostTask(FROM_HERE,
99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, 99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork,
100 factory()->GetWeakPtr())); 100 factory()->GetWeakPtr()));
101 MessageLoop::current()->Run(); 101 base::MessageLoop::current()->Run();
102 EXPECT_TRUE(did_do_work()); 102 EXPECT_TRUE(did_do_work());
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 } // namespace browser_sync 107 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698