Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Unified Diff: content/shell/browser/layout_test/layout_test_devtools_frontend.cc

Issue 1819243002: [DevTools] Use InspectorFrontendHost.readyForTest for layout tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ready-for-test
Patch Set: resource-tree-reload.html fix Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/shell/browser/layout_test/layout_test_devtools_frontend.cc
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 7da2af53ad64fb820513e6b131d081edd4c0546d..f30846ac661a286cb919ac2fbcbfc60da354a2a1 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();
« no previous file with comments | « content/shell/browser/layout_test/layout_test_devtools_frontend.h ('k') | content/shell/browser/shell_devtools_frontend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698