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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl_browsertest.cc

Issue 2635203002: Quit immediately in TestNavigationObserver. (Closed)
Patch Set: Add comment. Created 3 years, 11 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 | « chrome/test/base/ui_test_utils.cc ('k') | content/public/test/test_navigation_observer.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "base/memory/weak_ptr.h"
5 #include "content/browser/frame_host/navigation_handle_impl.h" 6 #include "content/browser/frame_host/navigation_handle_impl.h"
6 #include "content/browser/web_contents/web_contents_impl.h" 7 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
8 #include "content/public/browser/web_contents_observer.h" 9 #include "content/public/browser/web_contents_observer.h"
9 #include "content/public/common/request_context_type.h" 10 #include "content/public/common/request_context_type.h"
10 #include "content/public/test/browser_test_utils.h" 11 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/content_browser_test.h" 12 #include "content/public/test/content_browser_test.h"
12 #include "content/public/test/content_browser_test_utils.h" 13 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/public/test/test_navigation_observer.h" 14 #include "content/public/test/test_navigation_observer.h"
14 #include "content/public/test/test_utils.h" 15 #include "content/public/test/test_utils.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 NavigationThrottle::ThrottleCheckResult will_start_result, 200 NavigationThrottle::ThrottleCheckResult will_start_result,
200 NavigationThrottle::ThrottleCheckResult will_redirect_result, 201 NavigationThrottle::ThrottleCheckResult will_redirect_result,
201 NavigationThrottle::ThrottleCheckResult will_process_result) 202 NavigationThrottle::ThrottleCheckResult will_process_result)
202 : WebContentsObserver(web_contents), 203 : WebContentsObserver(web_contents),
203 will_start_result_(will_start_result), 204 will_start_result_(will_start_result),
204 will_redirect_result_(will_redirect_result), 205 will_redirect_result_(will_redirect_result),
205 will_process_result_(will_process_result), 206 will_process_result_(will_process_result),
206 will_start_called_(0), 207 will_start_called_(0),
207 will_redirect_called_(0), 208 will_redirect_called_(0),
208 will_process_called_(0), 209 will_process_called_(0),
209 navigation_throttle_(nullptr) {} 210 navigation_throttle_(nullptr),
210 ~TestNavigationThrottleInstaller() override{}; 211 weak_factory_(this) {}
212 ~TestNavigationThrottleInstaller() override {}
211 213
212 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } 214 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; }
213 215
214 void WaitForThrottleWillStart() { 216 void WaitForThrottleWillStart() {
215 if (will_start_called_) 217 if (will_start_called_)
216 return; 218 return;
217 will_start_loop_runner_ = new MessageLoopRunner(); 219 will_start_loop_runner_ = new MessageLoopRunner();
218 will_start_loop_runner_->Run(); 220 will_start_loop_runner_->Run();
219 will_start_loop_runner_ = nullptr; 221 will_start_loop_runner_ = nullptr;
220 } 222 }
(...skipping 16 matching lines...) Expand all
237 239
238 int will_start_called() { return will_start_called_; } 240 int will_start_called() { return will_start_called_; }
239 int will_redirect_called() { return will_redirect_called_; } 241 int will_redirect_called() { return will_redirect_called_; }
240 int will_process_called() { return will_process_called_; } 242 int will_process_called() { return will_process_called_; }
241 243
242 private: 244 private:
243 void DidStartNavigation(NavigationHandle* handle) override { 245 void DidStartNavigation(NavigationHandle* handle) override {
244 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( 246 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle(
245 handle, will_start_result_, will_redirect_result_, will_process_result_, 247 handle, will_start_result_, will_redirect_result_, will_process_result_,
246 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, 248 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest,
247 base::Unretained(this)), 249 weak_factory_.GetWeakPtr()),
248 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, 250 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest,
249 base::Unretained(this)), 251 weak_factory_.GetWeakPtr()),
250 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, 252 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse,
251 base::Unretained(this)))); 253 weak_factory_.GetWeakPtr())));
252 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); 254 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get());
253 handle->RegisterThrottleForTesting(std::move(throttle)); 255 handle->RegisterThrottleForTesting(std::move(throttle));
254 } 256 }
255 257
256 void DidFinishNavigation(NavigationHandle* handle) override { 258 void DidFinishNavigation(NavigationHandle* handle) override {
257 if (!navigation_throttle_) 259 if (!navigation_throttle_)
258 return; 260 return;
259 261
260 if (handle == navigation_throttle_->navigation_handle()) 262 if (handle == navigation_throttle_->navigation_handle())
261 navigation_throttle_ = nullptr; 263 navigation_throttle_ = nullptr;
(...skipping 20 matching lines...) Expand all
282 NavigationThrottle::ThrottleCheckResult will_start_result_; 284 NavigationThrottle::ThrottleCheckResult will_start_result_;
283 NavigationThrottle::ThrottleCheckResult will_redirect_result_; 285 NavigationThrottle::ThrottleCheckResult will_redirect_result_;
284 NavigationThrottle::ThrottleCheckResult will_process_result_; 286 NavigationThrottle::ThrottleCheckResult will_process_result_;
285 int will_start_called_; 287 int will_start_called_;
286 int will_redirect_called_; 288 int will_redirect_called_;
287 int will_process_called_; 289 int will_process_called_;
288 TestNavigationThrottle* navigation_throttle_; 290 TestNavigationThrottle* navigation_throttle_;
289 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; 291 scoped_refptr<MessageLoopRunner> will_start_loop_runner_;
290 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; 292 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_;
291 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; 293 scoped_refptr<MessageLoopRunner> will_process_loop_runner_;
294
295 // The throttle installer can be deleted before all tasks posted by its
296 // throttles are run, so it must be referenced via weak pointers.
297 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_;
292 }; 298 };
293 299
294 // Records all navigation start URLs from the WebContents. 300 // Records all navigation start URLs from the WebContents.
295 class NavigationStartUrlRecorder : public WebContentsObserver { 301 class NavigationStartUrlRecorder : public WebContentsObserver {
296 public: 302 public:
297 NavigationStartUrlRecorder(WebContents* web_contents) 303 NavigationStartUrlRecorder(WebContents* web_contents)
298 : WebContentsObserver(web_contents) {} 304 : WebContentsObserver(web_contents) {}
299 305
300 void DidStartNavigation(NavigationHandle* navigation_handle) override { 306 void DidStartNavigation(NavigationHandle* navigation_handle) override {
301 urls_.push_back(navigation_handle->GetURL()); 307 urls_.push_back(navigation_handle->GetURL());
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, 904 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest,
899 StartUrlIsHttpsUpgradedCrossSite) { 905 StartUrlIsHttpsUpgradedCrossSite) {
900 GURL start_url( 906 GURL start_url(
901 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); 907 embedded_test_server()->GetURL("/https_upgrade_cross_site.html"));
902 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); 908 GURL cross_site_iframe_secure_url("https://other.com/title1.html");
903 909
904 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); 910 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url);
905 } 911 }
906 912
907 } // namespace content 913 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.cc ('k') | content/public/test/test_navigation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698