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 207227e263637a7491ea2494763dd6c03196babc..7e619364361261eb4b4edeca7737053713f34f8a 100644 |
--- a/content/test/content_browser_test_utils_internal.cc |
+++ b/content/test/content_browser_test_utils_internal.cc |
@@ -29,11 +29,36 @@ |
#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 TestNavigationManager to pause navigations. |
+class TestNavigationManagerThrottle : public NavigationThrottle { |
+ public: |
+ TestNavigationManagerThrottle(NavigationHandle* handle, |
+ base::Closure on_will_start_request_closure) |
+ : NavigationThrottle(handle), |
+ on_will_start_request_closure_(on_will_start_request_closure) {} |
+ ~TestNavigationManagerThrottle() override {} |
+ |
+ private: |
+ // NavigationThrottle implementation. |
+ NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
+ on_will_start_request_closure_); |
+ return NavigationThrottle::DEFER; |
+ } |
+ |
+ base::Closure on_will_start_request_closure_; |
+}; |
+ |
+} // namespace |
+ |
void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { |
TestFrameNavigationObserver observer(node); |
NavigationController::LoadURLParams params(url); |
@@ -43,6 +68,13 @@ void NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { |
observer.Wait(); |
} |
+void SetShouldProceedOnBeforeUnload(Shell* shell, bool proceed) { |
+ ShellJavaScriptDialogManager* manager = |
+ static_cast<ShellJavaScriptDialogManager*>( |
+ shell->GetJavaScriptDialogManager(shell->web_contents())); |
+ manager->set_should_proceed_on_beforeunload(proceed); |
+} |
+ |
FrameTreeVisualizer::FrameTreeVisualizer() { |
} |
@@ -327,4 +359,63 @@ void NavigationStallDelegate::RequestBeginning( |
throttles->push_back(new HttpRequestStallThrottle); |
} |
+TestNavigationManager::TestNavigationManager(WebContents* web_contents, |
+ const GURL& url) |
+ : WebContentsObserver(web_contents), |
+ url_(url), |
+ navigation_paused_(false), |
+ handle_(nullptr), |
+ weak_factory_(this) {} |
+ |
+TestNavigationManager::~TestNavigationManager() {} |
+ |
+void TestNavigationManager::WaitForWillStartRequest() { |
+ if (navigation_paused_) |
+ return; |
+ loop_runner_ = new MessageLoopRunner(); |
+ loop_runner_->Run(); |
+ loop_runner_ = nullptr; |
+} |
+ |
+void TestNavigationManager::ResumeNavigation() { |
+ if (!navigation_paused_ || !handle_) |
+ return; |
+ navigation_paused_ = false; |
+ handle_->Resume(); |
+} |
+ |
+void TestNavigationManager::WaitForNavigationFinished() { |
+ if (!handle_) |
+ return; |
+ loop_runner_ = new MessageLoopRunner(); |
+ loop_runner_->Run(); |
+ loop_runner_ = nullptr; |
+} |
+ |
+void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) { |
+ if (handle_ || handle->GetURL() != url_) |
+ return; |
+ |
+ handle_ = handle; |
+ scoped_ptr<NavigationThrottle> throttle(new TestNavigationManagerThrottle( |
+ handle_, base::Bind(&TestNavigationManager::OnWillStartRequest, |
+ weak_factory_.GetWeakPtr()))); |
+ handle_->RegisterThrottleForTesting(std::move(throttle)); |
+} |
+ |
+void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) { |
+ if (handle != handle_) |
+ return; |
+ handle_ = nullptr; |
+ navigation_paused_ = false; |
+ if (loop_runner_) |
+ loop_runner_->Quit(); |
+} |
+ |
+void TestNavigationManager::OnWillStartRequest() { |
+ navigation_paused_ = true; |
+ if (loop_runner_) |
+ loop_runner_->Quit(); |
+} |
+ |
} // namespace content |