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

Side by Side Diff: content/public/test/test_utils.cc

Issue 2564943002: Reland "Add thread checking to RunLoop, deprecate MessageLoopRunner. (patchset #4 id:20002 of https… (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « content/public/test/test_utils.h ('k') | extensions/test/result_catcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/test/test_utils.h" 5 #include "content/public/test/test_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } // namespace 113 } // namespace
114 114
115 void RunMessageLoop() { 115 void RunMessageLoop() {
116 base::RunLoop run_loop; 116 base::RunLoop run_loop;
117 RunThisRunLoop(&run_loop); 117 RunThisRunLoop(&run_loop);
118 } 118 }
119 119
120 void RunThisRunLoop(base::RunLoop* run_loop) { 120 void RunThisRunLoop(base::RunLoop* run_loop) {
121 base::MessageLoop::ScopedNestableTaskAllower allow( 121 base::MessageLoop::ScopedNestableTaskAllower allow(
122 base::MessageLoop::current()); 122 base::MessageLoop::current());
123
124 // If we're running inside a browser test, we might need to allow the test
125 // launcher to do extra work before/after running a nested message loop.
126 TestLauncherDelegate* delegate = NULL;
127 delegate = GetCurrentTestLauncherDelegate();
128 if (delegate)
129 delegate->PreRunMessageLoop(run_loop);
130 run_loop->Run(); 123 run_loop->Run();
131 if (delegate)
132 delegate->PostRunMessageLoop();
133 } 124 }
134 125
135 void RunAllPendingInMessageLoop() { 126 void RunAllPendingInMessageLoop() {
136 DCHECK_CURRENTLY_ON(BrowserThread::UI); 127 DCHECK_CURRENTLY_ON(BrowserThread::UI);
137 base::RunLoop run_loop; 128 base::RunLoop run_loop;
138 base::ThreadTaskRunnerHandle::Get()->PostTask( 129 base::ThreadTaskRunnerHandle::Get()->PostTask(
139 FROM_HERE, GetQuitTaskForRunLoop(&run_loop)); 130 FROM_HERE, GetDeferredQuitTaskForRunLoop(&run_loop));
140 RunThisRunLoop(&run_loop); 131 RunThisRunLoop(&run_loop);
141 } 132 }
142 133
143 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { 134 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) {
144 DCHECK_CURRENTLY_ON(BrowserThread::UI); 135 DCHECK_CURRENTLY_ON(BrowserThread::UI);
145 if (thread_id == BrowserThread::UI) { 136 if (thread_id == BrowserThread::UI) {
146 RunAllPendingInMessageLoop(); 137 RunAllPendingInMessageLoop();
147 return; 138 return;
148 } 139 }
149 140
(...skipping 18 matching lines...) Expand all
168 TaskObserver task_observer; 159 TaskObserver task_observer;
169 base::MessageLoop::current()->AddTaskObserver(&task_observer); 160 base::MessageLoop::current()->AddTaskObserver(&task_observer);
170 base::RunLoop().RunUntilIdle(); 161 base::RunLoop().RunUntilIdle();
171 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); 162 base::MessageLoop::current()->RemoveTaskObserver(&task_observer);
172 163
173 if (!task_observer.processed()) 164 if (!task_observer.processed())
174 break; 165 break;
175 } 166 }
176 } 167 }
177 168
178 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) { 169 base::Closure GetDeferredQuitTaskForRunLoop(base::RunLoop* run_loop) {
179 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), 170 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
180 kNumQuitDeferrals); 171 kNumQuitDeferrals);
181 } 172 }
182 173
183 std::unique_ptr<base::Value> ExecuteScriptAndGetValue( 174 std::unique_ptr<base::Value> ExecuteScriptAndGetValue(
184 RenderFrameHost* render_frame_host, 175 RenderFrameHost* render_frame_host,
185 const std::string& script) { 176 const std::string& script) {
186 ScriptCallback observer; 177 ScriptCallback observer;
187 178
188 render_frame_host->ExecuteJavaScriptForTests( 179 render_frame_host->ExecuteJavaScriptForTests(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 224
234 void MessageLoopRunner::Quit() { 225 void MessageLoopRunner::Quit() {
235 DCHECK(thread_checker_.CalledOnValidThread()); 226 DCHECK(thread_checker_.CalledOnValidThread());
236 227
237 quit_closure_called_ = true; 228 quit_closure_called_ = true;
238 229
239 // Only run the quit task if we are running the message loop. 230 // Only run the quit task if we are running the message loop.
240 if (loop_running_) { 231 if (loop_running_) {
241 switch (quit_mode_) { 232 switch (quit_mode_) {
242 case QuitMode::DEFERRED: 233 case QuitMode::DEFERRED:
243 GetQuitTaskForRunLoop(&run_loop_).Run(); 234 GetDeferredQuitTaskForRunLoop(&run_loop_).Run();
244 break; 235 break;
245 case QuitMode::IMMEDIATE: 236 case QuitMode::IMMEDIATE:
246 run_loop_.Quit(); 237 run_loop_.Quit();
247 break; 238 break;
248 } 239 }
249 loop_running_ = false; 240 loop_running_ = false;
250 } 241 }
251 } 242 }
252 243
253 WindowedNotificationObserver::WindowedNotificationObserver( 244 WindowedNotificationObserver::WindowedNotificationObserver(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 379
389 void WebContentsDestroyedWatcher::Wait() { 380 void WebContentsDestroyedWatcher::Wait() {
390 message_loop_runner_->Run(); 381 message_loop_runner_->Run();
391 } 382 }
392 383
393 void WebContentsDestroyedWatcher::WebContentsDestroyed() { 384 void WebContentsDestroyedWatcher::WebContentsDestroyed() {
394 message_loop_runner_->Quit(); 385 message_loop_runner_->Quit();
395 } 386 }
396 387
397 } // namespace content 388 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_utils.h ('k') | extensions/test/result_catcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698