Chromium Code Reviews| 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 IMMEDIATE, // Message loop stops after finishing the current task. | |
| 98 LOOSE, // Several generations of posted tasks are executed before stopping. | |
| 99 }; | |
| 100 | |
| 101 MessageLoopRunner(QuitMode mode = QuitMode::LOOSE); | |
|
nasko
2016/11/23 17:48:29
Instead of making the quit type be captured for th
Alexander Semashko
2016/11/23 18:38:08
I thought the current way would be clearer; also t
nasko
2016/11/24 00:00:43
lukasza@ pointed out a different argument in favor
Alexander Semashko
2016/11/24 10:31:42
Too loose name could be an additional warning for
| |
| 95 | 102 |
| 96 // Run the current MessageLoop unless the quit closure | 103 // Run the current MessageLoop unless the quit closure |
| 97 // has already been called. | 104 // has already been called. |
| 98 void Run(); | 105 void Run(); |
| 99 | 106 |
| 100 // Quit the matching call to Run (nested MessageLoops are unaffected). | 107 // Quit the matching call to Run (nested MessageLoops are unaffected). |
| 101 void Quit(); | 108 void Quit(); |
| 102 | 109 |
| 103 // Hand this closure off to code that uses callbacks to notify completion. | 110 // Hand this closure off to code that uses callbacks to notify completion. |
| 104 // Example: | 111 // Example: |
| 105 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; | 112 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; |
| 106 // kick_off_some_api(runner->QuitClosure()); | 113 // kick_off_some_api(runner->QuitClosure()); |
| 107 // runner->Run(); | 114 // runner->Run(); |
| 108 base::Closure QuitClosure(); | 115 base::Closure QuitClosure(); |
| 109 | 116 |
| 110 bool loop_running() const { return loop_running_; } | 117 bool loop_running() const { return loop_running_; } |
| 111 | 118 |
| 112 private: | 119 private: |
| 113 friend class base::RefCounted<MessageLoopRunner>; | 120 friend class base::RefCounted<MessageLoopRunner>; |
| 114 ~MessageLoopRunner(); | 121 ~MessageLoopRunner(); |
| 115 | 122 |
| 123 QuitMode quit_mode_; | |
| 124 | |
| 116 // True when the message loop is running. | 125 // True when the message loop is running. |
| 117 bool loop_running_; | 126 bool loop_running_; |
| 118 | 127 |
| 119 // True after closure returned by |QuitClosure| has been called. | 128 // True after closure returned by |QuitClosure| has been called. |
| 120 bool quit_closure_called_; | 129 bool quit_closure_called_; |
| 121 | 130 |
| 122 base::RunLoop run_loop_; | 131 base::RunLoop run_loop_; |
| 123 | 132 |
| 124 base::ThreadChecker thread_checker_; | 133 base::ThreadChecker thread_checker_; |
| 125 | 134 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 void WebContentsDestroyed() override; | 292 void WebContentsDestroyed() override; |
| 284 | 293 |
| 285 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 294 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 286 | 295 |
| 287 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); | 296 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); |
| 288 }; | 297 }; |
| 289 | 298 |
| 290 } // namespace content | 299 } // namespace content |
| 291 | 300 |
| 292 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 301 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| OLD | NEW |