Commit 1ca4fac0 authored by jochen@chromium.org's avatar jochen@chromium.org

[content shell] add support for invoking testRunner.notifyDone in a different process

Some layout tests, e.g.
http/tests/navigation/no-referrer-target-blank.html create a new
process, and notifyDone() will be invoked in that new process. Add
support for forwarding that signal to the main test runner.

BUG=111316
R=mkwst@chromium.org
TEST=http/tests/navigation/no-referrer-target-blank.html does not time out

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192819 0039d316-1c4b-4281-b951-d872f2087c98
parent 8b830e96
......@@ -68,6 +68,8 @@
'shell/geolocation/shell_access_token_store.h',
'shell/minimal_ash.cc',
'shell/minimal_ash.h',
'shell/notify_done_forwarder.cc',
'shell/notify_done_forwarder.h',
'shell/paths_mac.h',
'shell/paths_mac.mm',
'shell/shell.cc',
......
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/shell/notify_done_forwarder.h"
#include "content/shell/shell_messages.h"
#include "content/shell/webkit_test_controller.h"
namespace content {
DEFINE_WEB_CONTENTS_USER_DATA_KEY(NotifyDoneForwarder);
NotifyDoneForwarder::NotifyDoneForwarder(WebContents* web_contents)
: WebContentsObserver(web_contents) {}
NotifyDoneForwarder::~NotifyDoneForwarder() {}
bool NotifyDoneForwarder::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(NotifyDoneForwarder, message)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_TestFinishedInSecondaryWindow,
OnTestFinishedInSecondaryWindow)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void NotifyDoneForwarder::OnTestFinishedInSecondaryWindow() {
WebKitTestController::Get()->TestFinishedInSecondaryWindow();
}
} // namespace content
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_SHELL_NOTIFY_DONE_FORWARDER_H_
#define CONTENT_SHELL_NOTIFY_DONE_FORWARDER_H_
#include "base/basictypes.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class NotifyDoneForwarder : public WebContentsObserver,
public WebContentsUserData<NotifyDoneForwarder> {
public:
virtual ~NotifyDoneForwarder();
// WebContentsObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
private:
friend class WebContentsUserData<NotifyDoneForwarder>;
explicit NotifyDoneForwarder(WebContents* web_contents);
void OnTestFinishedInSecondaryWindow();
DISALLOW_COPY_AND_ASSIGN(NotifyDoneForwarder);
};
} // namespace content
#endif // CONTENT_SHELL_NOTIFY_DONE_FORWARDER_H_
......@@ -22,6 +22,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/renderer_preferences.h"
#include "content/shell/notify_done_forwarder.h"
#include "content/shell/shell_browser_main_parts.h"
#include "content/shell/shell_content_browser_client.h"
#include "content/shell/shell_devtools_frontend.h"
......@@ -263,6 +264,8 @@ void Shell::WebContentsCreated(WebContents* source_contents,
const GURL& target_url,
WebContents* new_contents) {
CreateShell(new_contents);
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
NotifyDoneForwarder::CreateForWebContents(new_contents);
}
void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
......
......@@ -39,6 +39,10 @@ IPC_MESSAGE_CONTROL1(ShellViewMsg_LoadHyphenDictionary,
IPC_MESSAGE_ROUTED1(ShellViewMsg_SetTestConfiguration,
content::ShellTestConfiguration)
// Tells the main window that a secondary window in a different process invoked
// notifyDone().
IPC_MESSAGE_ROUTED0(ShellViewMsg_NotifyDone)
// Pushes a snapshot of the current session history from the browser process.
// This includes only information about those RenderViews that are in the
// same process as the main window of the layout test and that are the current
......@@ -67,6 +71,8 @@ IPC_MESSAGE_ROUTED1(ShellViewHostMsg_TestFinished,
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_ResetDone)
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_TestFinishedInSecondaryWindow)
// WebTestDelegate related.
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_OverridePreferences,
webkit_glue::WebPreferences /* preferences */)
......
......@@ -309,6 +309,13 @@ void WebKitTestController::OpenURL(const GURL& url) {
gfx::Size());
}
void WebKitTestController::TestFinishedInSecondaryWindow() {
RenderViewHost* render_view_host =
main_window_->web_contents()->GetRenderViewHost();
render_view_host->Send(
new ShellViewMsg_NotifyDone(render_view_host->GetRoutingID()));
}
bool WebKitTestController::OnMessageReceived(const IPC::Message& message) {
DCHECK(CalledOnValidThread());
bool handled = true;
......
......@@ -94,6 +94,7 @@ class WebKitTestController : public base::NonThreadSafe,
void RendererUnresponsive();
void OverrideWebkitPrefs(webkit_glue::WebPreferences* prefs);
void OpenURL(const GURL& url);
void TestFinishedInSecondaryWindow();
WebKitTestResultPrinter* printer() { return printer_.get(); }
void set_printer(WebKitTestResultPrinter* printer) {
......
......@@ -47,6 +47,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTestingSupport.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h"
......@@ -73,6 +74,7 @@ using WebKit::WebMediaPlayer;
using WebKit::WebMediaPlayerClient;
using WebKit::WebPoint;
using WebKit::WebRect;
using WebKit::WebScriptSource;
using WebKit::WebSize;
using WebKit::WebString;
using WebKit::WebURL;
......@@ -405,8 +407,10 @@ void WebKitTestRunner::setLocale(const std::string& locale) {
}
void WebKitTestRunner::testFinished() {
if (!is_main_window_)
if (!is_main_window_) {
Send(new ShellViewHostMsg_TestFinishedInSecondaryWindow(routing_id()));
return;
}
WebTestInterfaces* interfaces =
ShellRenderProcessObserver::GetInstance()->test_interfaces();
interfaces->setTestIsRunning(false);
......@@ -517,6 +521,7 @@ bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
OnSetTestConfiguration)
IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory, OnSessionHistory)
IPC_MESSAGE_HANDLER(ShellViewMsg_Reset, OnReset)
IPC_MESSAGE_HANDLER(ShellViewMsg_NotifyDone, OnNotifyDone)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
......@@ -525,6 +530,13 @@ bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
void WebKitTestRunner::Navigate(const GURL& url) {
focus_on_next_commit_ = true;
if (!is_main_window_ &&
ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) {
WebTestInterfaces* interfaces =
ShellRenderProcessObserver::GetInstance()->test_interfaces();
interfaces->setTestIsRunning(true);
interfaces->configureForTestWithURL(GURL(), false);
}
}
void WebKitTestRunner::DidCommitProvisionalLoad(WebFrame* frame,
......@@ -661,4 +673,9 @@ void WebKitTestRunner::OnReset() {
Send(new ShellViewHostMsg_ResetDone(routing_id()));
}
void WebKitTestRunner::OnNotifyDone() {
render_view()->GetWebView()->mainFrame()->executeScript(
WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();")));
}
} // namespace content
......@@ -114,6 +114,7 @@ class WebKitTestRunner : public RenderViewObserver,
const std::vector<std::vector<std::string> >& session_histories,
const std::vector<unsigned>& current_entry_indexes);
void OnReset();
void OnNotifyDone();
// After finishing the test, retrieves the audio, text, and pixel dumps from
// the TestRunner library and sends them to the browser process.
......
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