Commit a79cb991 authored by asanka@chromium.org's avatar asanka@chromium.org

Add 'waitUntilExternalURLLoad' method to TestRunner.

This method can be used in layout tests to produce log output and end a
test when the WebFrameClient receives a loadURLExternally() call. This
happens if the content attempts to download a resource explicitly.

Required by Blink CL: https://codereview.chromium.org/197033005/

BUG=346744

Review URL: https://codereview.chromium.org/200663002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266377 0039d316-1c4b-4281-b951-d872f2087c98
parent 6a848b53
...@@ -51,6 +51,11 @@ public: ...@@ -51,6 +51,11 @@ public:
const CR_DEFINE_STATIC_LOCAL(WebString, suffix, ("-can-create-without-renderer")); const CR_DEFINE_STATIC_LOCAL(WebString, suffix, ("-can-create-without-renderer"));
return mimeType.utf8().find(suffix.utf8()) != std::string::npos; return mimeType.utf8().find(suffix.utf8()) != std::string::npos;
} }
virtual void loadURLExternally(blink::WebLocalFrame* frame, const blink::WebURLRequest& request, blink::WebNavigationPolicy policy, const blink::WebString& suggested_name)
{
m_baseProxy->loadURLExternally(frame, request, policy, suggested_name);
Base::loadURLExternally(frame, request, policy, suggested_name);
}
virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame) virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame)
{ {
m_baseProxy->didStartProvisionalLoad(frame); m_baseProxy->didStartProvisionalLoad(frame);
......
...@@ -975,6 +975,18 @@ bool WebTestProxyBase::isChooserShown() ...@@ -975,6 +975,18 @@ bool WebTestProxyBase::isChooserShown()
return 0 < m_chooserCount; return 0 < m_chooserCount;
} }
void WebTestProxyBase::loadURLExternally(WebLocalFrame* frame, const WebURLRequest& request, WebNavigationPolicy policy, const WebString& suggested_name)
{
if (m_testInterfaces->testRunner()->shouldWaitUntilExternalURLLoad()) {
if (policy == WebNavigationPolicyDownload) {
m_delegate->printMessage(string("Downloading URL with suggested filename \"") + suggested_name.utf8() + "\"\n");
} else {
m_delegate->printMessage(string("Loading URL externally - \"") + URLDescription(request.url()) + "\"\n");
}
m_delegate->testFinished();
}
}
void WebTestProxyBase::didStartProvisionalLoad(WebLocalFrame* frame) void WebTestProxyBase::didStartProvisionalLoad(WebLocalFrame* frame)
{ {
if (!m_testInterfaces->testRunner()->topLoadingFrame()) if (!m_testInterfaces->testRunner()->topLoadingFrame())
......
...@@ -165,6 +165,7 @@ protected: ...@@ -165,6 +165,7 @@ protected:
void didBlur(); void didBlur();
void setToolTipText(const blink::WebString&, blink::WebTextDirection); void setToolTipText(const blink::WebString&, blink::WebTextDirection);
void didAddMessageToConsole(const blink::WebConsoleMessage&, const blink::WebString& sourceName, unsigned sourceLine); void didAddMessageToConsole(const blink::WebConsoleMessage&, const blink::WebString& sourceName, unsigned sourceLine);
void loadURLExternally(blink::WebLocalFrame* frame, const blink::WebURLRequest& request, blink::WebNavigationPolicy policy, const blink::WebString& suggested_name);
void didStartProvisionalLoad(blink::WebLocalFrame*); void didStartProvisionalLoad(blink::WebLocalFrame*);
void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame*); void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame*);
bool didFailProvisionalLoad(blink::WebLocalFrame*, const blink::WebURLError&); bool didFailProvisionalLoad(blink::WebLocalFrame*, const blink::WebURLError&);
......
...@@ -223,6 +223,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> { ...@@ -223,6 +223,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void SetWillSendRequestClearHeader(const std::string& header); void SetWillSendRequestClearHeader(const std::string& header);
void DumpResourceRequestPriorities(); void DumpResourceRequestPriorities();
void SetUseMockTheme(bool use); void SetUseMockTheme(bool use);
void WaitUntilExternalURLLoad();
void ShowWebInspector(gin::Arguments* args); void ShowWebInspector(gin::Arguments* args);
void CloseWebInspector(); void CloseWebInspector();
bool IsChooserShown(); bool IsChooserShown();
...@@ -444,6 +445,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder( ...@@ -444,6 +445,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
.SetMethod("dumpResourceRequestPriorities", .SetMethod("dumpResourceRequestPriorities",
&TestRunnerBindings::DumpResourceRequestPriorities) &TestRunnerBindings::DumpResourceRequestPriorities)
.SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme) .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
.SetMethod("waitUntilExternalURLLoad",
&TestRunnerBindings::WaitUntilExternalURLLoad)
.SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector) .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
.SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector) .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
.SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown) .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
...@@ -1102,6 +1105,11 @@ void TestRunnerBindings::SetUseMockTheme(bool use) { ...@@ -1102,6 +1105,11 @@ void TestRunnerBindings::SetUseMockTheme(bool use) {
runner_->SetUseMockTheme(use); runner_->SetUseMockTheme(use);
} }
void TestRunnerBindings::WaitUntilExternalURLLoad() {
if (runner_)
runner_->WaitUntilExternalURLLoad();
}
void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) { void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
if (runner_) { if (runner_) {
std::string settings; std::string settings;
...@@ -1423,6 +1431,7 @@ void TestRunner::Reset() { ...@@ -1423,6 +1431,7 @@ void TestRunner::Reset() {
top_loading_frame_ = NULL; top_loading_frame_ = NULL;
wait_until_done_ = false; wait_until_done_ = false;
wait_until_external_url_load_ = false;
policy_delegate_enabled_ = false; policy_delegate_enabled_ = false;
policy_delegate_is_permissive_ = false; policy_delegate_is_permissive_ = false;
policy_delegate_should_notify_done_ = false; policy_delegate_should_notify_done_ = false;
...@@ -1643,6 +1652,10 @@ bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const { ...@@ -1643,6 +1652,10 @@ bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
return should_stay_on_page_after_handling_before_unload_; return should_stay_on_page_after_handling_before_unload_;
} }
bool TestRunner::shouldWaitUntilExternalURLLoad() const {
return wait_until_external_url_load_;
}
const std::set<std::string>* TestRunner::httpHeadersToClear() const { const std::set<std::string>* TestRunner::httpHeadersToClear() const {
return &http_headers_to_clear_; return &http_headers_to_clear_;
} }
...@@ -2471,6 +2484,10 @@ void TestRunner::ShowWebInspector(const std::string& str, ...@@ -2471,6 +2484,10 @@ void TestRunner::ShowWebInspector(const std::string& str,
showDevTools(str, frontend_url); showDevTools(str, frontend_url);
} }
void TestRunner::WaitUntilExternalURLLoad() {
wait_until_external_url_load_ = true;
}
void TestRunner::CloseWebInspector() { void TestRunner::CloseWebInspector() {
delegate_->closeDevTools(); delegate_->closeDevTools();
} }
......
...@@ -105,6 +105,7 @@ class TestRunner : public ::WebTestRunner::WebTestRunner, ...@@ -105,6 +105,7 @@ class TestRunner : public ::WebTestRunner::WebTestRunner,
bool shouldDumpProgressFinishedCallback() const; bool shouldDumpProgressFinishedCallback() const;
bool shouldDumpSpellCheckCallbacks() const; bool shouldDumpSpellCheckCallbacks() const;
bool shouldStayOnPageAfterHandlingBeforeUnload() const; bool shouldStayOnPageAfterHandlingBeforeUnload() const;
bool shouldWaitUntilExternalURLLoad() const;
const std::set<std::string>* httpHeadersToClear() const; const std::set<std::string>* httpHeadersToClear() const;
void setTopLoadingFrame(blink::WebFrame*, bool); void setTopLoadingFrame(blink::WebFrame*, bool);
blink::WebFrame* topLoadingFrame() const; blink::WebFrame* topLoadingFrame() const;
...@@ -443,6 +444,10 @@ class TestRunner : public ::WebTestRunner::WebTestRunner, ...@@ -443,6 +444,10 @@ class TestRunner : public ::WebTestRunner::WebTestRunner,
// Sets a flag to enable the mock theme. // Sets a flag to enable the mock theme.
void SetUseMockTheme(bool use); void SetUseMockTheme(bool use);
// Sets a flag that causes the test to be marked as completed when the
// WebFrameClient receives a loadURLExternally() call.
void WaitUntilExternalURLLoad();
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Methods interacting with the WebTestProxy // Methods interacting with the WebTestProxy
...@@ -534,6 +539,10 @@ class TestRunner : public ::WebTestRunner::WebTestRunner, ...@@ -534,6 +539,10 @@ class TestRunner : public ::WebTestRunner::WebTestRunner,
// If true, don't dump output until notifyDone is called. // If true, don't dump output until notifyDone is called.
bool wait_until_done_; bool wait_until_done_;
// If true, ends the test when a URL is loaded externally via
// WebFrameClient::loadURLExternally().
bool wait_until_external_url_load_;
// Causes navigation actions just printout the intended navigation instead // Causes navigation actions just printout the intended navigation instead
// of taking you to the page. This is used for cases like mailto, where you // of taking you to the page. This is used for cases like mailto, where you
// don't actually want to open the mail program. // don't actually want to open the mail program.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment