aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Graham <james@hoppipolla.co.uk>2015-05-06 12:22:10 +0100
committerJames Graham <james@hoppipolla.co.uk>2015-05-06 12:22:10 +0100
commit1576107c45d48473df172807bcdcbfa1a1db7d83 (patch)
tree3fc2521c5748209879128f976b608812330654f8
parentb762758366928d15063ce661e75e9494d5720353 (diff)
downloadservo-1576107c45d48473df172807bcdcbfa1a1db7d83.tar.gz
servo-1576107c45d48473df172807bcdcbfa1a1db7d83.zip
Implement webdriver commands for back/forward/title/handles.
-rw-r--r--components/msg/constellation_msg.rs2
-rw-r--r--components/script/script_task.rs4
-rw-r--r--components/script/webdriver_handlers.rs7
-rw-r--r--components/webdriver_server/lib.rs36
-rw-r--r--components/webdriver_traits/lib.rs3
5 files changed, 47 insertions, 5 deletions
diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs
index 98743cdc650..4d9d2d19fb4 100644
--- a/components/msg/constellation_msg.rs
+++ b/components/msg/constellation_msg.rs
@@ -226,7 +226,7 @@ pub enum Msg {
ChangeRunningAnimationsState(PipelineId, AnimationState),
/// Requests that the constellation instruct layout to begin a new tick of the animation.
TickAnimation(PipelineId),
- // Request that the constellation send the current root pipeline id over a provided channel
+ /// Request that the constellation send the current root pipeline id over a provided channel
GetRootPipeline(Sender<Option<PipelineId>>),
/// Notifies the constellation that this frame has received focus.
Focus(PipelineId),
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index 534af2e081f..397078fde19 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -791,7 +791,9 @@ impl ScriptTask {
let page = self.root_page();
match msg {
WebDriverScriptCommand::EvaluateJS(script, reply) =>
- webdriver_handlers::handle_evaluate_js(&page, pipeline_id, script, reply)
+ webdriver_handlers::handle_evaluate_js(&page, pipeline_id, script, reply),
+ WebDriverScriptCommand::GetTitle(reply) =>
+ webdriver_handlers::handle_get_title(&page, pipeline_id, reply)
}
}
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index d021c28e38e..f9ff918c60e 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -5,6 +5,7 @@
use webdriver_traits::{EvaluateJSReply};
use dom::bindings::conversions::FromJSValConvertible;
use dom::bindings::conversions::StringificationBehavior;
+use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::js::{OptionalRootable, Rootable};
use dom::window::ScriptHelpers;
use dom::document::DocumentHelpers;
@@ -15,7 +16,7 @@ use script_task::get_page;
use std::rc::Rc;
use std::sync::mpsc::Sender;
-pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<Result<EvaluateJSReply, ()>>){
+pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<Result<EvaluateJSReply, ()>>) {
let page = get_page(&*page, pipeline);
let window = page.window().root();
let cx = window.r().get_cx();
@@ -36,3 +37,7 @@ pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, r
Err(())
}).unwrap();
}
+
+pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: Sender<String>) {
+ reply.send(page.document().root().r().Title()).unwrap();
+}
diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs
index d22b4ba119b..712cd1fc354 100644
--- a/components/webdriver_server/lib.rs
+++ b/components/webdriver_server/lib.rs
@@ -18,7 +18,7 @@ extern crate rustc_serialize;
extern crate uuid;
extern crate webdriver_traits;
-use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId};
+use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId, NavigationDirection};
use msg::constellation_msg::Msg as ConstellationMsg;
use std::sync::mpsc::channel;
use webdriver_traits::WebDriverScriptCommand;
@@ -110,6 +110,29 @@ impl Handler {
Ok(WebDriverResponse::Void)
}
+ fn handle_go_back(&self) -> WebDriverResult<WebDriverResponse> {
+ let ConstellationChan(ref const_chan) = self.constellation_chan;
+ const_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back)).unwrap();
+ Ok(WebDriverResponse::Void)
+ }
+
+ fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> {
+ let ConstellationChan(ref const_chan) = self.constellation_chan;
+ const_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Forward)).unwrap();
+ Ok(WebDriverResponse::Void)
+ }
+
+ fn handle_get_title(&self) -> WebDriverResult<WebDriverResponse> {
+ let pipeline_id = self.get_root_pipeline();
+
+ let (sender, reciever) = channel();
+ let ConstellationChan(ref const_chan) = self.constellation_chan;
+ const_chan.send(ConstellationMsg::WebDriverCommand(pipeline_id,
+ WebDriverScriptCommand::GetTitle(sender))).unwrap();
+ let value = reciever.recv().unwrap();
+ Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json())))
+ }
+
fn handle_get_window_handle(&self) -> WebDriverResult<WebDriverResponse> {
// For now we assume there's only one window so just use the session
// id as the window id
@@ -117,6 +140,13 @@ impl Handler {
Ok(WebDriverResponse::Generic(ValueResponse::new(handle.to_json())))
}
+ fn handle_get_window_handles(&self) -> WebDriverResult<WebDriverResponse> {
+ // For now we assume there's only one window so just use the session
+ // id as the window id
+ let handles = vec![self.session.as_ref().unwrap().id.to_string().to_json()];
+ Ok(WebDriverResponse::Generic(ValueResponse::new(handles.to_json())))
+ }
+
fn handle_execute_script(&self, parameters: &JavascriptCommandParameters) -> WebDriverResult<WebDriverResponse> {
// TODO: This isn't really right because it always runs the script in the
// root window
@@ -149,7 +179,11 @@ impl WebDriverHandler for Handler {
match msg.command {
WebDriverCommand::NewSession => self.handle_new_session(),
WebDriverCommand::Get(ref parameters) => self.handle_get(parameters),
+ WebDriverCommand::GoBack => self.handle_go_back(),
+ WebDriverCommand::GoForward => self.handle_go_forward(),
+ WebDriverCommand::GetTitle => self.handle_get_title(),
WebDriverCommand::GetWindowHandle => self.handle_get_window_handle(),
+ WebDriverCommand::GetWindowHandles => self.handle_get_window_handles(),
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
_ => Err(WebDriverError::new(ErrorStatus::UnsupportedOperation,
"Command not implemented"))
diff --git a/components/webdriver_traits/lib.rs b/components/webdriver_traits/lib.rs
index 16157a42ce3..8e816165722 100644
--- a/components/webdriver_traits/lib.rs
+++ b/components/webdriver_traits/lib.rs
@@ -11,7 +11,8 @@ use rustc_serialize::json::{Json, ToJson};
use std::sync::mpsc::Sender;
pub enum WebDriverScriptCommand {
- EvaluateJS(String, Sender<Result<EvaluateJSReply, ()>>)
+ EvaluateJS(String, Sender<Result<EvaluateJSReply, ()>>),
+ GetTitle(Sender<String>)
}
pub enum EvaluateJSReply {