diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-27 15:49:16 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-27 15:49:16 +0000 |
commit | a1b38b3c984fdf39e37b3db74cf8a8fa7c9a1063 (patch) | |
tree | 4e2d6c77453abe2f21c71b9504a1965a54baefac /chrome/browser | |
parent | 4dad4a8367a040019074ed97d7307487b2832c8c (diff) | |
download | chromium_src-a1b38b3c984fdf39e37b3db74cf8a8fa7c9a1063.zip chromium_src-a1b38b3c984fdf39e37b3db74cf8a8fa7c9a1063.tar.gz chromium_src-a1b38b3c984fdf39e37b3db74cf8a8fa7c9a1063.tar.bz2 |
Implementing webdriver advanced controls APIs for chromedriver.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6857001
Patch from Hisayori Noda <hnoda@google.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 142 insertions, 10 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 15beb50..50ce7b6 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -2201,10 +2201,13 @@ void RendererProcessClosedObserver::Observe( InputEventAckNotificationObserver::InputEventAckNotificationObserver( AutomationProvider* automation, IPC::Message* reply_message, - int event_type) + int event_type, + int count) : automation_(automation->AsWeakPtr()), reply_message_(reply_message), - event_type_(event_type) { + event_type_(event_type), + count_(count) { + DCHECK(1 <= count); registrar_.Add( this, NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, NotificationService::AllSources()); @@ -2217,7 +2220,8 @@ void InputEventAckNotificationObserver::Observe( const NotificationSource& source, const NotificationDetails& details) { Details<int> request_details(details); - if (event_type_ == *request_details.ptr()) { + // If the event type matches for "count" times, replies with a JSON message. + if (event_type_ == *request_details.ptr() && --count_ == 0) { if (automation_) { AutomationJSONReply(automation_, reply_message_.release()).SendSuccess(NULL); diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 2d71001..99d5529 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -1244,13 +1244,13 @@ class RendererProcessClosedObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(RendererProcessClosedObserver); }; -// Allows the automation provider to wait for acknowledgement that a input -// event has been handled. +// Allows the automation provider to wait for acknowledgement that a certain +// type and number of input events has been processed by the renderer. class InputEventAckNotificationObserver : public NotificationObserver { public: InputEventAckNotificationObserver(AutomationProvider* automation, IPC::Message* reply_message, - int event_type); + int event_type, int count); virtual ~InputEventAckNotificationObserver(); virtual void Observe(NotificationType type, @@ -1262,6 +1262,7 @@ class InputEventAckNotificationObserver : public NotificationObserver { base::WeakPtr<AutomationProvider> automation_; scoped_ptr<IPC::Message> reply_message_; int event_type_; + int count_; DISALLOW_COPY_AND_ASSIGN(InputEventAckNotificationObserver); }; diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index a26d14b..615297d 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -900,7 +900,8 @@ void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); mouse_event.type = WebKit::WebInputEvent::MouseUp; - new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); + new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, + 1); tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); } @@ -922,7 +923,8 @@ void TestingAutomationProvider::WebkitMouseMove( } mouse_event.type = WebKit::WebInputEvent::MouseMove; - new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); + new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, + 1); tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); } @@ -970,7 +972,93 @@ void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, // Step 4 - Release the left mouse button. mouse_event.type = WebKit::WebInputEvent::MouseUp; mouse_event.clickCount = 1; - new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); + new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, + 1); + tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); +} + +void TestingAutomationProvider::WebkitMouseButtonDown( + DictionaryValue* args, IPC::Message* reply_message) { + TabContents* tab_contents; + std::string error; + if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { + AutomationJSONReply(this, reply_message).SendError(error); + return; + } + + WebKit::WebMouseEvent mouse_event; + if (!args->GetInteger("x", &mouse_event.x) || + !args->GetInteger("y", &mouse_event.y)) { + AutomationJSONReply(this, reply_message) + .SendError("(X,Y) coordinates missing or invalid"); + return; + } + + mouse_event.type = WebKit::WebInputEvent::MouseDown; + mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; + mouse_event.clickCount = 1; + new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, + 1); + tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); +} + +void TestingAutomationProvider::WebkitMouseButtonUp( + DictionaryValue* args, IPC::Message* reply_message) { + TabContents* tab_contents; + std::string error; + if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { + AutomationJSONReply(this, reply_message).SendError(error); + return; + } + + WebKit::WebMouseEvent mouse_event; + if (!args->GetInteger("x", &mouse_event.x) || + !args->GetInteger("y", &mouse_event.y)) { + AutomationJSONReply(this, reply_message) + .SendError("(X,Y) coordinates missing or invalid"); + return; + } + + mouse_event.type = WebKit::WebInputEvent::MouseUp; + mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; + mouse_event.clickCount = 1; + new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, + 1); + tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); +} + +void TestingAutomationProvider::WebkitMouseDoubleClick( + DictionaryValue* args, IPC::Message* reply_message) { + TabContents* tab_contents; + std::string error; + if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { + AutomationJSONReply(this, reply_message).SendError(error); + return; + } + + WebKit::WebMouseEvent mouse_event; + if (!args->GetInteger("x", &mouse_event.x) || + !args->GetInteger("y", &mouse_event.y)) { + AutomationJSONReply(this, reply_message) + .SendError("(X,Y) coordinates missing or invalid"); + return; + } + + mouse_event.type = WebKit::WebInputEvent::MouseDown; + mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; + mouse_event.clickCount = 1; + tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); + + mouse_event.type = WebKit::WebInputEvent::MouseUp; + new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, + 2); + tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); + + mouse_event.type = WebKit::WebInputEvent::MouseDown; + mouse_event.clickCount = 2; + tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); + + mouse_event.type = WebKit::WebInputEvent::MouseUp; tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); } @@ -2083,6 +2171,12 @@ void TestingAutomationProvider::SendJSONRequest(int handle, &TestingAutomationProvider::WebkitMouseClick; handler_map["WebkitMouseDrag"] = &TestingAutomationProvider::WebkitMouseDrag; + handler_map["WebkitMouseButtonUp"] = + &TestingAutomationProvider::WebkitMouseButtonUp; + handler_map["WebkitMouseButtonDown"] = + &TestingAutomationProvider::WebkitMouseButtonDown; + handler_map["WebkitMouseDoubleClick"] = + &TestingAutomationProvider::WebkitMouseDoubleClick; handler_map["SendWebkitKeyEvent"] = &TestingAutomationProvider::SendWebkitKeyEvent; handler_map["SendOSLevelKeyEventToTab"] = @@ -4765,7 +4859,7 @@ void TestingAutomationProvider::SendWebkitKeyEvent( AutomationJSONReply(this, reply_message).SendError(error); return; } - new InputEventAckNotificationObserver(this, reply_message, event.type); + new InputEventAckNotificationObserver(this, reply_message, event.type, 1); tab_contents->render_view_host()->ForwardKeyboardEvent(event); } diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index a0ed895..5018d9d 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -991,6 +991,39 @@ class TestingAutomationProvider : public AutomationProvider, void WebkitMouseDrag(DictionaryValue* args, IPC::Message* message); + // Sends the WebKit events for a mouse button down at a given coordinate. + // Example: + // input: { "windex": 1, + // "tab_index": 1, + // "x": 100, + // "y": 100 + // } + // output: none + void WebkitMouseButtonDown(DictionaryValue* args, + IPC::Message* message); + + // Sends the WebKit events for a mouse button up at a given coordinate. + // Example: + // input: { "windex": 1, + // "tab_index": 1, + // "x": 100, + // "y": 100 + // } + // output: none + void WebkitMouseButtonUp(DictionaryValue* args, + IPC::Message* message); + + // Sends the WebKit events for a mouse double click at a given coordinate. + // Example: + // input: { "windex": 1, + // "tab_index": 1, + // "x": 100, + // "y": 100 + // } + // output: none + void WebkitMouseDoubleClick(DictionaryValue* args, + IPC::Message* message); + // Sends the WebKit key event with the specified properties. // Example: // input: { "windex": 1, |