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

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 9372120: Implementation of AutomationEventQueue and associated framework to support generic non-blocking aut… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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: chrome/browser/automation/testing_automation_provider.cc
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index afc251a4d660590022094a732d548c3ad5f630a6..2ca2a24de885e03406a8ec40180385ec3c0a56eb 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -2316,6 +2316,16 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs;
handler_map["ExecuteJavascript"] =
&TestingAutomationProvider::ExecuteJavascriptJSON;
+ handler_map["ObserveRaisedEvents"] =
+ &TestingAutomationProvider::ObserveRaisedEvents;
+ handler_map["GetEvent"] =
+ &TestingAutomationProvider::GetEvent;
+ handler_map["RemoveEventObserver"] =
+ &TestingAutomationProvider::RemoveEventObserver;
+ handler_map["ClearEvents"] =
+ &TestingAutomationProvider::ClearEvents;
+ handler_map["ClearEventObservers"] =
+ &TestingAutomationProvider::ClearEventObservers;
handler_map["ExecuteJavascriptInRenderView"] =
&TestingAutomationProvider::ExecuteJavascriptInRenderView;
handler_map["GoForward"] =
@@ -6443,6 +6453,91 @@ void TestingAutomationProvider::ExecuteJavascriptInRenderView(
rvh);
}
+void TestingAutomationProvider::ObserveRaisedEvents(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ if (SendErrorIfModalDialogActive(this, reply_message))
+ return;
+
+ std::string event_name;
+ if (!args->GetString("event_name", &event_name)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("'event_name' missing or invalid");
+ return;
+ }
+ std::string error;
+ RenderViewHost* render_view;
+ if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ Error(automation::kInvalidId, error));
+ return;
+ }
+ string16 frame_xpath;
+ if (!args->GetString("frame_xpath", &frame_xpath)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("'frame_xpath' missing or invalid");
+ return;
+ }
+ std::string set_automation_id;
+ base::SStringPrintf(&set_automation_id,
+ "window.domAutomationController.setAutomationId(%d);",
+ reply_message->routing_id());
+ render_view->ExecuteJavascriptInWebFrame(
+ frame_xpath, UTF8ToUTF16(set_automation_id));
+
+ RaisedEventObserver* jsobserver =
+ new RaisedEventObserver(automation_event_queue_, event_name);
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ return_value->SetInteger("observer_id", jsobserver->GetId());
+ AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
+}
+
+void TestingAutomationProvider::RemoveEventObserver(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ int observer_id;
+ if (!args->GetInteger("observer_id", &observer_id)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("'observer_id' missing or invalid");
+ return;
+ }
+ automation_event_queue_.RemoveObserver(observer_id);
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::ClearEvents(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ automation_event_queue_.Clear();
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::ClearEventObservers(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ automation_event_queue_.ClearObservers();
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::GetEvent(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ int observer_id;
+ bool blocking;
+ if (!args->GetInteger("observer_id", &observer_id)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("'observer_id' missing or invalid");
+ return;
+ }
+ if (!args->GetBoolean("blocking", &blocking)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("'blocking' missing or invalid");
+ return;
+ }
+
+ automation_event_queue_.GetEvent(this, reply_message, observer_id, blocking);
+}
+
void TestingAutomationProvider::GoForward(
DictionaryValue* args,
IPC::Message* reply_message) {

Powered by Google App Engine
This is Rietveld 408576698