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

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 jkarlin@ and 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
« no previous file with comments | « content/public/common/content_features.cc ('k') | content/public/test/test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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_
OLDNEW
« no previous file with comments | « content/public/common/content_features.cc ('k') | content/public/test/test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698