From 9eade1989738709a2170818a6287fed320dac5cf Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 15 Jun 2015 13:24:49 +0100 Subject: [PATCH 1/5] Add support for the Get URL WebDriver command. --- components/compositing/constellation.rs | 4 ++++ components/msg/constellation_msg.rs | 1 + components/webdriver_server/lib.rs | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 7dd06342790..963363c29a7 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -917,6 +917,10 @@ impl Constellation { self.webdriver.load_channel = Some((id, reply)); } }, + WebDriverCommandMsg::GetUrl(pipeline_id, reply) => { + let pipeline = self.pipeline(pipeline_id); + reply.send(pipeline.url.clone()).unwrap(); + } WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd) => { let pipeline = self.pipeline(pipeline_id); let control_msg = ConstellationControlMsg::WebDriverScriptCommand(pipeline_id, cmd); diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 52b883615e5..db6216c6568 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -336,6 +336,7 @@ impl MozBrowserEvent { #[derive(Deserialize, Serialize)] pub enum WebDriverCommandMsg { LoadUrl(PipelineId, LoadData, IpcSender), + GetUrl(PipelineId, IpcSender), ScriptCommand(PipelineId, WebDriverScriptCommand), TakeScreenshot(PipelineId, IpcSender>) } diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 6713fbfe453..500e7d220dc 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -191,6 +191,21 @@ impl Handler { } } + fn handle_get_current_url(&self) -> WebDriverResult { + let pipeline_id = try!(self.get_root_pipeline()); + + let (sender, reciever) = channel(); + + let ConstellationChan(ref const_chan) = self.constellation_chan; + let cmd_msg = WebDriverCommandMsg::GetUrl(pipeline_id, sender); + const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); + + //Wait to get a load event + let url = reciever.recv().unwrap(); + + Ok(WebDriverResponse::Generic(ValueResponse::new(url.serialize().to_json()))) + } + fn handle_go_back(&self) -> WebDriverResult { let ConstellationChan(ref const_chan) = self.constellation_chan; const_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back)).unwrap(); @@ -489,6 +504,7 @@ impl WebDriverHandler for Handler { match msg.command { WebDriverCommand::NewSession => self.handle_new_session(), WebDriverCommand::Get(ref parameters) => self.handle_get(parameters), + WebDriverCommand::GetCurrentUrl => self.handle_get_current_url(), WebDriverCommand::GoBack => self.handle_go_back(), WebDriverCommand::GoForward => self.handle_go_forward(), WebDriverCommand::GetTitle => self.handle_get_title(), From f28219b8cb8713357b53a2657391f1f68acd1606 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 15 Jun 2015 14:35:36 +0100 Subject: [PATCH 2/5] Implement WebDriver Refresh command --- components/compositing/constellation.rs | 22 ++++++++-- components/msg/constellation_msg.rs | 1 + components/webdriver_server/lib.rs | 55 +++++++++++++++++-------- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 963363c29a7..da78540bd37 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -912,14 +912,18 @@ impl Constellation { // and pass the event to that script task. match msg { WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, reply) => { - let new_pipeline_id = self.load_url(pipeline_id, load_data); - if let Some(id) = new_pipeline_id { - self.webdriver.load_channel = Some((id, reply)); - } + self.load_url_for_webdriver(pipeline_id, load_data, reply); }, WebDriverCommandMsg::GetUrl(pipeline_id, reply) => { let pipeline = self.pipeline(pipeline_id); reply.send(pipeline.url.clone()).unwrap(); + }, + WebDriverCommandMsg::Refresh(pipeline_id, reply) => { + let load_data = { + let pipeline = self.pipeline(pipeline_id); + LoadData::new(pipeline.url.clone()) + }; + self.load_url_for_webdriver(pipeline_id, load_data, reply); } WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd) => { let pipeline = self.pipeline(pipeline_id); @@ -941,6 +945,16 @@ impl Constellation { } } + fn load_url_for_webdriver(&mut self, + pipeline_id: PipelineId, + load_data:LoadData, + reply: Sender) { + let new_pipeline_id = self.load_url(pipeline_id, load_data); + if let Some(id) = new_pipeline_id { + self.webdriver.load_channel = Some((id, reply)); + } + } + fn add_or_replace_pipeline_in_frame_tree(&mut self, frame_change: FrameChange) { // If the currently focused pipeline is the one being changed (or a child diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index db6216c6568..24d9f9bfd7a 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -337,6 +337,7 @@ impl MozBrowserEvent { pub enum WebDriverCommandMsg { LoadUrl(PipelineId, LoadData, IpcSender), GetUrl(PipelineId, IpcSender), + Refresh(PipelineId, IpcSender), ScriptCommand(PipelineId, WebDriverScriptCommand), TakeScreenshot(PipelineId, IpcSender>) } diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 500e7d220dc..a8b68eaadd7 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -35,7 +35,7 @@ use webdriver::server::{self, WebDriverHandler, Session}; use webdriver::error::{WebDriverResult, WebDriverError, ErrorStatus}; use util::task::spawn_named; use uuid::Uuid; -use ipc_channel::ipc::{self, IpcReceiver}; +use ipc_channel::ipc::{self, IpcSender, IpcReceiver}; use std::borrow::ToOwned; use rustc_serialize::json::{Json, ToJson}; @@ -139,7 +139,7 @@ impl Handler { const_chan.send(ConstellationMsg::GetPipeline(frame_id, sender)).unwrap(); - reciever.recv().unwrap() + receiver.recv().unwrap() } fn handle_new_session(&mut self) -> WebDriverResult { @@ -176,15 +176,21 @@ impl Handler { let cmd_msg = WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, sender.clone()); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); + self.wait_for_load(sender, receiver) + } + + fn wait_for_load(&self, + sender: IpcSender, + receiver: IpcReceiver) -> WebDriverResult { let timeout = self.load_timeout; - let timeout_chan = sender.clone(); + let timeout_chan = sender; thread::spawn(move || { sleep_ms(timeout); let _ = timeout_chan.send(LoadStatus::LoadTimeout); }); //Wait to get a load event - match reciever.recv().unwrap() { + match receiver.recv().unwrap() { LoadStatus::LoadComplete => Ok(WebDriverResponse::Void), LoadStatus::LoadTimeout => Err(WebDriverError::new(ErrorStatus::Timeout, "Load timed out")) @@ -194,14 +200,14 @@ impl Handler { fn handle_get_current_url(&self) -> WebDriverResult { let pipeline_id = try!(self.get_root_pipeline()); - let (sender, reciever) = channel(); + let (sender, receiver) = channel(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd_msg = WebDriverCommandMsg::GetUrl(pipeline_id, sender); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); //Wait to get a load event - let url = reciever.recv().unwrap(); + let url = receiver.recv().unwrap(); Ok(WebDriverResponse::Generic(ValueResponse::new(url.serialize().to_json()))) } @@ -218,6 +224,18 @@ impl Handler { Ok(WebDriverResponse::Void) } + fn handle_refresh(&self) -> WebDriverResult { + let pipeline_id = try!(self.get_root_pipeline()); + + let (sender, receiver) = channel(); + + let ConstellationChan(ref const_chan) = self.constellation_chan; + let cmd_msg = WebDriverCommandMsg::Refresh(pipeline_id, sender.clone()); + const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); + + self.wait_for_load(sender, receiver) + } + fn handle_get_title(&self) -> WebDriverResult { let pipeline_id = try!(self.get_root_pipeline()); @@ -226,7 +244,7 @@ impl Handler { let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, WebDriverScriptCommand::GetTitle(sender)); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - let value = reciever.recv().unwrap(); + let value = receiver.recv().unwrap(); Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json()))) } @@ -257,7 +275,7 @@ impl Handler { let cmd = WebDriverScriptCommand::FindElementCSS(parameters.value.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - match reciever.recv().unwrap() { + match receiver.recv().unwrap() { Ok(value) => { let value_resp = value.map(|x| WebElement::new(x).to_json()).to_json(); Ok(WebDriverResponse::Generic(ValueResponse::new(value_resp))) @@ -300,12 +318,12 @@ impl Handler { WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd))).unwrap(); } - let frame = match reciever.recv().unwrap() { + let frame = match receiver.recv().unwrap() { Ok(Some((pipeline_id, subpage_id))) => { let (sender, reciever) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; const_chan.send(ConstellationMsg::GetFrame(pipeline_id, subpage_id, sender)).unwrap(); - reciever.recv().unwrap() + receiver.recv().unwrap() }, Ok(None) => None, Err(_) => { @@ -332,7 +350,7 @@ impl Handler { let cmd = WebDriverScriptCommand::FindElementsCSS(parameters.value.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - match reciever.recv().unwrap() { + match receiver.recv().unwrap() { Ok(value) => { let resp_value: Vec = value.into_iter().map( |x| WebElement::new(x).to_json()).collect(); @@ -351,7 +369,7 @@ impl Handler { let cmd = WebDriverScriptCommand::GetElementText(element.id.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - match reciever.recv().unwrap() { + match receiver.recv().unwrap() { Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json()))), Err(_) => Err(WebDriverError::new(ErrorStatus::StaleElementReference, "Unable to find element in document")) @@ -366,7 +384,7 @@ impl Handler { let cmd = WebDriverScriptCommand::GetActiveElement(sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - let value = reciever.recv().unwrap().map(|x| WebElement::new(x).to_json()); + let value = receiver.recv().unwrap().map(|x| WebElement::new(x).to_json()); Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json()))) } @@ -378,7 +396,7 @@ impl Handler { let cmd = WebDriverScriptCommand::GetElementTagName(element.id.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - match reciever.recv().unwrap() { + match receiver.recv().unwrap() { Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json()))), Err(_) => Err(WebDriverError::new(ErrorStatus::StaleElementReference, "Unable to find element in document")) @@ -410,7 +428,7 @@ impl Handler { let (sender, reciever) = ipc::channel().unwrap(); let command = WebDriverScriptCommand::ExecuteScript(script, sender); - self.execute_script(command, reciever) + self.execute_script(command, receiver) } fn handle_execute_async_script(&self, @@ -424,7 +442,7 @@ impl Handler { let (sender, reciever) = ipc::channel().unwrap(); let command = WebDriverScriptCommand::ExecuteAsyncScript(script, sender); - self.execute_script(command, reciever) + self.execute_script(command, receiver) } fn execute_script(&self, @@ -437,7 +455,7 @@ impl Handler { let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, command); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - match reciever.recv().unwrap() { + match receiver.recv().unwrap() { Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json()))), Err(WebDriverJSError::Timeout) => Err(WebDriverError::new(ErrorStatus::Timeout, "")), Err(WebDriverJSError::UnknownType) => Err(WebDriverError::new( @@ -458,7 +476,7 @@ impl Handler { let cmd_msg = WebDriverCommandMsg::TakeScreenshot(pipeline_id, sender); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - if let Some(x) = reciever.recv().unwrap() { + if let Some(x) = receiver.recv().unwrap() { img = Some(x); break; }; @@ -507,6 +525,7 @@ impl WebDriverHandler for Handler { WebDriverCommand::GetCurrentUrl => self.handle_get_current_url(), WebDriverCommand::GoBack => self.handle_go_back(), WebDriverCommand::GoForward => self.handle_go_forward(), + WebDriverCommand::Refresh => self.handle_refresh(), WebDriverCommand::GetTitle => self.handle_get_title(), WebDriverCommand::GetWindowHandle => self.handle_get_window_handle(), WebDriverCommand::GetWindowHandles => self.handle_get_window_handles(), From 512ba5031563640cebc1a237a881bc1274e3477c Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 15 Jun 2015 14:36:01 +0100 Subject: [PATCH 3/5] Add some more WebDriver capabilities from the spec. --- components/webdriver_server/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index a8b68eaadd7..9793a958a54 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -148,6 +148,9 @@ impl Handler { let mut capabilities = BTreeMap::new(); capabilities.insert("browserName".to_owned(), "servo".to_json()); capabilities.insert("browserVersion".to_owned(), "0.0.1".to_json()); + capabilities.insert("acceptSslCerts".to_owned(), false.to_json()); + capabilities.insert("takeScreenshot".to_owned(), true.to_json()); + capabilities.insert("takeElementScreenshot".to_owned(), false.to_json()); let rv = Ok(WebDriverResponse::NewSession( NewSessionResponse::new( session.id.to_string(), From 2a701cc3398cd9909477c2fb43f7e73cd7a97169 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sun, 19 Jul 2015 20:40:12 +0100 Subject: [PATCH 4/5] Fixup rebase issues --- components/compositing/constellation.rs | 2 +- components/webdriver_server/lib.rs | 32 ++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index da78540bd37..836ba81f976 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -948,7 +948,7 @@ impl Constellation { fn load_url_for_webdriver(&mut self, pipeline_id: PipelineId, load_data:LoadData, - reply: Sender) { + reply: IpcSender) { let new_pipeline_id = self.load_url(pipeline_id, load_data); if let Some(id) = new_pipeline_id { self.webdriver.load_channel = Some((id, reply)); diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 9793a958a54..a29939b64e1 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -134,7 +134,7 @@ impl Handler { } fn get_pipeline(&self, frame_id: Option) -> Option { - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; const_chan.send(ConstellationMsg::GetPipeline(frame_id, sender)).unwrap(); @@ -172,7 +172,7 @@ impl Handler { let pipeline_id = try!(self.get_root_pipeline()); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let load_data = LoadData::new(url); let ConstellationChan(ref const_chan) = self.constellation_chan; @@ -203,7 +203,7 @@ impl Handler { fn handle_get_current_url(&self) -> WebDriverResult { let pipeline_id = try!(self.get_root_pipeline()); - let (sender, receiver) = channel(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd_msg = WebDriverCommandMsg::GetUrl(pipeline_id, sender); @@ -230,7 +230,7 @@ impl Handler { fn handle_refresh(&self) -> WebDriverResult { let pipeline_id = try!(self.get_root_pipeline()); - let (sender, receiver) = channel(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd_msg = WebDriverCommandMsg::Refresh(pipeline_id, sender.clone()); @@ -242,7 +242,7 @@ impl Handler { fn handle_get_title(&self) -> WebDriverResult { let pipeline_id = try!(self.get_root_pipeline()); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, WebDriverScriptCommand::GetTitle(sender)); @@ -273,7 +273,7 @@ impl Handler { "Unsupported locator strategy")) } - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd = WebDriverScriptCommand::FindElementCSS(parameters.value.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); @@ -313,7 +313,7 @@ impl Handler { "Selecting frame by id not supported")); } let pipeline_id = try!(self.get_frame_pipeline()); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let cmd = WebDriverScriptCommand::GetFrameId(frame_id, sender); { let ConstellationChan(ref const_chan) = self.constellation_chan; @@ -323,7 +323,7 @@ impl Handler { let frame = match receiver.recv().unwrap() { Ok(Some((pipeline_id, subpage_id))) => { - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; const_chan.send(ConstellationMsg::GetFrame(pipeline_id, subpage_id, sender)).unwrap(); receiver.recv().unwrap() @@ -348,7 +348,7 @@ impl Handler { "Unsupported locator strategy")) } - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd = WebDriverScriptCommand::FindElementsCSS(parameters.value.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); @@ -367,7 +367,7 @@ impl Handler { fn handle_get_element_text(&self, element: &WebElement) -> WebDriverResult { let pipeline_id = try!(self.get_frame_pipeline()); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd = WebDriverScriptCommand::GetElementText(element.id.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); @@ -382,7 +382,7 @@ impl Handler { fn handle_get_active_element(&self) -> WebDriverResult { let pipeline_id = try!(self.get_frame_pipeline()); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd = WebDriverScriptCommand::GetActiveElement(sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); @@ -394,7 +394,7 @@ impl Handler { fn handle_get_element_tag_name(&self, element: &WebElement) -> WebDriverResult { let pipeline_id = try!(self.get_frame_pipeline()); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd = WebDriverScriptCommand::GetElementTagName(element.id.clone(), sender); let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd); @@ -429,7 +429,7 @@ impl Handler { // it with a vec of arguments. let script = format!("(function() {{ {} }})({})", func_body, args_string); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let command = WebDriverScriptCommand::ExecuteScript(script, sender); self.execute_script(command, receiver) } @@ -443,14 +443,14 @@ impl Handler { "setTimeout(webdriverTimeout, {}); (function(callback) {{ {} }})({})", self.script_timeout, func_body, args_string); - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let command = WebDriverScriptCommand::ExecuteAsyncScript(script, sender); self.execute_script(command, receiver) } fn execute_script(&self, command: WebDriverScriptCommand, - reciever: IpcReceiver) + receiver: IpcReceiver) -> WebDriverResult { let pipeline_id = try!(self.get_frame_pipeline()); @@ -474,7 +474,7 @@ impl Handler { let iterations = 30_000 / interval; for _ in 0..iterations { - let (sender, reciever) = ipc::channel().unwrap(); + let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; let cmd_msg = WebDriverCommandMsg::TakeScreenshot(pipeline_id, sender); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); From f44470ef523edf27e8e2c855e564283089791388 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sun, 19 Jul 2015 20:40:55 +0100 Subject: [PATCH 5/5] Ensure we get the post-redirect url --- components/compositing/constellation.rs | 4 ---- components/msg/constellation_msg.rs | 1 - components/msg/webdriver_msg.rs | 2 ++ components/script/script_task.rs | 2 ++ components/script/webdriver_handlers.rs | 8 ++++++++ components/webdriver_server/lib.rs | 4 ++-- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 836ba81f976..93192981dc7 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -914,10 +914,6 @@ impl Constellation { WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, reply) => { self.load_url_for_webdriver(pipeline_id, load_data, reply); }, - WebDriverCommandMsg::GetUrl(pipeline_id, reply) => { - let pipeline = self.pipeline(pipeline_id); - reply.send(pipeline.url.clone()).unwrap(); - }, WebDriverCommandMsg::Refresh(pipeline_id, reply) => { let load_data = { let pipeline = self.pipeline(pipeline_id); diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 24d9f9bfd7a..16c90b670d1 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -336,7 +336,6 @@ impl MozBrowserEvent { #[derive(Deserialize, Serialize)] pub enum WebDriverCommandMsg { LoadUrl(PipelineId, LoadData, IpcSender), - GetUrl(PipelineId, IpcSender), Refresh(PipelineId, IpcSender), ScriptCommand(PipelineId, WebDriverScriptCommand), TakeScreenshot(PipelineId, IpcSender>) diff --git a/components/msg/webdriver_msg.rs b/components/msg/webdriver_msg.rs index 0c2d8860a96..dd90a3492d9 100644 --- a/components/msg/webdriver_msg.rs +++ b/components/msg/webdriver_msg.rs @@ -6,6 +6,7 @@ use constellation_msg::{PipelineId, SubpageId}; use ipc_channel::ipc::IpcSender; use rustc_serialize::json::{Json, ToJson}; +use url::Url; #[derive(Deserialize, Serialize)] pub enum WebDriverScriptCommand { @@ -17,6 +18,7 @@ pub enum WebDriverScriptCommand { GetElementTagName(String, IpcSender>), GetElementText(String, IpcSender>), GetFrameId(WebDriverFrameId, IpcSender, ()>>), + GetUrl(IpcSender), GetTitle(IpcSender) } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index b1f7357a613..4ba2efddef0 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -873,6 +873,8 @@ impl ScriptTask { webdriver_handlers::handle_get_text(&page, pipeline_id, node_id, reply), WebDriverScriptCommand::GetFrameId(frame_id, reply) => webdriver_handlers::handle_get_frame_id(&page, pipeline_id, frame_id, reply), + WebDriverScriptCommand::GetUrl(reply) => + webdriver_handlers::handle_get_url(&page, pipeline_id, reply), WebDriverScriptCommand::GetTitle(reply) => webdriver_handlers::handle_get_title(&page, pipeline_id, reply), WebDriverScriptCommand::ExecuteAsyncScript(script, reply) => diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 591e38eb52b..e3b50cb2aaf 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -24,6 +24,7 @@ use js::jsval::UndefinedValue; use ipc_channel::ipc::IpcSender; use std::rc::Rc; +use url::Url; fn find_node_by_unique_id(page: &Rc, pipeline: PipelineId, node_id: String) -> Option> { let page = get_page(&*page, pipeline); @@ -179,3 +180,10 @@ pub fn handle_get_name(page: &Rc, None => Err(()) }).unwrap(); } + +pub fn handle_get_url(page: &Rc, + _pipeline: PipelineId, + reply: IpcSender) { + let url = page.document().r().url(); + reply.send(url).unwrap(); +} diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index a29939b64e1..91506de0330 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -206,10 +206,10 @@ impl Handler { let (sender, receiver) = ipc::channel().unwrap(); let ConstellationChan(ref const_chan) = self.constellation_chan; - let cmd_msg = WebDriverCommandMsg::GetUrl(pipeline_id, sender); + let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, + WebDriverScriptCommand::GetUrl(sender)); const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - //Wait to get a load event let url = receiver.recv().unwrap(); Ok(WebDriverResponse::Generic(ValueResponse::new(url.serialize().to_json())))