| 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/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
| 12 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 14 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 16 | 17 |
| 17 // A collections of functions designed for use with unit and browser tests. | 18 // A collections of functions designed for use with unit and browser tests. |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 // Turns on nestable tasks, runs the message loop, then resets nestable tasks | 22 // Turns on nestable tasks, runs the message loop, then resets nestable tasks |
| 22 // to what they were originally. Prefer this over MessageLoop::Run for in | 23 // to what they were originally. Prefer this over MessageLoop::Run for in |
| 23 // process browser tests that need to block until a condition is met. | 24 // process browser tests that need to block until a condition is met. |
| 24 void RunMessageLoop(); | 25 void RunMessageLoop(); |
| 25 | 26 |
| 26 // Variant of RunMessageLoop that takes RunLoop. | 27 // Variant of RunMessageLoop that takes RunLoop. |
| 27 void RunThisRunLoop(base::RunLoop* run_loop); | 28 void RunThisRunLoop(base::RunLoop* run_loop); |
| 28 | 29 |
| 30 // Turns on nestable tasks, runs all pending tasks in the message loop, |
| 31 // then resets nestable tasks to what they were originally. Prefer this |
| 32 // over MessageLoop::RunAllPending for in process browser tests to run |
| 33 // all pending tasks. |
| 34 void RunAllPendingInMessageLoop(); |
| 35 |
| 36 // Blocks the current thread until all the pending messages in the loop of the |
| 37 // thread |thread_id| have been processed. |
| 38 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id); |
| 39 |
| 29 // Get task to quit the given RunLoop. It allows a few generations of pending | 40 // Get task to quit the given RunLoop. It allows a few generations of pending |
| 30 // tasks to run as opposed to run_loop->QuitClosure(). | 41 // tasks to run as opposed to run_loop->QuitClosure(). |
| 31 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop); | 42 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop); |
| 32 | 43 |
| 33 // Helper class to Run and Quit the message loop. Run and Quit can only happen | 44 // Helper class to Run and Quit the message loop. Run and Quit can only happen |
| 34 // once per instance. Make a new instance for each use. Calling Quit after Run | 45 // once per instance. Make a new instance for each use. Calling Quit after Run |
| 35 // has returned is safe and has no effect. | 46 // has returned is safe and has no effect. |
| 36 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { | 47 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { |
| 37 public: | 48 public: |
| 38 MessageLoopRunner(); | 49 MessageLoopRunner(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 NotificationSource source_; | 119 NotificationSource source_; |
| 109 NotificationDetails details_; | 120 NotificationDetails details_; |
| 110 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 121 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 111 | 122 |
| 112 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); | 123 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); |
| 113 }; | 124 }; |
| 114 | 125 |
| 115 } // namespace content | 126 } // namespace content |
| 116 | 127 |
| 117 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 128 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
| OLD | NEW |