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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // thread |thread_id| have been processed. Can only be called from the UI | 55 // thread |thread_id| have been processed. Can only be called from the UI |
56 // thread. | 56 // thread. |
57 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id); | 57 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id); |
58 | 58 |
59 // Runs until both the blocking pool and the current message loop are empty | 59 // Runs until both the blocking pool and the current message loop are empty |
60 // (have no more scheduled tasks) and no tasks are running. | 60 // (have no more scheduled tasks) and no tasks are running. |
61 void RunAllBlockingPoolTasksUntilIdle(); | 61 void RunAllBlockingPoolTasksUntilIdle(); |
62 | 62 |
63 // Get task to quit the given RunLoop. It allows a few generations of pending | 63 // Get task to quit the given RunLoop. It allows a few generations of pending |
64 // tasks to run as opposed to run_loop->QuitClosure(). | 64 // tasks to run as opposed to run_loop->QuitClosure(). |
65 base::Closure GetDeferredQuitTaskForRunLoop(base::RunLoop* run_loop); | 65 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop); |
66 | 66 |
67 // Executes the specified JavaScript in the specified frame, and runs a nested | 67 // Executes the specified JavaScript in the specified frame, and runs a nested |
68 // MessageLoop. When the result is available, it is returned. | 68 // MessageLoop. When the result is available, it is returned. |
69 // This should not be used; the use of the ExecuteScript functions in | 69 // This should not be used; the use of the ExecuteScript functions in |
70 // browser_test_utils is preferable. | 70 // browser_test_utils is preferable. |
71 std::unique_ptr<base::Value> ExecuteScriptAndGetValue( | 71 std::unique_ptr<base::Value> ExecuteScriptAndGetValue( |
72 RenderFrameHost* render_frame_host, | 72 RenderFrameHost* render_frame_host, |
73 const std::string& script); | 73 const std::string& script); |
74 | 74 |
75 // Returns true if all sites are isolated. Typically used to bail from a test | 75 // Returns true if all sites are isolated. Typically used to bail from a test |
76 // that is incompatible with --site-per-process. | 76 // that is incompatible with --site-per-process. |
77 bool AreAllSitesIsolatedForTesting(); | 77 bool AreAllSitesIsolatedForTesting(); |
78 | 78 |
79 // Appends --site-per-process to the command line, enabling tests to exercise | 79 // Appends --site-per-process to the command line, enabling tests to exercise |
80 // site isolation and cross-process iframes. This must be called early in | 80 // site isolation and cross-process iframes. This must be called early in |
81 // the test; the flag will be read on the first real navigation. | 81 // the test; the flag will be read on the first real navigation. |
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 | 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. | 93 // really need, pass QuitMode::IMMEDIATE in the constructor. |
94 // | |
95 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is | |
96 // not needed. If you need to defer quitting the loop, use | |
97 // GetDeferredQuitTaskForRunLoop directly. | |
98 // If you found a case where base::RunLoop is inconvenient or can not be used at | |
99 // all, please post details in a comment on https://crbug.com/668707. | |
100 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { | 94 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { |
101 public: | 95 public: |
102 enum class QuitMode { | 96 enum class QuitMode { |
103 // Message loop stops after finishing the current task. | 97 // Message loop stops after finishing the current task. |
104 IMMEDIATE, | 98 IMMEDIATE, |
105 | 99 |
106 // Several generations of posted tasks are executed before stopping. | 100 // Several generations of posted tasks are executed before stopping. |
107 DEFERRED, | 101 DEFERRED, |
108 }; | 102 }; |
109 | 103 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 void WebContentsDestroyed() override; | 295 void WebContentsDestroyed() override; |
302 | 296 |
303 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 297 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
304 | 298 |
305 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); | 299 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); |
306 }; | 300 }; |
307 | 301 |
308 } // namespace content | 302 } // namespace content |
309 | 303 |
310 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 304 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
OLD | NEW |