OLD | NEW |
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 Loading... |
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); |
123 run_loop->Run(); | 130 run_loop->Run(); |
| 131 if (delegate) |
| 132 delegate->PostRunMessageLoop(); |
124 } | 133 } |
125 | 134 |
126 void RunAllPendingInMessageLoop() { | 135 void RunAllPendingInMessageLoop() { |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 136 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
128 base::RunLoop run_loop; | 137 base::RunLoop run_loop; |
129 base::ThreadTaskRunnerHandle::Get()->PostTask( | 138 base::ThreadTaskRunnerHandle::Get()->PostTask( |
130 FROM_HERE, GetDeferredQuitTaskForRunLoop(&run_loop)); | 139 FROM_HERE, GetQuitTaskForRunLoop(&run_loop)); |
131 RunThisRunLoop(&run_loop); | 140 RunThisRunLoop(&run_loop); |
132 } | 141 } |
133 | 142 |
134 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { | 143 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { |
135 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 144 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
136 if (thread_id == BrowserThread::UI) { | 145 if (thread_id == BrowserThread::UI) { |
137 RunAllPendingInMessageLoop(); | 146 RunAllPendingInMessageLoop(); |
138 return; | 147 return; |
139 } | 148 } |
140 | 149 |
(...skipping 18 matching lines...) Expand all Loading... |
159 TaskObserver task_observer; | 168 TaskObserver task_observer; |
160 base::MessageLoop::current()->AddTaskObserver(&task_observer); | 169 base::MessageLoop::current()->AddTaskObserver(&task_observer); |
161 base::RunLoop().RunUntilIdle(); | 170 base::RunLoop().RunUntilIdle(); |
162 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); | 171 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); |
163 | 172 |
164 if (!task_observer.processed()) | 173 if (!task_observer.processed()) |
165 break; | 174 break; |
166 } | 175 } |
167 } | 176 } |
168 | 177 |
169 base::Closure GetDeferredQuitTaskForRunLoop(base::RunLoop* run_loop) { | 178 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) { |
170 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), | 179 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), |
171 kNumQuitDeferrals); | 180 kNumQuitDeferrals); |
172 } | 181 } |
173 | 182 |
174 std::unique_ptr<base::Value> ExecuteScriptAndGetValue( | 183 std::unique_ptr<base::Value> ExecuteScriptAndGetValue( |
175 RenderFrameHost* render_frame_host, | 184 RenderFrameHost* render_frame_host, |
176 const std::string& script) { | 185 const std::string& script) { |
177 ScriptCallback observer; | 186 ScriptCallback observer; |
178 | 187 |
179 render_frame_host->ExecuteJavaScriptForTests( | 188 render_frame_host->ExecuteJavaScriptForTests( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 233 |
225 void MessageLoopRunner::Quit() { | 234 void MessageLoopRunner::Quit() { |
226 DCHECK(thread_checker_.CalledOnValidThread()); | 235 DCHECK(thread_checker_.CalledOnValidThread()); |
227 | 236 |
228 quit_closure_called_ = true; | 237 quit_closure_called_ = true; |
229 | 238 |
230 // Only run the quit task if we are running the message loop. | 239 // Only run the quit task if we are running the message loop. |
231 if (loop_running_) { | 240 if (loop_running_) { |
232 switch (quit_mode_) { | 241 switch (quit_mode_) { |
233 case QuitMode::DEFERRED: | 242 case QuitMode::DEFERRED: |
234 GetDeferredQuitTaskForRunLoop(&run_loop_).Run(); | 243 GetQuitTaskForRunLoop(&run_loop_).Run(); |
235 break; | 244 break; |
236 case QuitMode::IMMEDIATE: | 245 case QuitMode::IMMEDIATE: |
237 run_loop_.Quit(); | 246 run_loop_.Quit(); |
238 break; | 247 break; |
239 } | 248 } |
240 loop_running_ = false; | 249 loop_running_ = false; |
241 } | 250 } |
242 } | 251 } |
243 | 252 |
244 WindowedNotificationObserver::WindowedNotificationObserver( | 253 WindowedNotificationObserver::WindowedNotificationObserver( |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 388 |
380 void WebContentsDestroyedWatcher::Wait() { | 389 void WebContentsDestroyedWatcher::Wait() { |
381 message_loop_runner_->Run(); | 390 message_loop_runner_->Run(); |
382 } | 391 } |
383 | 392 |
384 void WebContentsDestroyedWatcher::WebContentsDestroyed() { | 393 void WebContentsDestroyedWatcher::WebContentsDestroyed() { |
385 message_loop_runner_->Quit(); | 394 message_loop_runner_->Quit(); |
386 } | 395 } |
387 | 396 |
388 } // namespace content | 397 } // namespace content |
OLD | NEW |