Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: content/public/test/test_utils.h

Issue 2946113002: Use FrameIsAd to decide whether to isolate a frame in TopDocumentIsolation mode. (Closed)
Patch Set: Addressing CR feedback from creis@. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 78
78 // Returns true if all sites are isolated. Typically used to bail from a test 79 // Returns true if all sites are isolated. Typically used to bail from a test
79 // that is incompatible with --site-per-process. 80 // that is incompatible with --site-per-process.
80 bool AreAllSitesIsolatedForTesting(); 81 bool AreAllSitesIsolatedForTesting();
81 82
82 // Appends --site-per-process to the command line, enabling tests to exercise 83 // Appends --site-per-process to the command line, enabling tests to exercise
83 // site isolation and cross-process iframes. This must be called early in 84 // site isolation and cross-process iframes. This must be called early in
84 // the test; the flag will be read on the first real navigation. 85 // the test; the flag will be read on the first real navigation.
85 void IsolateAllSitesForTesting(base::CommandLine* command_line); 86 void IsolateAllSitesForTesting(base::CommandLine* command_line);
86 87
88 // Enables a testing mode for TopDocumentIsolation by 1) enabling
89 // features::kTopDocumentIsolation via |scoped_feature_list| and 2) forcing a
90 // mode that isolates all cross-site frames.
91 void EnableTopDocumentIsolationForTesting(base::CommandLine* command_line);
92
87 // Resets the internal secure schemes/origins whitelist. 93 // Resets the internal secure schemes/origins whitelist.
88 void ResetSchemesAndOriginsWhitelist(); 94 void ResetSchemesAndOriginsWhitelist();
89 95
90 #if defined(OS_ANDROID) 96 #if defined(OS_ANDROID)
91 // Registers content/browser JNI bindings necessary for some types of tests. 97 // Registers content/browser JNI bindings necessary for some types of tests.
92 bool RegisterJniForTesting(JNIEnv* env); 98 bool RegisterJniForTesting(JNIEnv* env);
93 #endif 99 #endif
94 100
95 // Helper class to Run and Quit the message loop. Run and Quit can only happen 101 // Helper class to Run and Quit the message loop. Run and Quit can only happen
96 // once per instance. Make a new instance for each use. Calling Quit after Run 102 // once per instance. Make a new instance for each use. Calling Quit after Run
97 // has returned is safe and has no effect. 103 // has returned is safe and has no effect.
98 // Note that by default Quit does not quit immediately. If that is not what you 104 // Note that by default Quit does not quit immediately. If that is not what you
99 // really need, pass QuitMode::IMMEDIATE in the constructor. 105 // really need, pass QuitMode::IMMEDIATE in the constructor.
100 // 106 //
101 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is 107 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is
102 // not needed. If you need to defer quitting the loop, use 108 // not needed. If you need to defer quitting the loop, use
103 // GetDeferredQuitTaskForRunLoop directly. 109 // GetDeferredQuitTaskForRunLoop directly.
104 // If you found a case where base::RunLoop is inconvenient or can not be used at 110 // If you found a case where base::RunLoop is inconvenient or can not be used at
105 // all, please post details in a comment on https://crbug.com/668707. 111 // all, please post details in a comment on https://crbug.com/668707.
106 class MessageLoopRunner : public base::RefCountedThreadSafe<MessageLoopRunner> { 112 class MessageLoopRunner : public base::RefCountedThreadSafe<MessageLoopRunner> {
107 public: 113 public:
108 enum class QuitMode { 114 enum class QuitMode {
109 // Message loop stops after finishing the current task. 115 // Message loop stops after finishing the current task.
110 IMMEDIATE, 116 IMMEDIATE,
111 117
112 // Several generations of posted tasks are executed before stopping. 118 // Several generations of posted tasks are executed before stopping.
113 DEFERRED, 119 DEFERRED,
114 }; 120 };
115 121
116 MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED); 122 explicit MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED);
117 123
118 // Run the current MessageLoop unless the quit closure 124 // Run the current MessageLoop unless the quit closure
119 // has already been called. 125 // has already been called.
120 void Run(); 126 void Run();
121 127
122 // Quit the matching call to Run (nested MessageLoops are unaffected). 128 // Quit the matching call to Run (nested MessageLoops are unaffected).
123 void Quit(); 129 void Quit();
124 130
125 // Hand this closure off to code that uses callbacks to notify completion. 131 // Hand this closure off to code that uses callbacks to notify completion.
126 // Example: 132 // Example:
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 std::unique_ptr<base::RunLoop> run_loop_; 274 std::unique_ptr<base::RunLoop> run_loop_;
269 std::unique_ptr<TestServiceManagerContext> shell_context_; 275 std::unique_ptr<TestServiceManagerContext> shell_context_;
270 276
271 DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThreadHelper); 277 DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThreadHelper);
272 }; 278 };
273 279
274 // This observer keeps track of the last deleted RenderFrame to avoid 280 // This observer keeps track of the last deleted RenderFrame to avoid
275 // accessing it and causing use-after-free condition. 281 // accessing it and causing use-after-free condition.
276 class RenderFrameDeletedObserver : public WebContentsObserver { 282 class RenderFrameDeletedObserver : public WebContentsObserver {
277 public: 283 public:
278 RenderFrameDeletedObserver(RenderFrameHost* rfh); 284 explicit RenderFrameDeletedObserver(RenderFrameHost* rfh);
279 ~RenderFrameDeletedObserver() override; 285 ~RenderFrameDeletedObserver() override;
280 286
281 // Overridden WebContentsObserver methods. 287 // Overridden WebContentsObserver methods.
282 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; 288 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
283 289
284 void WaitUntilDeleted(); 290 void WaitUntilDeleted();
285 bool deleted(); 291 bool deleted();
286 292
287 private: 293 private:
288 int process_id_; 294 int process_id_;
(...skipping 18 matching lines...) Expand all
307 void WebContentsDestroyed() override; 313 void WebContentsDestroyed() override;
308 314
309 base::RunLoop run_loop_; 315 base::RunLoop run_loop_;
310 316
311 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); 317 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher);
312 }; 318 };
313 319
314 } // namespace content 320 } // namespace content
315 321
316 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 322 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698