| 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 "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 RenderViewHost* render_view_host, | 56 RenderViewHost* render_view_host, |
| 57 const std::string& script); | 57 const std::string& script); |
| 58 | 58 |
| 59 // Helper class to Run and Quit the message loop. Run and Quit can only happen | 59 // Helper class to Run and Quit the message loop. Run and Quit can only happen |
| 60 // once per instance. Make a new instance for each use. Calling Quit after Run | 60 // once per instance. Make a new instance for each use. Calling Quit after Run |
| 61 // has returned is safe and has no effect. | 61 // has returned is safe and has no effect. |
| 62 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { | 62 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { |
| 63 public: | 63 public: |
| 64 MessageLoopRunner(); | 64 MessageLoopRunner(); |
| 65 | 65 |
| 66 // Run the current MessageLoop. | 66 // Run the current MessageLoop unless the quit closure |
| 67 // has already been called. |
| 67 void Run(); | 68 void Run(); |
| 68 | 69 |
| 69 // Quit the matching call to Run (nested MessageLoops are unaffected). | 70 // Quit the matching call to Run (nested MessageLoops are unaffected). |
| 70 void Quit(); | 71 void Quit(); |
| 71 | 72 |
| 72 // Hand this closure off to code that uses callbacks to notify completion. | 73 // Hand this closure off to code that uses callbacks to notify completion. |
| 73 // Example: | 74 // Example: |
| 74 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; | 75 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; |
| 75 // kick_off_some_api(runner->QuitClosure()); | 76 // kick_off_some_api(runner->QuitClosure()); |
| 76 // runner->Run(); | 77 // runner->Run(); |
| 77 base::Closure QuitClosure(); | 78 base::Closure QuitClosure(); |
| 78 | 79 |
| 79 private: | 80 private: |
| 80 friend class base::RefCounted<MessageLoopRunner>; | 81 friend class base::RefCounted<MessageLoopRunner>; |
| 81 ~MessageLoopRunner(); | 82 ~MessageLoopRunner(); |
| 82 | 83 |
| 84 // True when the message loop is running. |
| 85 bool loop_running_; |
| 86 |
| 87 // True after closure returned by |QuitClosure| has been called. |
| 88 bool quit_closure_called_; |
| 89 |
| 83 base::RunLoop run_loop_; | 90 base::RunLoop run_loop_; |
| 84 | 91 |
| 85 DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner); | 92 DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner); |
| 86 }; | 93 }; |
| 87 | 94 |
| 88 // A WindowedNotificationObserver allows code to watch for a notification | 95 // A WindowedNotificationObserver allows code to watch for a notification |
| 89 // over a window of time. Typically testing code will need to do something | 96 // over a window of time. Typically testing code will need to do something |
| 90 // like this: | 97 // like this: |
| 91 // PerformAction() | 98 // PerformAction() |
| 92 // WaitForCompletionNotification() | 99 // WaitForCompletionNotification() |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 NotificationSource source_; | 141 NotificationSource source_; |
| 135 NotificationDetails details_; | 142 NotificationDetails details_; |
| 136 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 143 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 137 | 144 |
| 138 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); | 145 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); |
| 139 }; | 146 }; |
| 140 | 147 |
| 141 } // namespace content | 148 } // namespace content |
| 142 | 149 |
| 143 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 150 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| OLD | NEW |