diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-06 01:42:39 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-06 01:42:39 +0000 |
commit | 5cb5ff33998335f9f3be415bfe211c16e76c49a9 (patch) | |
tree | 6f65eda745eb68461597f35f62446e722b55841b /chrome/browser/automation/testing_automation_provider.cc | |
parent | f37d483f4ce280edd3dad6a4f59b38e3b0cd94e2 (diff) | |
download | chromium_src-5cb5ff33998335f9f3be415bfe211c16e76c49a9.zip chromium_src-5cb5ff33998335f9f3be415bfe211c16e76c49a9.tar.gz chromium_src-5cb5ff33998335f9f3be415bfe211c16e76c49a9.tar.bz2 |
Implementation of AutomationEventQueue and associated framework to support generic non-blocking automation events.
Change-Id: I39f50d1d5b321a863572eec6c61e11923092ed47
BUG=98289
TEST=functional/apptest.py
Review URL: http://codereview.chromium.org/9372120
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/testing_automation_provider.cc')
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 11f239a..ba0df97 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -2316,6 +2316,14 @@ void TestingAutomationProvider::SendJSONRequest(int handle, handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; handler_map["ExecuteJavascript"] = &TestingAutomationProvider::ExecuteJavascriptJSON; + handler_map["AddDomRaisedEventObserver"] = + &TestingAutomationProvider::AddDomRaisedEventObserver; + handler_map["RemoveEventObserver"] = + &TestingAutomationProvider::RemoveEventObserver; + handler_map["GetNextEvent"] = + &TestingAutomationProvider::GetNextEvent; + handler_map["ClearEventQueue"] = + &TestingAutomationProvider::ClearEventQueue; handler_map["ExecuteJavascriptInRenderView"] = &TestingAutomationProvider::ExecuteJavascriptInRenderView; handler_map["GoForward"] = @@ -6445,6 +6453,78 @@ void TestingAutomationProvider::ExecuteJavascriptInRenderView( rvh); } +void TestingAutomationProvider::AddDomRaisedEventObserver( + DictionaryValue* args, + IPC::Message* reply_message) { + if (SendErrorIfModalDialogActive(this, reply_message)) + return; + + AutomationJSONReply reply(this, reply_message); + std::string event_name; + if (!args->GetString("event_name", &event_name)) { + reply.SendError("'event_name' missing or invalid"); + return; + } + + if (!automation_event_queue_.get()) + automation_event_queue_.reset(new AutomationEventQueue); + + int observer_id = automation_event_queue_->AddObserver( + new DomRaisedEventObserver(automation_event_queue_.get(), event_name)); + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->SetInteger("observer_id", observer_id); + reply.SendSuccess(return_value.get()); +} + +void TestingAutomationProvider::RemoveEventObserver( + DictionaryValue* args, + IPC::Message* reply_message) { + AutomationJSONReply reply(this, reply_message); + int observer_id; + if (!args->GetInteger("observer_id", &observer_id) || + !automation_event_queue_.get()) { + reply.SendError("'observer_id' missing or invalid"); + return; + } + if (automation_event_queue_->RemoveObserver(observer_id)) { + reply.SendSuccess(NULL); + return; + } + reply.SendError("Invalid observer id."); +} + +void TestingAutomationProvider::ClearEventQueue( + DictionaryValue* args, + IPC::Message* reply_message) { + automation_event_queue_.reset(); + AutomationJSONReply(this, reply_message).SendSuccess(NULL); +} + +void TestingAutomationProvider::GetNextEvent( + DictionaryValue* args, + IPC::Message* reply_message) { + scoped_ptr<AutomationJSONReply> reply( + new AutomationJSONReply(this, reply_message)); + int observer_id; + bool blocking; + if (!args->GetInteger("observer_id", &observer_id)) { + reply->SendError("'observer_id' missing or invalid"); + return; + } + if (!args->GetBoolean("blocking", &blocking)) { + reply->SendError("'blocking' missing or invalid"); + return; + } + if (!automation_event_queue_.get()) { + reply->SendError( + "No observers are attached to the queue. Did you forget to add one?"); + return; + } + + // The reply will be freed once a matching event is added to the queue. + automation_event_queue_->GetNextEvent(reply.release(), observer_id, blocking); +} + void TestingAutomationProvider::GoForward( DictionaryValue* args, IPC::Message* reply_message) { |