OLD | NEW |
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 Loading... |
22 #include "content/browser/frame_host/frame_tree_node.h" | 22 #include "content/browser/frame_host/frame_tree_node.h" |
23 #include "content/browser/frame_host/navigator.h" | 23 #include "content/browser/frame_host/navigator.h" |
24 #include "content/browser/frame_host/render_frame_proxy_host.h" | 24 #include "content/browser/frame_host/render_frame_proxy_host.h" |
25 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 25 #include "content/browser/frame_host/render_widget_host_view_child_frame.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 NavigationDelayer to pause navigations. |
| 41 class NavigationDelayerThrottle : public NavigationThrottle { |
| 42 public: |
| 43 NavigationDelayerThrottle(NavigationHandle* handle, |
| 44 base::Closure on_paused_closure) |
| 45 : NavigationThrottle(handle), on_paused_closure_(on_paused_closure) {} |
| 46 ~NavigationDelayerThrottle() override {} |
| 47 |
| 48 private: |
| 49 // NavigationThrottle implementation. |
| 50 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
| 51 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_paused_closure_); |
| 52 return NavigationThrottle::DEFER; |
| 53 } |
| 54 |
| 55 base::Closure on_paused_closure_; |
| 56 }; |
| 57 |
| 58 } // namespace |
| 59 |
37 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { | 60 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { |
38 TestFrameNavigationObserver observer(node); | 61 TestFrameNavigationObserver observer(node); |
39 NavigationController::LoadURLParams params(url); | 62 NavigationController::LoadURLParams params(url); |
40 params.transition_type = ui::PAGE_TRANSITION_LINK; | 63 params.transition_type = ui::PAGE_TRANSITION_LINK; |
41 params.frame_tree_node_id = node->frame_tree_node_id(); | 64 params.frame_tree_node_id = node->frame_tree_node_id(); |
42 node->navigator()->GetController()->LoadURLWithParams(params); | 65 node->navigator()->GetController()->LoadURLWithParams(params); |
43 observer.Wait(); | 66 observer.Wait(); |
44 } | 67 } |
45 | 68 |
| 69 void SetProceedByDefaultOnBeforeUnload(Shell* shell, bool proceed) { |
| 70 ShellJavaScriptDialogManager* manager = |
| 71 static_cast<ShellJavaScriptDialogManager*>( |
| 72 shell->GetJavaScriptDialogManager(shell->web_contents())); |
| 73 manager->set_proceed_beforeunload_default(proceed); |
| 74 } |
| 75 |
46 FrameTreeVisualizer::FrameTreeVisualizer() { | 76 FrameTreeVisualizer::FrameTreeVisualizer() { |
47 } | 77 } |
48 | 78 |
49 FrameTreeVisualizer::~FrameTreeVisualizer() { | 79 FrameTreeVisualizer::~FrameTreeVisualizer() { |
50 } | 80 } |
51 | 81 |
52 std::string FrameTreeVisualizer::DepictFrameTree(FrameTreeNode* root) { | 82 std::string FrameTreeVisualizer::DepictFrameTree(FrameTreeNode* root) { |
53 // Tracks the sites actually used in this depiction. | 83 // Tracks the sites actually used in this depiction. |
54 std::map<std::string, SiteInstance*> legend; | 84 std::map<std::string, SiteInstance*> legend; |
55 | 85 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 net::URLRequest* request, | 348 net::URLRequest* request, |
319 content::ResourceContext* resource_context, | 349 content::ResourceContext* resource_context, |
320 content::AppCacheService* appcache_service, | 350 content::AppCacheService* appcache_service, |
321 ResourceType resource_type, | 351 ResourceType resource_type, |
322 ScopedVector<content::ResourceThrottle>* throttles) { | 352 ScopedVector<content::ResourceThrottle>* throttles) { |
323 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 353 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
324 if (request->url() == url_) | 354 if (request->url() == url_) |
325 throttles->push_back(new HttpRequestStallThrottle); | 355 throttles->push_back(new HttpRequestStallThrottle); |
326 } | 356 } |
327 | 357 |
| 358 NavigationDelayer::NavigationDelayer(WebContents* web_contents, const GURL& url) |
| 359 : WebContentsObserver(web_contents), |
| 360 url_(url), |
| 361 navigation_paused_(false), |
| 362 handle_(nullptr), |
| 363 weak_factory_(this) {} |
| 364 |
| 365 NavigationDelayer::~NavigationDelayer() {} |
| 366 |
| 367 void NavigationDelayer::WaitForNavigationPaused() { |
| 368 if (navigation_paused_) |
| 369 return; |
| 370 loop_runner_ = new MessageLoopRunner(); |
| 371 loop_runner_->Run(); |
| 372 loop_runner_ = nullptr; |
| 373 } |
| 374 |
| 375 void NavigationDelayer::WaitForNavigationFinished() { |
| 376 if (!handle_) |
| 377 return; |
| 378 loop_runner_ = new MessageLoopRunner(); |
| 379 loop_runner_->Run(); |
| 380 loop_runner_ = nullptr; |
| 381 } |
| 382 |
| 383 void NavigationDelayer::ResumeNavigation() { |
| 384 if (!navigation_paused_ || !handle_) |
| 385 return; |
| 386 navigation_paused_ = false; |
| 387 handle_->Resume(); |
| 388 } |
| 389 |
| 390 void NavigationDelayer::DidStartNavigation(NavigationHandle* handle) { |
| 391 if (handle_ || handle->GetURL() != url_) |
| 392 return; |
| 393 |
| 394 handle_ = handle; |
| 395 scoped_ptr<NavigationThrottle> throttle(new NavigationDelayerThrottle( |
| 396 handle_, base::Bind(&NavigationDelayer::OnPausedNavigation, |
| 397 weak_factory_.GetWeakPtr()))); |
| 398 handle_->RegisterThrottleForTesting(std::move(throttle)); |
| 399 } |
| 400 |
| 401 void NavigationDelayer::DidFinishNavigation(NavigationHandle* handle) { |
| 402 if (handle != handle_) |
| 403 return; |
| 404 handle_ = nullptr; |
| 405 navigation_paused_ = false; |
| 406 if (loop_runner_) |
| 407 loop_runner_->Quit(); |
| 408 } |
| 409 |
| 410 void NavigationDelayer::OnPausedNavigation() { |
| 411 navigation_paused_ = true; |
| 412 if (loop_runner_) |
| 413 loop_runner_->Quit(); |
| 414 } |
| 415 |
328 } // namespace content | 416 } // namespace content |
OLD | NEW |