| 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 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| 6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void IsolateAllSitesForTesting(base::CommandLine* command_line); | 82 void IsolateAllSitesForTesting(base::CommandLine* command_line); |
| 83 | 83 |
| 84 #if defined(OS_ANDROID) | 84 #if defined(OS_ANDROID) |
| 85 // Registers content/browser JNI bindings necessary for some types of tests. | 85 // Registers content/browser JNI bindings necessary for some types of tests. |
| 86 bool RegisterJniForTesting(JNIEnv* env); | 86 bool RegisterJniForTesting(JNIEnv* env); |
| 87 #endif | 87 #endif |
| 88 | 88 |
| 89 // Helper class to Run and Quit the message loop. Run and Quit can only happen | 89 // Helper class to Run and Quit the message loop. Run and Quit can only happen |
| 90 // once per instance. Make a new instance for each use. Calling Quit after Run | 90 // once per instance. Make a new instance for each use. Calling Quit after Run |
| 91 // has returned is safe and has no effect. | 91 // has returned is safe and has no effect. |
| 92 // Note that by default Quit does not quit immediately. If that is not what you |
| 93 // really need, pass QuitMode::IMMEDIATE in the constructor. |
| 92 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { | 94 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { |
| 93 public: | 95 public: |
| 94 MessageLoopRunner(); | 96 enum class QuitMode { |
| 97 // Message loop stops after finishing the current task. |
| 98 IMMEDIATE, |
| 99 |
| 100 // Several generations of posted tasks are executed before stopping. |
| 101 DEFERRED, |
| 102 }; |
| 103 |
| 104 MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED); |
| 95 | 105 |
| 96 // Run the current MessageLoop unless the quit closure | 106 // Run the current MessageLoop unless the quit closure |
| 97 // has already been called. | 107 // has already been called. |
| 98 void Run(); | 108 void Run(); |
| 99 | 109 |
| 100 // Quit the matching call to Run (nested MessageLoops are unaffected). | 110 // Quit the matching call to Run (nested MessageLoops are unaffected). |
| 101 void Quit(); | 111 void Quit(); |
| 102 | 112 |
| 103 // Hand this closure off to code that uses callbacks to notify completion. | 113 // Hand this closure off to code that uses callbacks to notify completion. |
| 104 // Example: | 114 // Example: |
| 105 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; | 115 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; |
| 106 // kick_off_some_api(runner->QuitClosure()); | 116 // kick_off_some_api(runner->QuitClosure()); |
| 107 // runner->Run(); | 117 // runner->Run(); |
| 108 base::Closure QuitClosure(); | 118 base::Closure QuitClosure(); |
| 109 | 119 |
| 110 bool loop_running() const { return loop_running_; } | 120 bool loop_running() const { return loop_running_; } |
| 111 | 121 |
| 112 private: | 122 private: |
| 113 friend class base::RefCounted<MessageLoopRunner>; | 123 friend class base::RefCounted<MessageLoopRunner>; |
| 114 ~MessageLoopRunner(); | 124 ~MessageLoopRunner(); |
| 115 | 125 |
| 126 QuitMode quit_mode_; |
| 127 |
| 116 // True when the message loop is running. | 128 // True when the message loop is running. |
| 117 bool loop_running_; | 129 bool loop_running_; |
| 118 | 130 |
| 119 // True after closure returned by |QuitClosure| has been called. | 131 // True after closure returned by |QuitClosure| has been called. |
| 120 bool quit_closure_called_; | 132 bool quit_closure_called_; |
| 121 | 133 |
| 122 base::RunLoop run_loop_; | 134 base::RunLoop run_loop_; |
| 123 | 135 |
| 124 base::ThreadChecker thread_checker_; | 136 base::ThreadChecker thread_checker_; |
| 125 | 137 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 void WebContentsDestroyed() override; | 295 void WebContentsDestroyed() override; |
| 284 | 296 |
| 285 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 297 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 286 | 298 |
| 287 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); | 299 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); |
| 288 }; | 300 }; |
| 289 | 301 |
| 290 } // namespace content | 302 } // namespace content |
| 291 | 303 |
| 292 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 304 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| OLD | NEW |