Index: content/test/content_browser_test_utils_internal.cc |
diff --git a/content/test/content_browser_test_utils_internal.cc b/content/test/content_browser_test_utils_internal.cc |
index dad702ccd709105ec0488d78f59470ddc7e75abd..bb3c9691d8c84eafdfe64b2e9d1a18400835ea78 100644 |
--- a/content/test/content_browser_test_utils_internal.cc |
+++ b/content/test/content_browser_test_utils_internal.cc |
@@ -29,11 +29,34 @@ |
#include "content/public/test/browser_test_utils.h" |
#include "content/public/test/content_browser_test_utils.h" |
#include "content/shell/browser/shell.h" |
+#include "content/shell/browser/shell_javascript_dialog_manager.h" |
#include "content/test/test_frame_navigation_observer.h" |
#include "net/url_request/url_request.h" |
namespace content { |
+namespace { |
+ |
+// Helper class used by the NavigationDelayer to pause navigations. |
+class NavigationDelayerThrottle : public NavigationThrottle { |
+ public: |
+ NavigationDelayerThrottle(NavigationHandle* handle, |
+ base::Closure on_paused_closure) |
+ : NavigationThrottle(handle), on_paused_closure_(on_paused_closure) {} |
+ ~NavigationDelayerThrottle() override {} |
+ |
+ private: |
+ // NavigationThrottle implementation. |
+ NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_paused_closure_); |
+ return NavigationThrottle::DEFER; |
+ } |
+ |
+ base::Closure on_paused_closure_; |
+}; |
+ |
+} // namespace |
+ |
void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { |
TestFrameNavigationObserver observer(node); |
NavigationController::LoadURLParams params(url); |
@@ -43,6 +66,13 @@ void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { |
observer.Wait(); |
} |
+void SetProceedByDefaultOnBeforeUnload(Shell* shell, bool proceed) { |
+ ShellJavaScriptDialogManager* manager = |
+ static_cast<ShellJavaScriptDialogManager*>( |
+ shell->GetJavaScriptDialogManager(shell->web_contents())); |
+ manager->set_proceed_beforeunload_default(proceed); |
+} |
+ |
FrameTreeVisualizer::FrameTreeVisualizer() { |
} |
@@ -325,4 +355,62 @@ void NavigationStallDelegate::RequestBeginning( |
throttles->push_back(new HttpRequestStallThrottle); |
} |
+NavigationDelayer::NavigationDelayer(WebContents* web_contents, const GURL& url) |
+ : WebContentsObserver(web_contents), |
+ url_(url), |
+ navigation_paused_(false), |
+ handle_(nullptr), |
+ weak_factory_(this) {} |
+ |
+NavigationDelayer::~NavigationDelayer() {} |
+ |
+void NavigationDelayer::WaitForNavigationPaused() { |
+ if (navigation_paused_) |
+ return; |
+ loop_runner_ = new MessageLoopRunner(); |
nasko
2016/03/29 20:19:06
Why not create it in the constructor?
clamy
2016/03/30 13:31:11
Because we will use it twice, and you can only use
|
+ loop_runner_->Run(); |
+ loop_runner_ = nullptr; |
+} |
+ |
+void NavigationDelayer::WaitForNavigationFinished() { |
+ if (!handle_) |
+ return; |
+ loop_runner_ = new MessageLoopRunner(); |
+ loop_runner_->Run(); |
+ loop_runner_ = nullptr; |
+} |
+ |
+void NavigationDelayer::ResumeNavigation() { |
+ if (!navigation_paused_ || !handle_) |
+ return; |
+ navigation_paused_ = false; |
+ handle_->Resume(); |
+} |
+ |
+void NavigationDelayer::DidStartNavigation(NavigationHandle* handle) { |
+ if (handle_ || handle->GetURL() != url_) |
+ return; |
+ |
+ handle_ = handle; |
+ scoped_ptr<NavigationThrottle> throttle(new NavigationDelayerThrottle( |
+ handle_, base::Bind(&NavigationDelayer::OnPausedNavigation, |
+ weak_factory_.GetWeakPtr()))); |
+ handle_->RegisterThrottleForTesting(std::move(throttle)); |
+} |
+ |
+void NavigationDelayer::DidFinishNavigation(NavigationHandle* handle) { |
+ if (handle != handle_) |
+ return; |
+ handle_ = nullptr; |
+ navigation_paused_ = false; |
+ if (loop_runner_) |
+ loop_runner_->Quit(); |
+} |
+ |
+void NavigationDelayer::OnPausedNavigation() { |
+ navigation_paused_ = true; |
+ if (loop_runner_) |
+ loop_runner_->Quit(); |
+} |
+ |
} // namespace content |