aboutsummaryrefslogtreecommitdiffstats
path: root/components/webdriver_server/lib.rs
diff options
context:
space:
mode:
authorJames Graham <james@hoppipolla.co.uk>2015-06-16 17:32:42 +0100
committerJames Graham <james@hoppipolla.co.uk>2015-11-16 22:48:26 +0000
commit09b9293b092a89aaca651f3ce655e5a97878e52c (patch)
tree67cf816cd300717b8d5c8d3d364680db1ce230e9 /components/webdriver_server/lib.rs
parentdb94fda10e3351c96a0df61099d2fdfa481cc62b (diff)
downloadservo-09b9293b092a89aaca651f3ce655e5a97878e52c.tar.gz
servo-09b9293b092a89aaca651f3ce655e5a97878e52c.zip
Implement support for WebDriver send keys command.
Supports sending keys to an element. The specification here is still rather unfinished so the error handling and so on in this code will need iteration as it becomes clearer what the expected behaviour is.
Diffstat (limited to 'components/webdriver_server/lib.rs')
-rw-r--r--components/webdriver_server/lib.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs
index bb3019582d0..497e543b28d 100644
--- a/components/webdriver_server/lib.rs
+++ b/components/webdriver_server/lib.rs
@@ -21,9 +21,12 @@ extern crate util;
extern crate uuid;
extern crate webdriver;
+mod keys;
+
use hyper::method::Method::{self, Post};
use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
+use keys::keycodes_to_keys;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, FrameId, LoadData, PipelineId};
use msg::constellation_msg::{NavigationDirection, PixelFormat, WebDriverCommandMsg};
@@ -40,7 +43,7 @@ use util::prefs::{get_pref, reset_all_prefs, reset_pref, set_pref, PrefValue};
use util::task::spawn_named;
use uuid::Uuid;
use webdriver::command::{GetParameters, JavascriptCommandParameters, LocatorParameters};
-use webdriver::command::{Parameters, SwitchToFrameParameters, TimeoutsParameters};
+use webdriver::command::{Parameters, SendKeysParameters, SwitchToFrameParameters, TimeoutsParameters};
use webdriver::command::{WebDriverCommand, WebDriverExtensionCommand, WebDriverMessage};
use webdriver::common::{LocatorStrategy, WebElement};
use webdriver::error::{ErrorStatus, WebDriverError, WebDriverResult};
@@ -204,6 +207,7 @@ impl WebDriverSession {
}
}
+
impl Handler {
pub fn new(constellation_chan: ConstellationChan) -> Handler {
Handler {
@@ -595,6 +599,31 @@ impl Handler {
}
}
+ fn handle_element_send_keys(&self,
+ element: &WebElement,
+ keys: &SendKeysParameters) -> WebDriverResult<WebDriverResponse> {
+ let pipeline_id = try!(self.frame_pipeline());
+
+ let ConstellationChan(ref const_chan) = self.constellation_chan;
+ let (sender, receiver) = ipc::channel().unwrap();
+
+ let cmd = WebDriverScriptCommand::FocusElement(element.id.clone(), sender);
+ let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd);
+ const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap();
+
+ // TODO: distinguish the not found and not focusable cases
+ try!(receiver.recv().unwrap().or_else(|_| Err(WebDriverError::new(
+ ErrorStatus::StaleElementReference, "Element not found or not focusable"))));
+
+ let keys = try!(keycodes_to_keys(&keys.value).or_else(|_|
+ Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, "Failed to convert keycodes"))));
+
+ let cmd_msg = WebDriverCommandMsg::SendKeys(pipeline_id, keys);
+ const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap();
+
+ Ok(WebDriverResponse::Void)
+ }
+
fn handle_take_screenshot(&self) -> WebDriverResult<WebDriverResponse> {
let mut img = None;
let pipeline_id = try!(self.root_pipeline());
@@ -705,6 +734,8 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
WebDriverCommand::GetElementTagName(ref element) => self.handle_element_tag_name(element),
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
WebDriverCommand::ExecuteAsyncScript(ref x) => self.handle_execute_async_script(x),
+ WebDriverCommand::ElementSendKeys(ref element, ref keys) =>
+ self.handle_element_send_keys(element, keys),
WebDriverCommand::SetTimeouts(ref x) => self.handle_set_timeouts(x),
WebDriverCommand::TakeScreenshot => self.handle_take_screenshot(),
WebDriverCommand::Extension(ref extension) => {