Commit 34594939 authored by morrita@chromium.org's avatar morrita@chromium.org

Add IPC benchmarking API to Blink TestRunner

This add an window.testRunner API that sends do-nothing IPC message
roundtrip. This API can be used to build IPC benchmark using
JavaScript.

TEST=none (Will add blink-side LayoutTest once this is landed)
BUG=402185
R=darin@chromium.org, jam@chromim.org, jochen@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#290063}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290063 0039d316-1c4b-4281-b951-d872f2087c98
parent dee45a43
......@@ -166,6 +166,8 @@
'shell/geolocation/shell_access_token_store.h',
'shell/renderer/gc_controller.cc',
'shell/renderer/gc_controller.h',
'shell/renderer/ipc_echo.cc',
'shell/renderer/ipc_echo.h',
'shell/renderer/leak_detector.cc',
'shell/renderer/leak_detector.h',
'shell/renderer/shell_content_renderer_client.cc',
......
......@@ -115,6 +115,8 @@ static_library("content_shell_lib") {
"geolocation/shell_access_token_store.h",
"renderer/gc_controller.cc",
"renderer/gc_controller.h",
"renderer/ipc_echo.cc",
"renderer/ipc_echo.h",
"renderer/leak_detector.cc",
"renderer/leak_detector.h",
"renderer/shell_content_renderer_client.cc",
......
......@@ -389,6 +389,7 @@ bool WebKitTestController::OnMessageReceived(const IPC::Message& message) {
OnCloseRemainingWindows)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_ResetDone, OnResetDone)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_LeakDetectionDone, OnLeakDetectionDone)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_EchoPing, OnEchoPing)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
......@@ -693,4 +694,14 @@ void WebKitTestController::OnLeakDetectionDone(
DiscardMainWindow();
}
void WebKitTestController::OnEchoPing(int id, const std::string& body) {
if (main_window_ && main_window_->web_contents()) {
RenderViewHost* render_view_host =
main_window_->web_contents()->GetRenderViewHost();
render_view_host->Send(
new ShellViewMsg_EchoPong(render_view_host->GetRoutingID(), id, body));
}
}
} // namespace content
......@@ -177,6 +177,7 @@ class WebKitTestController : public base::NonThreadSafe,
void OnCloseRemainingWindows();
void OnResetDone();
void OnLeakDetectionDone(const content::LeakDetectionResult& result);
void OnEchoPing(int id, const std::string& body);
scoped_ptr<WebKitTestResultPrinter> printer_;
......
......@@ -113,6 +113,13 @@ IPC_MESSAGE_ROUTED1(ShellViewHostMsg_SetDeviceScaleFactor,
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_CaptureSessionHistory)
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_CloseRemainingWindows)
IPC_MESSAGE_ROUTED2(ShellViewHostMsg_EchoPing,
int /* id */,
std::string /* body */)
IPC_MESSAGE_ROUTED2(ShellViewMsg_EchoPong,
int /* id */,
std::string /* body */)
IPC_STRUCT_TRAITS_BEGIN(content::LeakDetectionResult)
IPC_STRUCT_TRAITS_MEMBER(leaked)
IPC_STRUCT_TRAITS_MEMBER(detail)
......
// Copyright 2014 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/renderer/ipc_echo.h"
#include "base/logging.h"
#include "content/shell/common/shell_messages.h"
#include "ipc/ipc_sender.h"
#include "third_party/WebKit/public/web/WebDOMCustomEvent.h"
#include "third_party/WebKit/public/web/WebDOMEvent.h"
#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
namespace content {
IPCEcho::IPCEcho(blink::WebDocument document,
IPC::Sender* sender,
int routing_id)
: document_(document), sender_(sender), routing_id_(routing_id),
last_echo_id_(0) {
}
void IPCEcho::RequestEcho(int id, int size) {
sender_->Send(new ShellViewHostMsg_EchoPing(
routing_id_, id, std::string(size, '*')));
}
void IPCEcho::DidRespondEcho(int id, int size) {
last_echo_id_ = id;
last_echo_size_ = size;
blink::WebString eventName = blink::WebString::fromUTF8("CustomEvent");
blink::WebString eventType = blink::WebString::fromUTF8("pong");
blink::WebDOMEvent event = document_.createEvent(eventName);
event.to<blink::WebDOMCustomEvent>().initCustomEvent(
eventType, false, false, blink::WebSerializedScriptValue());
document_.dispatchEvent(event);
}
} // namespace content
// Copyright 2014 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_IPC_ECHO_H_
#define CONTENT_SHELL_IPC_ECHO_H_
#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "third_party/WebKit/public/web/WebDocument.h"
namespace IPC {
class Sender;
}
namespace content {
// This class is for writing micro benchmarks exercising underlying
// IPC::Channel using HTML and JavaScript.
//
// TODO(morrita): The benchmark effort tries to makesure that
// IPC::ChannelMojo is as performant as native IPC::Channel
// implementations. Currently IPC::ChannelMojo is hidden behind
// "--enable-renderer-mojo-channel". Once it is turned on by default.
// we no longer need this class and should remove it.
class IPCEcho {
public:
IPCEcho(blink::WebDocument document, IPC::Sender* sender, int routing_id);
void RequestEcho(int id, int size);
void DidRespondEcho(int id, int size);
int last_echo_id() const { return last_echo_id_; }
int last_echo_size() const { return last_echo_size_; }
blink::WebDocument document_;
IPC::Sender* sender_;
int routing_id_;
int last_echo_id_;
int last_echo_size_;
};
} // namespace content
#endif // CONTENT_SHELL_IPC_ECHO_DISPATCHER_H_
......@@ -168,6 +168,11 @@ public:
// Returns a text dump the back/forward history for the WebView associated
// with the given WebTestProxyBase.
virtual std::string dumpHistoryForWindow(WebTestProxyBase*) = 0;
// Send an IPC message will will be echoed back.
virtual void requestEcho(int id, int size) = 0;
virtual int lastEchoId() = 0;
virtual int lastEchoSize() = 0;
};
} // namespace content
......
......@@ -290,6 +290,9 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void SetMockPushClientSuccess(const std::string& endpoint,
const std::string& registration_id);
void SetMockPushClientError(const std::string& message);
void RequestEcho(int id, int size);
int GetLastEchoId() const;
int GetLastEchoSize() const;
bool GlobalFlag();
void SetGlobalFlag(bool value);
......@@ -544,6 +547,13 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
&TestRunnerBindings::SetMockPushClientSuccess)
.SetMethod("setMockPushClientError",
&TestRunnerBindings::SetMockPushClientError)
// IPCEcho API
.SetMethod("requestEcho",
&TestRunnerBindings::RequestEcho)
.SetProperty("lastEchoId",
&TestRunnerBindings::GetLastEchoId)
.SetProperty("lastEchoSize",
&TestRunnerBindings::GetLastEchoSize)
// Properties.
.SetProperty("globalFlag",
......@@ -1398,6 +1408,24 @@ void TestRunnerBindings::SetMockPushClientError(const std::string& message) {
runner_->SetMockPushClientError(message);
}
void TestRunnerBindings::RequestEcho(int id, int size) {
if (!runner_)
return;
runner_->RequestEcho(id, size);
}
int TestRunnerBindings::GetLastEchoId() const {
if (!runner_)
return 0;
return runner_->GetLastEchoId();
}
int TestRunnerBindings::GetLastEchoSize() const {
if (!runner_)
return 0;
return runner_->GetLastEchoSize();
}
bool TestRunnerBindings::GlobalFlag() {
if (runner_)
return runner_->global_flag_;
......@@ -2876,6 +2904,18 @@ void TestRunner::SetMockPushClientError(const std::string& message) {
proxy_->GetPushClientMock()->SetMockErrorValues(message);
}
void TestRunner::RequestEcho(int id, int size) {
delegate_->requestEcho(id, size);
}
int TestRunner::GetLastEchoId() const {
return delegate_->lastEchoId();
}
int TestRunner::GetLastEchoSize() const {
return delegate_->lastEchoSize();
}
void TestRunner::LocationChangeDone() {
web_history_item_count_ = delegate_->navigationEntryCount();
......
......@@ -558,6 +558,10 @@ class TestRunner : public WebTestRunner,
const std::string& registration_id);
void SetMockPushClientError(const std::string& message);
void RequestEcho(int id, int size);
int GetLastEchoId() const;
int GetLastEchoSize() const;
///////////////////////////////////////////////////////////////////////////
// Internal helpers
......
......@@ -30,6 +30,7 @@
#include "content/shell/common/shell_switches.h"
#include "content/shell/common/webkit_test_helpers.h"
#include "content/shell/renderer/gc_controller.h"
#include "content/shell/renderer/ipc_echo.h"
#include "content/shell/renderer/leak_detector.h"
#include "content/shell/renderer/shell_render_process_observer.h"
#include "content/shell/renderer/test_runner/WebTask.h"
......@@ -562,6 +563,26 @@ std::string WebKitTestRunner::dumpHistoryForWindow(WebTestProxyBase* proxy) {
current_entry_indexes_[pos]);
}
void WebKitTestRunner::requestEcho(int id, int size) {
if (!ipc_echo_) {
RenderView* view = render_view();
ipc_echo_.reset(new IPCEcho(view->GetWebView()->mainFrame()->document(),
view, view->GetRoutingID()));
}
ipc_echo_->RequestEcho(id, size);
}
int WebKitTestRunner::lastEchoId() {
DCHECK(ipc_echo_);
return ipc_echo_->last_echo_id();
}
int WebKitTestRunner::lastEchoSize() {
DCHECK(ipc_echo_);
return ipc_echo_->last_echo_size();
}
// RenderViewObserver --------------------------------------------------------
void WebKitTestRunner::DidClearWindowObject(WebLocalFrame* frame) {
......@@ -573,6 +594,7 @@ void WebKitTestRunner::DidClearWindowObject(WebLocalFrame* frame) {
bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message)
IPC_MESSAGE_HANDLER(ShellViewMsg_EchoPong, OnEchoPong)
IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration,
OnSetTestConfiguration)
IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory, OnSessionHistory)
......@@ -692,6 +714,10 @@ void WebKitTestRunner::CaptureDumpComplete() {
new ShellViewHostMsg_TestFinished(routing_id())));
}
void WebKitTestRunner::OnEchoPong(int id, const std::string& body) {
ipc_echo_->DidRespondEcho(id, body.size());
}
void WebKitTestRunner::OnSetTestConfiguration(
const ShellTestConfiguration& params) {
test_config_ = params;
......
......@@ -30,6 +30,7 @@ struct WebRect;
namespace content {
class IPCEcho;
class LeakDetector;
class WebTestProxyBase;
struct LeakDetectionResult;
......@@ -114,6 +115,9 @@ class WebKitTestRunner : public RenderViewObserver,
const std::string& frame_name) OVERRIDE;
virtual bool allowExternalPages() OVERRIDE;
virtual std::string dumpHistoryForWindow(WebTestProxyBase* proxy) OVERRIDE;
virtual void requestEcho(int id, int size) OVERRIDE;
virtual int lastEchoId() OVERRIDE;
virtual int lastEchoSize() OVERRIDE;
void Reset();
......@@ -124,6 +128,7 @@ class WebKitTestRunner : public RenderViewObserver,
private:
// Message handlers.
void OnEchoPong(int id, const std::string& body);
void OnSetTestConfiguration(const ShellTestConfiguration& params);
void OnSessionHistory(
const std::vector<int>& routing_ids,
......@@ -156,6 +161,7 @@ class WebKitTestRunner : public RenderViewObserver,
bool focus_on_next_commit_;
scoped_ptr<LeakDetector> leak_detector_;
scoped_ptr<IPCEcho> ipc_echo_;
bool needs_leak_detector_;
DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner);
......
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