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

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: Rebase + addressed nit 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 net::URLRequest* request, 352 net::URLRequest* request,
321 content::ResourceContext* resource_context, 353 content::ResourceContext* resource_context,
322 content::AppCacheService* appcache_service, 354 content::AppCacheService* appcache_service,
323 ResourceType resource_type, 355 ResourceType resource_type,
324 ScopedVector<content::ResourceThrottle>* throttles) { 356 ScopedVector<content::ResourceThrottle>* throttles) {
325 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 357 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
326 if (request->url() == url_) 358 if (request->url() == url_)
327 throttles->push_back(new HttpRequestStallThrottle); 359 throttles->push_back(new HttpRequestStallThrottle);
328 } 360 }
329 361
362 TestNavigationManager::TestNavigationManager(WebContents* web_contents,
363 const GURL& url)
364 : WebContentsObserver(web_contents),
365 url_(url),
366 navigation_paused_(false),
367 handle_(nullptr),
368 weak_factory_(this) {}
369
370 TestNavigationManager::~TestNavigationManager() {}
371
372 void TestNavigationManager::WaitForWillStartRequest() {
373 if (navigation_paused_)
374 return;
375 loop_runner_ = new MessageLoopRunner();
376 loop_runner_->Run();
377 loop_runner_ = nullptr;
378 }
379
380 void TestNavigationManager::ResumeNavigation() {
381 if (!navigation_paused_ || !handle_)
382 return;
383 navigation_paused_ = false;
384 handle_->Resume();
385 }
386
387 void TestNavigationManager::WaitForNavigationFinished() {
388 if (!handle_)
389 return;
390 loop_runner_ = new MessageLoopRunner();
391 loop_runner_->Run();
392 loop_runner_ = nullptr;
393 }
394
395 void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) {
396 if (handle_ || handle->GetURL() != url_)
397 return;
398
399 handle_ = handle;
400 scoped_ptr<NavigationThrottle> throttle(new TestNavigationManagerThrottle(
401 handle_, base::Bind(&TestNavigationManager::OnWillStartRequest,
402 weak_factory_.GetWeakPtr())));
403 handle_->RegisterThrottleForTesting(std::move(throttle));
404 }
405
406 void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) {
407 if (handle != handle_)
408 return;
409 handle_ = nullptr;
410 navigation_paused_ = false;
411 if (loop_runner_)
412 loop_runner_->Quit();
413 }
414
415 void TestNavigationManager::OnWillStartRequest() {
416 navigation_paused_ = true;
417 if (loop_runner_)
418 loop_runner_->Quit();
419 }
420
330 } // namespace content 421 } // namespace content
OLDNEW
« no previous file with comments | « content/test/content_browser_test_utils_internal.h ('k') | content/test/data/hang_before_unload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698