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

Side by Side Diff: chrome/browser/sync/glue/ui_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/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 14 matching lines...) Expand all
25 UIModelWorkerVisitor(base::WaitableEvent* was_run, 25 UIModelWorkerVisitor(base::WaitableEvent* was_run,
26 bool quit_loop) 26 bool quit_loop)
27 : quit_loop_when_run_(quit_loop), 27 : quit_loop_when_run_(quit_loop),
28 was_run_(was_run) { } 28 was_run_(was_run) { }
29 virtual ~UIModelWorkerVisitor() { } 29 virtual ~UIModelWorkerVisitor() { }
30 30
31 virtual syncer::SyncerError DoWork() { 31 virtual syncer::SyncerError DoWork() {
32 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 32 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
33 was_run_->Signal(); 33 was_run_->Signal();
34 if (quit_loop_when_run_) 34 if (quit_loop_when_run_)
35 MessageLoop::current()->Quit(); 35 base::MessageLoop::current()->Quit();
36 return syncer::SYNCER_OK; 36 return syncer::SYNCER_OK;
37 } 37 }
38 38
39 private: 39 private:
40 bool quit_loop_when_run_; 40 bool quit_loop_when_run_;
41 base::WaitableEvent* was_run_; 41 base::WaitableEvent* was_run_;
42 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor); 42 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor);
43 }; 43 };
44 44
45 // A faux-syncer that only interacts with its model safe worker. 45 // A faux-syncer that only interacts with its model safe worker.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 &faux_ui_loop_)); 91 &faux_ui_loop_));
92 bmw_ = new UIModelWorker(); 92 bmw_ = new UIModelWorker();
93 syncer_.reset(new Syncer(bmw_.get())); 93 syncer_.reset(new Syncer(bmw_.get()));
94 } 94 }
95 95
96 Syncer* syncer() { return syncer_.get(); } 96 Syncer* syncer() { return syncer_.get(); }
97 UIModelWorker* bmw() { return bmw_.get(); } 97 UIModelWorker* bmw() { return bmw_.get(); }
98 base::Thread* core_thread() { return &faux_core_thread_; } 98 base::Thread* core_thread() { return &faux_core_thread_; }
99 base::Thread* syncer_thread() { return &faux_syncer_thread_; } 99 base::Thread* syncer_thread() { return &faux_syncer_thread_; }
100 private: 100 private:
101 MessageLoop faux_ui_loop_; 101 base::MessageLoop faux_ui_loop_;
102 scoped_ptr<content::TestBrowserThread> ui_thread_; 102 scoped_ptr<content::TestBrowserThread> ui_thread_;
103 base::Thread faux_syncer_thread_; 103 base::Thread faux_syncer_thread_;
104 base::Thread faux_core_thread_; 104 base::Thread faux_core_thread_;
105 scoped_refptr<UIModelWorker> bmw_; 105 scoped_refptr<UIModelWorker> bmw_;
106 scoped_ptr<Syncer> syncer_; 106 scoped_ptr<Syncer> syncer_;
107 }; 107 };
108 108
109 TEST_F(SyncUIModelWorkerTest, ScheduledWorkRunsOnUILoop) { 109 TEST_F(SyncUIModelWorkerTest, ScheduledWorkRunsOnUILoop) {
110 base::WaitableEvent v_was_run(false, false); 110 base::WaitableEvent v_was_run(false, false);
111 scoped_ptr<UIModelWorkerVisitor> v( 111 scoped_ptr<UIModelWorkerVisitor> v(
112 new UIModelWorkerVisitor(&v_was_run, true)); 112 new UIModelWorkerVisitor(&v_was_run, true));
113 113
114 syncer_thread()->message_loop()->PostTask(FROM_HERE, 114 syncer_thread()->message_loop()->PostTask(FROM_HERE,
115 base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get())); 115 base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get()));
116 116
117 // We are on the UI thread, so run our loop to process the 117 // We are on the UI thread, so run our loop to process the
118 // (hopefully) scheduled task from a SyncShare invocation. 118 // (hopefully) scheduled task from a SyncShare invocation.
119 MessageLoop::current()->Run(); 119 base::MessageLoop::current()->Run();
120 120
121 bmw()->OnSyncerShutdownComplete(); 121 bmw()->OnSyncerShutdownComplete();
122 bmw()->Stop(); 122 bmw()->Stop();
123 syncer_thread()->Stop(); 123 syncer_thread()->Stop();
124 } 124 }
125 125
126 TEST_F(SyncUIModelWorkerTest, StopWithPendingWork) { 126 TEST_F(SyncUIModelWorkerTest, StopWithPendingWork) {
127 // What we want to set up is the following: 127 // What we want to set up is the following:
128 // ("ui_thread" is the thread we are currently executing on) 128 // ("ui_thread" is the thread we are currently executing on)
129 // 1 - simulate the user shutting down the browser, and the ui thread needing 129 // 1 - simulate the user shutting down the browser, and the ui thread needing
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 // This is what gets the UI thread blocked until NotifyExitRequested, 204 // This is what gets the UI thread blocked until NotifyExitRequested,
205 // which is called when FakeSyncapiShutdownCallback runs and deletes the 205 // which is called when FakeSyncapiShutdownCallback runs and deletes the
206 // syncer. 206 // syncer.
207 bmw()->Stop(); 207 bmw()->Stop();
208 208
209 // Was the thread killed? 209 // Was the thread killed?
210 EXPECT_FALSE(syncer_thread()->IsRunning()); 210 EXPECT_FALSE(syncer_thread()->IsRunning());
211 core_thread()->Stop(); 211 core_thread()->Stop();
212 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698