| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 command_line->AppendSwitch(switches::kSitePerProcess); | 201 command_line->AppendSwitch(switches::kSitePerProcess); |
| 202 } | 202 } |
| 203 | 203 |
| 204 #if defined(OS_ANDROID) | 204 #if defined(OS_ANDROID) |
| 205 // Registers content/browser JNI bindings necessary for some types of tests. | 205 // Registers content/browser JNI bindings necessary for some types of tests. |
| 206 bool RegisterJniForTesting(JNIEnv* env) { | 206 bool RegisterJniForTesting(JNIEnv* env) { |
| 207 return content::android::RegisterBrowserJni(env); | 207 return content::android::RegisterBrowserJni(env); |
| 208 } | 208 } |
| 209 #endif | 209 #endif |
| 210 | 210 |
| 211 MessageLoopRunner::MessageLoopRunner() | 211 MessageLoopRunner::MessageLoopRunner(QuitMode quit_mode) |
| 212 : loop_running_(false), | 212 : quit_mode_(quit_mode), loop_running_(false), quit_closure_called_(false) { |
| 213 quit_closure_called_(false) { | |
| 214 } | 213 } |
| 215 | 214 |
| 216 MessageLoopRunner::~MessageLoopRunner() = default; | 215 MessageLoopRunner::~MessageLoopRunner() = default; |
| 217 | 216 |
| 218 void MessageLoopRunner::Run() { | 217 void MessageLoopRunner::Run() { |
| 219 DCHECK(thread_checker_.CalledOnValidThread()); | 218 DCHECK(thread_checker_.CalledOnValidThread()); |
| 220 | 219 |
| 221 // Do not run the message loop if our quit closure has already been called. | 220 // Do not run the message loop if our quit closure has already been called. |
| 222 // This helps in scenarios where the closure has a chance to run before | 221 // This helps in scenarios where the closure has a chance to run before |
| 223 // we Run explicitly. | 222 // we Run explicitly. |
| 224 if (quit_closure_called_) | 223 if (quit_closure_called_) |
| 225 return; | 224 return; |
| 226 | 225 |
| 227 loop_running_ = true; | 226 loop_running_ = true; |
| 228 RunThisRunLoop(&run_loop_); | 227 RunThisRunLoop(&run_loop_); |
| 229 } | 228 } |
| 230 | 229 |
| 231 base::Closure MessageLoopRunner::QuitClosure() { | 230 base::Closure MessageLoopRunner::QuitClosure() { |
| 232 return base::Bind(&MessageLoopRunner::Quit, this); | 231 return base::Bind(&MessageLoopRunner::Quit, this); |
| 233 } | 232 } |
| 234 | 233 |
| 235 void MessageLoopRunner::Quit() { | 234 void MessageLoopRunner::Quit() { |
| 236 DCHECK(thread_checker_.CalledOnValidThread()); | 235 DCHECK(thread_checker_.CalledOnValidThread()); |
| 237 | 236 |
| 238 quit_closure_called_ = true; | 237 quit_closure_called_ = true; |
| 239 | 238 |
| 240 // 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. |
| 241 if (loop_running_) { | 240 if (loop_running_) { |
| 242 GetQuitTaskForRunLoop(&run_loop_).Run(); | 241 switch (quit_mode_) { |
| 242 case QuitMode::LOOSE: |
| 243 GetQuitTaskForRunLoop(&run_loop_).Run(); |
| 244 break; |
| 245 case QuitMode::IMMEDIATE: |
| 246 run_loop_.Quit(); |
| 247 break; |
| 248 } |
| 243 loop_running_ = false; | 249 loop_running_ = false; |
| 244 } | 250 } |
| 245 } | 251 } |
| 246 | 252 |
| 247 WindowedNotificationObserver::WindowedNotificationObserver( | 253 WindowedNotificationObserver::WindowedNotificationObserver( |
| 248 int notification_type, | 254 int notification_type, |
| 249 const NotificationSource& source) | 255 const NotificationSource& source) |
| 250 : seen_(false), | 256 : seen_(false), |
| 251 running_(false), | 257 running_(false), |
| 252 source_(NotificationService::AllSources()) { | 258 source_(NotificationService::AllSources()) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 388 |
| 383 void WebContentsDestroyedWatcher::Wait() { | 389 void WebContentsDestroyedWatcher::Wait() { |
| 384 message_loop_runner_->Run(); | 390 message_loop_runner_->Run(); |
| 385 } | 391 } |
| 386 | 392 |
| 387 void WebContentsDestroyedWatcher::WebContentsDestroyed() { | 393 void WebContentsDestroyedWatcher::WebContentsDestroyed() { |
| 388 message_loop_runner_->Quit(); | 394 message_loop_runner_->Quit(); |
| 389 } | 395 } |
| 390 | 396 |
| 391 } // namespace content | 397 } // namespace content |
| OLD | NEW |