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

Side by Side Diff: content/test/content_browser_test_utils_internal.cc

Issue 1825523002: Do not reset navigation state when BeforeUnload is cancelled by a commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/test/content_browser_test_utils_internal.h" 5 #include "content/test/content_browser_test_utils_internal.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 11 matching lines...) Expand all
22 #include "content/browser/frame_host/navigator.h" 22 #include "content/browser/frame_host/navigator.h"
23 #include "content/browser/frame_host/render_frame_proxy_host.h" 23 #include "content/browser/frame_host/render_frame_proxy_host.h"
24 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 24 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
25 #include "content/browser/renderer_host/delegated_frame_host.h" 25 #include "content/browser/renderer_host/delegated_frame_host.h"
26 #include "content/browser/renderer_host/render_widget_host_view_base.h" 26 #include "content/browser/renderer_host/render_widget_host_view_base.h"
27 #include "content/public/browser/resource_dispatcher_host.h" 27 #include "content/public/browser/resource_dispatcher_host.h"
28 #include "content/public/browser/resource_throttle.h" 28 #include "content/public/browser/resource_throttle.h"
29 #include "content/public/test/browser_test_utils.h" 29 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/content_browser_test_utils.h" 30 #include "content/public/test/content_browser_test_utils.h"
31 #include "content/shell/browser/shell.h" 31 #include "content/shell/browser/shell.h"
32 #include "content/shell/browser/shell_javascript_dialog_manager.h"
32 #include "content/test/test_frame_navigation_observer.h" 33 #include "content/test/test_frame_navigation_observer.h"
33 #include "net/url_request/url_request.h" 34 #include "net/url_request/url_request.h"
34 35
35 namespace content { 36 namespace content {
36 37
38 namespace {
39
40 // Helper class used by the TestNavigationManager to pause navigations.
41 class TestNavigationManagerThrottle : public NavigationThrottle {
42 public:
43 TestNavigationManagerThrottle(NavigationHandle* handle,
44 base::Closure on_will_start_request_closure)
45 : NavigationThrottle(handle),
46 on_will_start_request_closure_(on_will_start_request_closure) {}
47 ~TestNavigationManagerThrottle() override {}
48
49 private:
50 // NavigationThrottle implementation.
51 NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
52 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
53 on_will_start_request_closure_);
54 return NavigationThrottle::DEFER;
55 }
56
57 base::Closure on_will_start_request_closure_;
58 };
59
60 } // namespace
61
37 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { 62 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) {
38 TestFrameNavigationObserver observer(node); 63 TestFrameNavigationObserver observer(node);
39 NavigationController::LoadURLParams params(url); 64 NavigationController::LoadURLParams params(url);
40 params.transition_type = ui::PAGE_TRANSITION_LINK; 65 params.transition_type = ui::PAGE_TRANSITION_LINK;
41 params.frame_tree_node_id = node->frame_tree_node_id(); 66 params.frame_tree_node_id = node->frame_tree_node_id();
42 node->navigator()->GetController()->LoadURLWithParams(params); 67 node->navigator()->GetController()->LoadURLWithParams(params);
43 observer.Wait(); 68 observer.Wait();
44 } 69 }
45 70
71 void SetShouldProceedOnBeforeUnload(Shell* shell, bool proceed) {
72 ShellJavaScriptDialogManager* manager =
73 static_cast<ShellJavaScriptDialogManager*>(
74 shell->GetJavaScriptDialogManager(shell->web_contents()));
75 manager->set_should_proceed_on_beforeunload(proceed);
76 }
77
46 FrameTreeVisualizer::FrameTreeVisualizer() { 78 FrameTreeVisualizer::FrameTreeVisualizer() {
47 } 79 }
48 80
49 FrameTreeVisualizer::~FrameTreeVisualizer() { 81 FrameTreeVisualizer::~FrameTreeVisualizer() {
50 } 82 }
51 83
52 std::string FrameTreeVisualizer::DepictFrameTree(FrameTreeNode* root) { 84 std::string FrameTreeVisualizer::DepictFrameTree(FrameTreeNode* root) {
53 // Tracks the sites actually used in this depiction. 85 // Tracks the sites actually used in this depiction.
54 std::map<std::string, SiteInstance*> legend; 86 std::map<std::string, SiteInstance*> legend;
55 87
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 net::URLRequest* request, 350 net::URLRequest* request,
319 content::ResourceContext* resource_context, 351 content::ResourceContext* resource_context,
320 content::AppCacheService* appcache_service, 352 content::AppCacheService* appcache_service,
321 ResourceType resource_type, 353 ResourceType resource_type,
322 ScopedVector<content::ResourceThrottle>* throttles) { 354 ScopedVector<content::ResourceThrottle>* throttles) {
323 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 355 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
324 if (request->url() == url_) 356 if (request->url() == url_)
325 throttles->push_back(new HttpRequestStallThrottle); 357 throttles->push_back(new HttpRequestStallThrottle);
326 } 358 }
327 359
360 TestNavigationManager::TestNavigationManager(WebContents* web_contents,
361 const GURL& url)
362 : WebContentsObserver(web_contents),
363 url_(url),
364 navigation_paused_(false),
365 handle_(nullptr),
366 weak_factory_(this) {}
367
368 TestNavigationManager::~TestNavigationManager() {}
369
370 void TestNavigationManager::WaitForWillStartRequest() {
371 if (navigation_paused_)
372 return;
373 loop_runner_ = new MessageLoopRunner();
374 loop_runner_->Run();
375 loop_runner_ = nullptr;
376 }
377
378 void TestNavigationManager::WaitForNavigationFinished() {
379 if (!handle_)
380 return;
381 loop_runner_ = new MessageLoopRunner();
382 loop_runner_->Run();
383 loop_runner_ = nullptr;
384 }
385
386 void TestNavigationManager::ResumeNavigation() {
387 if (!navigation_paused_ || !handle_)
388 return;
389 navigation_paused_ = false;
390 handle_->Resume();
391 }
392
393 void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) {
394 if (handle_ || handle->GetURL() != url_)
395 return;
396
397 handle_ = handle;
398 scoped_ptr<NavigationThrottle> throttle(new TestNavigationManagerThrottle(
399 handle_, base::Bind(&TestNavigationManager::OnWillStartRequest,
400 weak_factory_.GetWeakPtr())));
401 handle_->RegisterThrottleForTesting(std::move(throttle));
402 }
403
404 void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) {
405 if (handle != handle_)
406 return;
407 handle_ = nullptr;
408 navigation_paused_ = false;
409 if (loop_runner_)
410 loop_runner_->Quit();
411 }
412
413 void TestNavigationManager::OnWillStartRequest() {
414 navigation_paused_ = true;
415 if (loop_runner_)
416 loop_runner_->Quit();
417 }
418
328 } // namespace content 419 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698