summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/automation
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-17 00:19:32 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-17 00:19:32 +0000
commitc158a6699a9f5e5f56d913c0b06e0d83e8358591 (patch)
tree727e3eb0a5aac10658e35d2e389b057faed103bf /chrome/renderer/automation
parentc7eca5b2c6f9a527d18d00486d2d7cd7dca9c7b1 (diff)
downloadchromium_src-c158a6699a9f5e5f56d913c0b06e0d83e8358591.zip
chromium_src-c158a6699a9f5e5f56d913c0b06e0d83e8358591.tar.gz
chromium_src-c158a6699a9f5e5f56d913c0b06e0d83e8358591.tar.bz2
Add support for DOM interaction in browser tests via C++.
BUG=none TEST=none Review URL: http://codereview.chromium.org/660046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41789 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/automation')
-rw-r--r--chrome/renderer/automation/dom_automation_controller.cc31
-rw-r--r--chrome/renderer/automation/dom_automation_controller.h5
-rw-r--r--chrome/renderer/automation/dom_automation_v8_extension.cc19
-rw-r--r--chrome/renderer/automation/dom_automation_v8_extension.h16
4 files changed, 71 insertions, 0 deletions
diff --git a/chrome/renderer/automation/dom_automation_controller.cc b/chrome/renderer/automation/dom_automation_controller.cc
index 3b7ac43..6c3e8a5 100644
--- a/chrome/renderer/automation/dom_automation_controller.cc
+++ b/chrome/renderer/automation/dom_automation_controller.cc
@@ -14,6 +14,7 @@ DomAutomationController::DomAutomationController()
automation_id_(MSG_ROUTING_NONE) {
BindMethod("send", &DomAutomationController::Send);
BindMethod("setAutomationId", &DomAutomationController::SetAutomationId);
+ BindMethod("sendJSON", &DomAutomationController::SendJSON);
}
void DomAutomationController::Send(const CppArgumentList& args,
@@ -86,6 +87,36 @@ void DomAutomationController::Send(const CppArgumentList& args,
return;
}
+void DomAutomationController::SendJSON(const CppArgumentList& args,
+ CppVariant* result) {
+ if (args.size() != 1) {
+ result->SetNull();
+ return;
+ }
+
+ if (automation_id_ == MSG_ROUTING_NONE) {
+ result->SetNull();
+ return;
+ }
+
+ if (!sender_) {
+ NOTREACHED();
+ result->SetNull();
+ return;
+ }
+
+ if (args[0].type != NPVariantType_String) {
+ result->SetNull();
+ return;
+ }
+
+ std::string json = args[0].ToString();
+ result->Set(sender_->Send(
+ new ViewHostMsg_DomOperationResponse(routing_id_, json, automation_id_)));
+
+ automation_id_ = MSG_ROUTING_NONE;
+}
+
void DomAutomationController::SetAutomationId(
const CppArgumentList& args, CppVariant* result) {
if (args.size() != 1) {
diff --git a/chrome/renderer/automation/dom_automation_controller.h b/chrome/renderer/automation/dom_automation_controller.h
index bc6f5fe..c815418 100644
--- a/chrome/renderer/automation/dom_automation_controller.h
+++ b/chrome/renderer/automation/dom_automation_controller.h
@@ -84,6 +84,11 @@ class DomAutomationController : public CppBoundClass {
// IPC. It sets the return value to null on unexpected errors or arguments.
void Send(const CppArgumentList& args, CppVariant* result);
+ // Makes the renderer send a javascript value to the app.
+ // The value must be a NPString and should be properly formed JSON.
+ // This function does not modify/escape the returned string in any way.
+ void SendJSON(const CppArgumentList& args, CppVariant* result);
+
void SetAutomationId(const CppArgumentList& args, CppVariant* result);
// TODO(vibhor): Implement later
diff --git a/chrome/renderer/automation/dom_automation_v8_extension.cc b/chrome/renderer/automation/dom_automation_v8_extension.cc
new file mode 100644
index 0000000..efe5ada
--- /dev/null
+++ b/chrome/renderer/automation/dom_automation_v8_extension.cc
@@ -0,0 +1,19 @@
+// Copyright (c) 2010 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/renderer/automation/dom_automation_v8_extension.h"
+
+#include "chrome/renderer/extensions/bindings_utils.h"
+#include "grit/renderer_resources.h"
+
+using bindings_utils::GetStringResource;
+
+const char* DomAutomationV8Extension::kName = "chrome/domautomation";
+
+v8::Extension* DomAutomationV8Extension::Get() {
+ static v8::Extension* extension =
+ new bindings_utils::ExtensionBase(
+ kName, GetStringResource<IDR_DOM_AUTOMATION_JS>(), 0, NULL);
+ return extension;
+}
diff --git a/chrome/renderer/automation/dom_automation_v8_extension.h b/chrome/renderer/automation/dom_automation_v8_extension.h
new file mode 100644
index 0000000..94201e7
--- /dev/null
+++ b/chrome/renderer/automation/dom_automation_v8_extension.h
@@ -0,0 +1,16 @@
+// Copyright (c) 2010 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 CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_V8_EXTENSION_H_
+#define CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_V8_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+class DomAutomationV8Extension {
+ public:
+ static const char* kName;
+ static v8::Extension* Get();
+};
+
+#endif // CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_V8_EXTENSION_H_