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 #include <string> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "content/public/browser/browser_child_process_observer.h" | 17 #include "content/public/browser/browser_child_process_observer.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // to set field trial params associated with the feature as specified by | 93 // to set field trial params associated with the feature as specified by |
93 // |param_name| and |param_value|. | 94 // |param_name| and |param_value|. |
94 // | 95 // |
95 // Note that a dummy trial and trial group will be registered behind the scenes. | 96 // Note that a dummy trial and trial group will be registered behind the scenes. |
96 // See also variations::testing::VariationsParamsManager class. | 97 // See also variations::testing::VariationsParamsManager class. |
97 void EnableFeatureWithParam(const base::Feature& feature, | 98 void EnableFeatureWithParam(const base::Feature& feature, |
98 const std::string& param_name, | 99 const std::string& param_name, |
99 const std::string& param_value, | 100 const std::string& param_value, |
100 base::CommandLine* command_line); | 101 base::CommandLine* command_line); |
101 | 102 |
| 103 // Mutates |command_line| to enable a testing mode for TopDocumentIsolation by |
| 104 // 1) enabling the features::kTopDocumentIsolation feature and 2) forcing a mode |
| 105 // that isolates all cross-site frames. |
| 106 void EnableTopDocumentIsolationForTesting(base::CommandLine* command_line); |
| 107 |
102 #if defined(OS_ANDROID) | 108 #if defined(OS_ANDROID) |
103 // Registers content/browser JNI bindings necessary for some types of tests. | 109 // Registers content/browser JNI bindings necessary for some types of tests. |
104 bool RegisterJniForTesting(JNIEnv* env); | 110 bool RegisterJniForTesting(JNIEnv* env); |
105 #endif | 111 #endif |
106 | 112 |
107 // Helper class to Run and Quit the message loop. Run and Quit can only happen | 113 // Helper class to Run and Quit the message loop. Run and Quit can only happen |
108 // once per instance. Make a new instance for each use. Calling Quit after Run | 114 // once per instance. Make a new instance for each use. Calling Quit after Run |
109 // has returned is safe and has no effect. | 115 // has returned is safe and has no effect. |
110 // Note that by default Quit does not quit immediately. If that is not what you | 116 // Note that by default Quit does not quit immediately. If that is not what you |
111 // really need, pass QuitMode::IMMEDIATE in the constructor. | 117 // really need, pass QuitMode::IMMEDIATE in the constructor. |
112 // | 118 // |
113 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is | 119 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is |
114 // not needed. If you need to defer quitting the loop, use | 120 // not needed. If you need to defer quitting the loop, use |
115 // GetDeferredQuitTaskForRunLoop directly. | 121 // GetDeferredQuitTaskForRunLoop directly. |
116 // If you found a case where base::RunLoop is inconvenient or can not be used at | 122 // If you found a case where base::RunLoop is inconvenient or can not be used at |
117 // all, please post details in a comment on https://crbug.com/668707. | 123 // all, please post details in a comment on https://crbug.com/668707. |
118 class MessageLoopRunner : public base::RefCountedThreadSafe<MessageLoopRunner> { | 124 class MessageLoopRunner : public base::RefCountedThreadSafe<MessageLoopRunner> { |
119 public: | 125 public: |
120 enum class QuitMode { | 126 enum class QuitMode { |
121 // Message loop stops after finishing the current task. | 127 // Message loop stops after finishing the current task. |
122 IMMEDIATE, | 128 IMMEDIATE, |
123 | 129 |
124 // Several generations of posted tasks are executed before stopping. | 130 // Several generations of posted tasks are executed before stopping. |
125 DEFERRED, | 131 DEFERRED, |
126 }; | 132 }; |
127 | 133 |
128 MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED); | 134 explicit MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED); |
129 | 135 |
130 // Run the current MessageLoop unless the quit closure | 136 // Run the current MessageLoop unless the quit closure |
131 // has already been called. | 137 // has already been called. |
132 void Run(); | 138 void Run(); |
133 | 139 |
134 // Quit the matching call to Run (nested MessageLoops are unaffected). | 140 // Quit the matching call to Run (nested MessageLoops are unaffected). |
135 void Quit(); | 141 void Quit(); |
136 | 142 |
137 // Hand this closure off to code that uses callbacks to notify completion. | 143 // Hand this closure off to code that uses callbacks to notify completion. |
138 // Example: | 144 // Example: |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 std::unique_ptr<base::RunLoop> run_loop_; | 286 std::unique_ptr<base::RunLoop> run_loop_; |
281 std::unique_ptr<TestServiceManagerContext> shell_context_; | 287 std::unique_ptr<TestServiceManagerContext> shell_context_; |
282 | 288 |
283 DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThreadHelper); | 289 DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThreadHelper); |
284 }; | 290 }; |
285 | 291 |
286 // This observer keeps track of the last deleted RenderFrame to avoid | 292 // This observer keeps track of the last deleted RenderFrame to avoid |
287 // accessing it and causing use-after-free condition. | 293 // accessing it and causing use-after-free condition. |
288 class RenderFrameDeletedObserver : public WebContentsObserver { | 294 class RenderFrameDeletedObserver : public WebContentsObserver { |
289 public: | 295 public: |
290 RenderFrameDeletedObserver(RenderFrameHost* rfh); | 296 explicit RenderFrameDeletedObserver(RenderFrameHost* rfh); |
291 ~RenderFrameDeletedObserver() override; | 297 ~RenderFrameDeletedObserver() override; |
292 | 298 |
293 // Overridden WebContentsObserver methods. | 299 // Overridden WebContentsObserver methods. |
294 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 300 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
295 | 301 |
296 void WaitUntilDeleted(); | 302 void WaitUntilDeleted(); |
297 bool deleted(); | 303 bool deleted(); |
298 | 304 |
299 private: | 305 private: |
300 int process_id_; | 306 int process_id_; |
(...skipping 18 matching lines...) Expand all Loading... |
319 void WebContentsDestroyed() override; | 325 void WebContentsDestroyed() override; |
320 | 326 |
321 base::RunLoop run_loop_; | 327 base::RunLoop run_loop_; |
322 | 328 |
323 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); | 329 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); |
324 }; | 330 }; |
325 | 331 |
326 } // namespace content | 332 } // namespace content |
327 | 333 |
328 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ | 334 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ |
OLD | NEW |