summaryrefslogtreecommitdiffstats
path: root/content/shell/browser
diff options
context:
space:
mode:
authordgozman <dgozman@chromium.org>2016-03-23 19:12:31 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 02:14:00 +0000
commit89f7238cebbf5d77e4caa84d0a2750f6faa7e983 (patch)
tree9f723cbc10b4ad0da72444988eb7e160d710d826 /content/shell/browser
parent47c9dd29746fc96baf54688641e43fb90916bd36 (diff)
downloadchromium_src-89f7238cebbf5d77e4caa84d0a2750f6faa7e983.zip
chromium_src-89f7238cebbf5d77e4caa84d0a2750f6faa7e983.tar.gz
chromium_src-89f7238cebbf5d77e4caa84d0a2750f6faa7e983.tar.bz2
[DevTools] Use InspectorFrontendHost.readyForTest for layout tests.
BUG=none Review URL: https://codereview.chromium.org/1819243002 Cr-Commit-Position: refs/heads/master@{#383015}
Diffstat (limited to 'content/shell/browser')
-rw-r--r--content/shell/browser/layout_test/blink_test_controller.cc8
-rw-r--r--content/shell/browser/layout_test/blink_test_controller.h1
-rw-r--r--content/shell/browser/layout_test/layout_test_devtools_frontend.cc46
-rw-r--r--content/shell/browser/layout_test/layout_test_devtools_frontend.h7
-rw-r--r--content/shell/browser/shell_devtools_frontend.h3
5 files changed, 62 insertions, 3 deletions
diff --git a/content/shell/browser/layout_test/blink_test_controller.cc b/content/shell/browser/layout_test/blink_test_controller.cc
index b823e7f..9f4b1b7 100644
--- a/content/shell/browser/layout_test/blink_test_controller.cc
+++ b/content/shell/browser/layout_test/blink_test_controller.cc
@@ -413,6 +413,8 @@ bool BlinkTestController::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ShellViewHostMsg_ClearDevToolsLocalStorage,
OnClearDevToolsLocalStorage)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_ShowDevTools, OnShowDevTools)
+ IPC_MESSAGE_HANDLER(ShellViewHostMsg_EvaluateInDevTools,
+ OnEvaluateInDevTools)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_CloseDevTools, OnCloseDevTools)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_GoToOffset, OnGoToOffset)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_Reload, OnReload)
@@ -765,6 +767,12 @@ void BlinkTestController::OnShowDevTools(const std::string& settings,
devtools_frontend_->Focus();
}
+void BlinkTestController::OnEvaluateInDevTools(
+ int call_id, const std::string& script) {
+ if (devtools_frontend_)
+ devtools_frontend_->EvaluateInFrontend(call_id, script);
+}
+
void BlinkTestController::OnCloseDevTools() {
if (devtools_frontend_)
devtools_frontend_->DisconnectFromTarget();
diff --git a/content/shell/browser/layout_test/blink_test_controller.h b/content/shell/browser/layout_test/blink_test_controller.h
index 10d4a44..4bcc36f 100644
--- a/content/shell/browser/layout_test/blink_test_controller.h
+++ b/content/shell/browser/layout_test/blink_test_controller.h
@@ -202,6 +202,7 @@ class BlinkTestController : public base::NonThreadSafe,
void OnClearDevToolsLocalStorage();
void OnShowDevTools(const std::string& settings,
const std::string& frontend_url);
+ void OnEvaluateInDevTools(int call_id, const std::string& script);
void OnCloseDevTools();
void OnGoToOffset(int offset);
void OnReload();
diff --git a/content/shell/browser/layout_test/layout_test_devtools_frontend.cc b/content/shell/browser/layout_test/layout_test_devtools_frontend.cc
index 7da2af53..f30846a 100644
--- a/content/shell/browser/layout_test/layout_test_devtools_frontend.cc
+++ b/content/shell/browser/layout_test/layout_test_devtools_frontend.cc
@@ -5,9 +5,13 @@
#include "content/shell/browser/layout_test/layout_test_devtools_frontend.h"
#include "base/command_line.h"
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/shell/browser/layout_test/blink_test_controller.h"
#include "content/shell/browser/shell.h"
@@ -67,13 +71,34 @@ void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings,
const std::string frontend_url) {
DisconnectFromTarget();
preferences()->Clear();
+ ready_for_test_ = false;
+ pending_evaluations_.clear();
frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url));
}
+void LayoutTestDevToolsFrontend::EvaluateInFrontend(
+ int call_id,
+ const std::string& script) {
+ if (!ready_for_test_) {
+ pending_evaluations_.push_back(std::make_pair(call_id, script));
+ return;
+ }
+
+ std::string encoded_script;
+ base::JSONWriter::Write(base::StringValue(script), &encoded_script);
+ std::string source =
+ base::StringPrintf("DevToolsAPI.evaluateForTestInFrontend(%d, %s);",
+ call_id,
+ encoded_script.c_str());
+ web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
+ base::UTF8ToUTF16(source));
+}
+
LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend(
Shell* frontend_shell,
WebContents* inspected_contents)
- : ShellDevToolsFrontend(frontend_shell, inspected_contents) {
+ : ShellDevToolsFrontend(frontend_shell, inspected_contents),
+ ready_for_test_(false) {
}
LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() {
@@ -84,6 +109,25 @@ void LayoutTestDevToolsFrontend::AgentHostClosed(
// Do not close the front-end shell.
}
+void LayoutTestDevToolsFrontend::HandleMessageFromDevToolsFrontend(
+ const std::string& message) {
+ std::string method;
+ base::DictionaryValue* dict = nullptr;
+ scoped_ptr<base::Value> parsed_message = base::JSONReader::Read(message);
+ if (parsed_message &&
+ parsed_message->GetAsDictionary(&dict) &&
+ dict->GetString("method", &method) &&
+ method == "readyForTest") {
+ ready_for_test_ = true;
+ for (const auto& pair : pending_evaluations_)
+ EvaluateInFrontend(pair.first, pair.second);
+ pending_evaluations_.clear();
+ return;
+ }
+
+ ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(message);
+}
+
void LayoutTestDevToolsFrontend::RenderProcessGone(
base::TerminationStatus status) {
BlinkTestController::Get()->DevToolsProcessCrashed();
diff --git a/content/shell/browser/layout_test/layout_test_devtools_frontend.h b/content/shell/browser/layout_test/layout_test_devtools_frontend.h
index db2dc41..839a9a5 100644
--- a/content/shell/browser/layout_test/layout_test_devtools_frontend.h
+++ b/content/shell/browser/layout_test/layout_test_devtools_frontend.h
@@ -26,6 +26,7 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend {
void ReuseFrontend(const std::string& settings,
const std::string frontend_url);
+ void EvaluateInFrontend(int call_id, const std::string& expression);
private:
LayoutTestDevToolsFrontend(Shell* frontend_shell,
@@ -35,9 +36,15 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend {
// content::DevToolsAgentHostClient implementation.
void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override;
+ // ShellDevToolsFrontend overrides.
+ void HandleMessageFromDevToolsFrontend(const std::string& message) override;
+
// WebContentsObserver implementation.
void RenderProcessGone(base::TerminationStatus status) override;
+ bool ready_for_test_;
+ std::vector<std::pair<int, std::string>> pending_evaluations_;
+
DISALLOW_COPY_AND_ASSIGN(LayoutTestDevToolsFrontend);
};
diff --git a/content/shell/browser/shell_devtools_frontend.h b/content/shell/browser/shell_devtools_frontend.h
index b1be4a6..3258a5a 100644
--- a/content/shell/browser/shell_devtools_frontend.h
+++ b/content/shell/browser/shell_devtools_frontend.h
@@ -55,6 +55,7 @@ class ShellDevToolsFrontend : public WebContentsObserver,
void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
const std::string& message) override;
base::DictionaryValue* preferences() { return &preferences_; }
+ virtual void HandleMessageFromDevToolsFrontend(const std::string& message);
private:
// WebContentsObserver overrides
@@ -62,8 +63,6 @@ class ShellDevToolsFrontend : public WebContentsObserver,
void DocumentAvailableInMainFrame() override;
void WebContentsDestroyed() override;
- void HandleMessageFromDevToolsFrontend(const std::string& message);
-
// net::URLFetcherDelegate overrides.
void OnURLFetchComplete(const net::URLFetcher* source) override;