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

Unified Diff: chrome/test/chromedriver/devtools_client.cc

Issue 11415205: [chromedriver] Implement connecting to devtools and loading a page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years 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
« no previous file with comments | « chrome/test/chromedriver/devtools_client.h ('k') | chrome/test/chromedriver/net/net_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/devtools_client.cc
diff --git a/chrome/test/chromedriver/devtools_client.cc b/chrome/test/chromedriver/devtools_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f78a492f8d8e465a01985479ac2d93a446cfcf81
--- /dev/null
+++ b/chrome/test/chromedriver/devtools_client.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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 "chrome/test/chromedriver/devtools_client.h"
+
+#include "base/json/json_writer.h"
+#include "base/values.h"
+#include "chrome/test/chromedriver/net/sync_websocket.h"
+#include "chrome/test/chromedriver/net/url_request_context_getter.h"
+#include "chrome/test/chromedriver/status.h"
+#include "googleurl/src/gurl.h"
+
+DevToolsClient::DevToolsClient(
+ URLRequestContextGetter* context_getter,
+ const std::string& url)
+ : context_getter_(context_getter),
+ url_(url),
+ socket_(new SyncWebSocket(context_getter)),
+ connected_(false) {}
+
+DevToolsClient::~DevToolsClient() {}
+
+Status DevToolsClient::SendCommand(
+ const std::string& method,
+ const base::DictionaryValue& params) {
+ if (!connected_) {
+ if (!socket_->Connect(GURL(url_)))
+ return Status(kUnknownError, "unable to connect to renderer");
+ connected_ = true;
+ }
+ base::DictionaryValue command;
+ command.SetInteger("id", 1);
+ command.SetString("method", method);
+ command.Set("params", params.DeepCopy());
+ std::string message;
+ base::JSONWriter::Write(&command, &message);
+ if (!socket_->Send(message))
+ return Status(kUnknownError, "unable to send message to renderer");
+ std::string response;
+ if (!socket_->ReceiveNextMessage(&response))
+ return Status(kUnknownError, "unable to receive message from renderer");
+ return Status(kOk);
+}
« no previous file with comments | « chrome/test/chromedriver/devtools_client.h ('k') | chrome/test/chromedriver/net/net_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698