diff --git a/components/msg/Cargo.toml b/components/msg/Cargo.toml index ac3a967802d..a47e3f83d8c 100644 --- a/components/msg/Cargo.toml +++ b/components/msg/Cargo.toml @@ -24,3 +24,4 @@ serde_macros = "0.7" url = {version = "1.0.0", features = ["heap_size", "serde"]} util = {path = "../util", features = ["servo"]} webrender_traits = {git = "https://github.com/servo/webrender_traits"} +cookie = { version = "0.2.5", features = ["serialize-serde", "serialize-rustc" ] } diff --git a/components/msg/lib.rs b/components/msg/lib.rs index bd97c3a33da..bac2f1a6011 100644 --- a/components/msg/lib.rs +++ b/components/msg/lib.rs @@ -10,6 +10,7 @@ #[allow(unused_extern_crates)] #[macro_use] extern crate bitflags; +extern crate cookie as cookie_rs; extern crate euclid; extern crate heapsize; extern crate hyper; diff --git a/components/msg/webdriver_msg.rs b/components/msg/webdriver_msg.rs index a6c94c3a439..ea848ce431d 100644 --- a/components/msg/webdriver_msg.rs +++ b/components/msg/webdriver_msg.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use constellation_msg::PipelineId; +use cookie_rs::Cookie; use euclid::rect::Rect; use ipc_channel::ipc::IpcSender; use rustc_serialize::json::{Json, ToJson}; @@ -10,12 +11,15 @@ use url::Url; #[derive(Deserialize, Serialize)] pub enum WebDriverScriptCommand { + AddCookie(Cookie, IpcSender>), ExecuteScript(String, IpcSender), ExecuteAsyncScript(String, IpcSender), FindElementCSS(String, IpcSender, ()>>), FindElementsCSS(String, IpcSender, ()>>), FocusElement(String, IpcSender>), GetActiveElement(IpcSender>), + GetCookie(String, IpcSender>), + GetCookies(IpcSender>), GetElementAttribute(String, String, IpcSender, ()>>), GetElementCSS(String, String, IpcSender>), GetElementRect(String, IpcSender, ()>>), @@ -28,6 +32,12 @@ pub enum WebDriverScriptCommand { GetTitle(IpcSender) } +#[derive(Deserialize, Serialize)] +pub enum WebDriverCookieError { + InvalidDomain, + UnableToSetCookie +} + #[derive(Deserialize, Serialize)] pub enum WebDriverJSValue { Undefined, diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 8eba3907a05..e87a7119640 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" bitflags = "0.7" brotli = {git = "https://github.com/ende76/brotli-rs"} content-blocker = "0.2" -cookie = {version = "0.2.4", features = ["serialize-rustc"]} +cookie = { version = "0.2.5", features = ["serialize-serde", "serialize-rustc" ] } device = {git = "https://github.com/servo/devices"} devtools_traits = {path = "../devtools_traits"} flate2 = "0.2.0" diff --git a/components/net/cookie_storage.rs b/components/net/cookie_storage.rs index 19a14b40564..f1ce7ee3190 100644 --- a/components/net/cookie_storage.rs +++ b/components/net/cookie_storage.rs @@ -6,6 +6,7 @@ //! http://tools.ietf.org/html/rfc6265 use cookie::Cookie; +use cookie_rs; use net_traits::CookieSource; use std::cmp::Ordering; use url::Url; @@ -114,4 +115,12 @@ impl CookieStorage { _ => Some(result) } } + + pub fn cookies_data_for_url<'a>(&'a mut self, url: &'a Url, + source: CookieSource) -> Box + 'a> { + Box::new(self.cookies.iter_mut().filter(move |c| { c.appropriate_for_url(url, source) }).map(|c| { + c.touch(); + c.cookie.clone() + })) + } } diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index 45dd9e35bc2..6825437e162 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -8,6 +8,7 @@ use chrome_loader; use connector::{Connector, create_http_connector}; use content_blocker::BLOCKED_CONTENT_RULES; use cookie; +use cookie_rs; use cookie_storage::CookieStorage; use data_loader; use devtools_traits::DevtoolsControlMsg; @@ -277,10 +278,17 @@ impl ResourceChannelManager { self.resource_manager.websocket_connect(connect, connect_data, group), CoreResourceMsg::SetCookiesForUrl(request, cookie_list, source) => self.resource_manager.set_cookies_for_url(request, cookie_list, source, group), + CoreResourceMsg::SetCookiesForUrlWithData(request, cookie, source) => + self.resource_manager.set_cookies_for_url_with_data(request, cookie, source, group), CoreResourceMsg::GetCookiesForUrl(url, consumer, source) => { let mut cookie_jar = group.cookie_jar.write().unwrap(); consumer.send(cookie_jar.cookies_for_url(&url, source)).unwrap(); } + CoreResourceMsg::GetCookiesDataForUrl(url, consumer, source) => { + let mut cookie_jar = group.cookie_jar.write().unwrap(); + let cookies = cookie_jar.cookies_data_for_url(&url, source).collect(); + consumer.send(cookies).unwrap(); + } CoreResourceMsg::Cancel(res_id) => { if let Some(cancel_sender) = self.resource_manager.cancel_load_map.get(&res_id) { let _ = cancel_sender.send(()); @@ -488,6 +496,14 @@ impl CoreResourceManager { } } + fn set_cookies_for_url_with_data(&mut self, request: Url, cookie: cookie_rs::Cookie, source: CookieSource, + resource_group: &ResourceGroup) { + if let Some(cookie) = cookie::Cookie::new_wrapped(cookie, &request, source) { + let mut cookie_jar = resource_group.cookie_jar.write().unwrap(); + cookie_jar.push(cookie, source) + } + } + fn load(&mut self, load_data: LoadData, consumer: LoadConsumer, diff --git a/components/net_traits/Cargo.toml b/components/net_traits/Cargo.toml index 2208be8ece2..37b27b21837 100644 --- a/components/net_traits/Cargo.toml +++ b/components/net_traits/Cargo.toml @@ -23,3 +23,4 @@ serde_macros = "0.7" url = {version = "1.0.0", features = ["heap_size"]} websocket = "0.17" uuid = { version = "0.2.2", features = ["v4", "serde"] } +cookie = { version = "0.2.5", features = ["serialize-serde", "serialize-rustc" ] } diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 8323da3d515..bb9e31ad160 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -12,6 +12,7 @@ #![deny(unsafe_code)] +extern crate cookie as cookie_rs; extern crate heapsize; extern crate hyper; extern crate image as piston_image; @@ -28,6 +29,7 @@ extern crate util; extern crate uuid; extern crate websocket; +use cookie_rs::Cookie; use filemanager_thread::FileManagerThreadMsg; use heapsize::HeapSizeOf; use hyper::header::{ContentType, Headers}; @@ -423,8 +425,12 @@ pub enum CoreResourceMsg { WebsocketConnect(WebSocketCommunicate, WebSocketConnectData), /// Store a set of cookies for a given originating URL SetCookiesForUrl(Url, String, CookieSource), + /// Store a set of cookies for a given originating URL + SetCookiesForUrlWithData(Url, Cookie, CookieSource), /// Retrieve the stored cookies for a given URL GetCookiesForUrl(Url, IpcSender>, CookieSource), + /// Get a cookie by name for a given originating URL + GetCookiesDataForUrl(Url, IpcSender>, CookieSource), /// Cancel a network request corresponding to a given `ResourceId` Cancel(ResourceId), /// Synchronization message solely for knowing the state of the ResourceChannelManager loop diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index fe446adebd6..5a6687abb7f 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -22,6 +22,7 @@ app_units = {version = "0.2.3", features = ["plugins"]} bitflags = "0.7" canvas_traits = {path = "../canvas_traits"} caseless = "0.1.0" +cookie = { version = "0.2.5", features = ["serialize-serde", "serialize-rustc" ] } cssparser = {version = "0.5.4", features = ["heap_size", "serde-serialization"]} devtools_traits = {path = "../devtools_traits"} encoding = "0.2" diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 08c04bf2b3e..23c50075068 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1562,7 +1562,7 @@ impl Document { } /// https://html.spec.whatwg.org/multipage/#cookie-averse-document-object - fn is_cookie_averse(&self) -> bool { + pub fn is_cookie_averse(&self) -> bool { self.browsing_context.is_none() || !url_has_network_scheme(&self.url) } diff --git a/components/script/lib.rs b/components/script/lib.rs index 757c8a28678..4823b2f475f 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -36,6 +36,7 @@ extern crate app_units; extern crate bitflags; extern crate canvas_traits; extern crate caseless; +extern crate cookie as cookie_rs; extern crate core; #[macro_use] extern crate cssparser; diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index a8e81846717..6697f334696 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1059,6 +1059,8 @@ impl ScriptThread { fn handle_webdriver_msg(&self, pipeline_id: PipelineId, msg: WebDriverScriptCommand) { let context = self.root_browsing_context(); match msg { + WebDriverScriptCommand::AddCookie(params, reply) => + webdriver_handlers::handle_add_cookie(&context, pipeline_id, params, reply), WebDriverScriptCommand::ExecuteScript(script, reply) => webdriver_handlers::handle_execute_script(&context, pipeline_id, script, reply), WebDriverScriptCommand::FindElementCSS(selector, reply) => @@ -1069,6 +1071,10 @@ impl ScriptThread { webdriver_handlers::handle_focus_element(&context, pipeline_id, element_id, reply), WebDriverScriptCommand::GetActiveElement(reply) => webdriver_handlers::handle_get_active_element(&context, pipeline_id, reply), + WebDriverScriptCommand::GetCookies(reply) => + webdriver_handlers::handle_get_cookies(&context, pipeline_id, reply), + WebDriverScriptCommand::GetCookie(name, reply) => + webdriver_handlers::handle_get_cookie(&context, pipeline_id, name, reply), WebDriverScriptCommand::GetElementTagName(node_id, reply) => webdriver_handlers::handle_get_name(&context, pipeline_id, node_id, reply), WebDriverScriptCommand::GetElementAttribute(node_id, name, reply) => diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 3c9d1ffcfb2..1c320b5be06 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use cookie_rs::Cookie; use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; @@ -26,12 +27,16 @@ use dom::window::ScriptHelpers; use euclid::point::Point2D; use euclid::rect::Rect; use euclid::size::Size2D; -use ipc_channel::ipc::IpcSender; +use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::JSContext; use js::jsapi::{HandleValue, RootedValue}; use js::jsval::UndefinedValue; use msg::constellation_msg::PipelineId; +use msg::webdriver_msg::WebDriverCookieError; use msg::webdriver_msg::{WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue}; +use net_traits::CookieSource::{HTTP, NonHTTP}; +use net_traits::CoreResourceMsg::{GetCookiesDataForUrl, SetCookiesForUrlWithData}; +use net_traits::IpcSend; use script_thread::get_browsing_context; use url::Url; @@ -177,6 +182,66 @@ pub fn handle_get_active_element(context: &BrowsingContext, |elem| elem.upcast::().unique_id())).unwrap(); } +pub fn handle_get_cookies(context: &BrowsingContext, + _pipeline: PipelineId, + reply: IpcSender>) { + let document = context.active_document(); + let url = document.url(); + let (sender, receiver) = ipc::channel().unwrap(); + let _ = document.window().resource_threads().send( + GetCookiesDataForUrl(url.clone(), sender, NonHTTP) + ); + let cookies = receiver.recv().unwrap(); + reply.send(cookies).unwrap(); +} + +// https://w3c.github.io/webdriver/webdriver-spec.html#get-cookie +pub fn handle_get_cookie(context: &BrowsingContext, + _pipeline: PipelineId, + name: String, + reply: IpcSender>) { + let document = context.active_document(); + let url = document.url(); + let (sender, receiver) = ipc::channel().unwrap(); + let _ = document.window().resource_threads().send( + GetCookiesDataForUrl(url.clone(), sender, NonHTTP) + ); + let cookies = receiver.recv().unwrap(); + reply.send(cookies.into_iter().filter(|c| c.name == &*name).collect()).unwrap(); +} + +// https://w3c.github.io/webdriver/webdriver-spec.html#add-cookie +pub fn handle_add_cookie(context: &BrowsingContext, + _pipeline: PipelineId, + cookie: Cookie, + reply: IpcSender>) { + let document = context.active_document(); + let url = document.url(); + let method = if cookie.httponly { + HTTP + } else { + NonHTTP + }; + reply.send(match (document.is_cookie_averse(), cookie.domain.clone()) { + (true, _) => Err(WebDriverCookieError::InvalidDomain), + (false, Some(ref domain)) if url.host_str().map(|x| { x == &**domain }).unwrap_or(false) => { + let _ = document.window().resource_threads().send( + SetCookiesForUrlWithData(url.clone(), cookie, method) + ); + Ok(()) + }, + (false, None) => { + let _ = document.window().resource_threads().send( + SetCookiesForUrlWithData(url.clone(), cookie, method) + ); + Ok(()) + }, + (_, _) => { + Err(WebDriverCookieError::UnableToSetCookie) + }, + }).unwrap(); +} + pub fn handle_get_title(context: &BrowsingContext, _pipeline: PipelineId, reply: IpcSender) { reply.send(String::from(context.active_document().Title())).unwrap(); } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index f5e2d6152c3..6d650539bc3 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -379,11 +379,12 @@ dependencies = [ [[package]] name = "cookie" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "openssl 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -966,7 +967,7 @@ name = "hyper" version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1362,6 +1363,7 @@ name = "msg" version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1385,7 +1387,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "brotli 0.3.23 (git+https://github.com/ende76/brotli-rs)", "content-blocker 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "device 0.0.1 (git+https://github.com/servo/devices)", "devtools_traits 0.0.1", "flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1433,7 +1435,7 @@ name = "net_tests" version = "0.0.1" dependencies = [ "content-blocker 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1453,6 +1455,7 @@ dependencies = [ name = "net_traits" version = "0.0.1" dependencies = [ + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1894,6 +1897,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "canvas_traits 0.0.1", "caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2549,6 +2553,7 @@ dependencies = [ name = "webdriver_server" version = "0.0.1" dependencies = [ + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/webdriver_server/Cargo.toml b/components/webdriver_server/Cargo.toml index d2e22b98b1a..00593b03b4e 100644 --- a/components/webdriver_server/Cargo.toml +++ b/components/webdriver_server/Cargo.toml @@ -23,3 +23,4 @@ script_traits = {path = "../script_traits"} url = {version = "1.0.0", features = ["heap_size"]} uuid = { version = "0.2", features = ["v4"] } webdriver = "0.9" +cookie = { version = "0.2.5", features = ["serialize-serde", "serialize-rustc" ] } diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 065ab0239bb..d2cedb10858 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -10,6 +10,7 @@ #![deny(unsafe_code)] +extern crate cookie as cookie_rs; extern crate euclid; extern crate hyper; extern crate image; @@ -32,7 +33,8 @@ use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use keys::keycodes_to_keys; use msg::constellation_msg::{FrameId, LoadData, PipelineId}; use msg::constellation_msg::{NavigationDirection, PixelFormat, WebDriverCommandMsg}; -use msg::webdriver_msg::{LoadStatus, WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverScriptCommand}; +use msg::webdriver_msg::{LoadStatus, WebDriverCookieError, WebDriverFrameId}; +use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult, WebDriverScriptCommand}; use regex::Captures; use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64}; use rustc_serialize::json::{Json, ToJson}; @@ -47,13 +49,15 @@ use url::Url; use util::prefs::{get_pref, reset_all_prefs, reset_pref, set_pref, PrefValue}; use util::thread::spawn_named; use uuid::Uuid; -use webdriver::command::{GetParameters, JavascriptCommandParameters, LocatorParameters}; -use webdriver::command::{Parameters, SendKeysParameters, SwitchToFrameParameters}; -use webdriver::command::{TimeoutsParameters, WindowSizeParameters}; +use webdriver::command::WindowSizeParameters; +use webdriver::command::{AddCookieParameters, GetParameters, JavascriptCommandParameters}; +use webdriver::command::{LocatorParameters, Parameters}; +use webdriver::command::{SendKeysParameters, SwitchToFrameParameters, TimeoutsParameters}; use webdriver::command::{WebDriverCommand, WebDriverExtensionCommand, WebDriverMessage}; -use webdriver::common::{LocatorStrategy, WebElement}; +use webdriver::common::{Date, LocatorStrategy, Nullable, WebElement}; use webdriver::error::{ErrorStatus, WebDriverError, WebDriverResult}; use webdriver::httpapi::WebDriverExtensionRoute; +use webdriver::response::{Cookie, CookieResponse}; use webdriver::response::{ElementRectResponse, NewSessionResponse, ValueResponse}; use webdriver::response::{WebDriverResponse, WindowSizeResponse}; use webdriver::server::{self, Session, WebDriverHandler}; @@ -64,6 +68,25 @@ fn extension_routes() -> Vec<(Method, &'static str, ServoExtensionRoute)> { (Post, "/session/{sessionId}/servo/prefs/reset", ServoExtensionRoute::ResetPrefs)] } +fn cookie_msg_to_cookie(cookie: cookie_rs::Cookie) -> Cookie { + Cookie { + name: cookie.name, + value: cookie.value, + path: cookie.path.map(Nullable::Value).unwrap_or(Nullable::Null), + domain: cookie.domain.map(Nullable::Value).unwrap_or(Nullable::Null), + expiry: match cookie.expires { + Some(time) => Nullable::Value(Date::new(time.to_timespec().sec as u64)), + None => Nullable::Null + }, + maxAge: match cookie.max_age { + Some(time) => Nullable::Value(Date::new(time)), + None => Nullable::Null + }, + secure: cookie.secure, + httpOnly: cookie.httponly, + } +} + pub fn start_server(port: u16, constellation_chan: Sender) { let handler = Handler::new(constellation_chan); spawn_named("WebdriverHttpServer".to_owned(), move || { @@ -615,6 +638,51 @@ impl Handler { } } + fn handle_get_cookies(&self) -> WebDriverResult { + let (sender, receiver) = ipc::channel().unwrap(); + try!(self.frame_script_command(WebDriverScriptCommand::GetCookies(sender))); + let cookies = receiver.recv().unwrap(); + let response = cookies.into_iter().map(|cookie| { + cookie_msg_to_cookie(cookie) + }).collect::>(); + Ok(WebDriverResponse::Cookie(CookieResponse::new(response))) + } + + fn handle_get_cookie(&self, name: &str) -> WebDriverResult { + let (sender, receiver) = ipc::channel().unwrap(); + try!(self.frame_script_command(WebDriverScriptCommand::GetCookie(name.to_owned(), sender))); + let cookies = receiver.recv().unwrap(); + let response = cookies.into_iter().map(|cookie| { + cookie_msg_to_cookie(cookie) + }).collect::>(); + Ok(WebDriverResponse::Cookie(CookieResponse::new(response))) + } + + fn handle_add_cookie(&self, params: &AddCookieParameters) -> WebDriverResult { + let (sender, receiver) = ipc::channel().unwrap(); + let cookie = cookie_rs::Cookie { + name: params.name.to_owned(), + value: params.value.to_owned(), + path: params.path.to_owned().into(), + domain: params.domain.to_owned().into(), + expires: None, + max_age: None, + secure: params.secure, + httponly: params.httpOnly, + custom: BTreeMap::new() + }; + try!(self.frame_script_command(WebDriverScriptCommand::AddCookie(cookie, sender))); + match receiver.recv().unwrap() { + Ok(_) => Ok(WebDriverResponse::Void), + Err(response) => match response { + WebDriverCookieError::InvalidDomain => Err(WebDriverError::new(ErrorStatus::InvalidCookieDomain, + "Invalid cookie domain")), + WebDriverCookieError::UnableToSetCookie => Err(WebDriverError::new(ErrorStatus::UnableToSetCookie, + "Unable to set cookie")) + } + } + } + fn handle_set_timeouts(&mut self, parameters: &TimeoutsParameters) -> WebDriverResult { //TODO: this conversion is crazy, spec should limit these to u32 and check upstream let value = parameters.ms as u32; @@ -790,6 +858,7 @@ impl WebDriverHandler for Handler { match msg.command { WebDriverCommand::NewSession => self.handle_new_session(), WebDriverCommand::DeleteSession => self.handle_delete_session(), + WebDriverCommand::AddCookie(ref parameters) => self.handle_add_cookie(parameters), WebDriverCommand::Get(ref parameters) => self.handle_get(parameters), WebDriverCommand::GetCurrentUrl => self.handle_current_url(), WebDriverCommand::GetWindowSize => self.handle_window_size(), @@ -806,6 +875,8 @@ impl WebDriverHandler for Handler { WebDriverCommand::SwitchToParentFrame => self.handle_switch_to_parent_frame(), WebDriverCommand::FindElement(ref parameters) => self.handle_find_element(parameters), WebDriverCommand::FindElements(ref parameters) => self.handle_find_elements(parameters), + WebDriverCommand::GetCookie(ref name) => self.handle_get_cookie(name), + WebDriverCommand::GetCookies => self.handle_get_cookies(), WebDriverCommand::GetActiveElement => self.handle_active_element(), WebDriverCommand::GetElementRect(ref element) => self.handle_element_rect(element), WebDriverCommand::GetElementText(ref element) => self.handle_element_text(element), diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 3497e7a8fd3..3339ad8458d 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -338,11 +338,12 @@ dependencies = [ [[package]] name = "cookie" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "openssl 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -875,7 +876,7 @@ name = "hyper" version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1264,6 +1265,7 @@ name = "msg" version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1287,7 +1289,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "brotli 0.3.23 (git+https://github.com/ende76/brotli-rs)", "content-blocker 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "device 0.0.1 (git+https://github.com/servo/devices)", "devtools_traits 0.0.1", "flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1334,6 +1336,7 @@ dependencies = [ name = "net_traits" version = "0.0.1" dependencies = [ + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1748,6 +1751,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "canvas_traits 0.0.1", "caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2411,6 +2415,7 @@ dependencies = [ name = "webdriver_server" version = "0.0.1" dependencies = [ + "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/tests/unit/net/cookie_http_state.rs b/tests/unit/net/cookie_http_state.rs index 45abb4d5d5f..fceb9189f52 100644 --- a/tests/unit/net/cookie_http_state.rs +++ b/tests/unit/net/cookie_http_state.rs @@ -288,7 +288,6 @@ fn test_attribute0003() { } #[test] -#[should_panic] // Look at cookie_http_state_utils.py if this test fails fn test_attribute0004() { let r = run("http://home.example.org:8888/cookie-parser?attribute0004", &["foo=bar; Secure="], @@ -297,7 +296,6 @@ fn test_attribute0004() { } #[test] -#[should_panic] // Look at cookie_http_state_utils.py if this test fails fn test_attribute0005() { let r = run("http://home.example.org:8888/cookie-parser?attribute0005", &["foo=bar; Secure=aaaa"], @@ -314,7 +312,6 @@ fn test_attribute0006() { } #[test] -#[should_panic] // Look at cookie_http_state_utils.py if this test fails fn test_attribute0007() { let r = run("http://home.example.org:8888/cookie-parser?attribute0007", &["foo=bar; Secure =aaaaa"], @@ -323,7 +320,6 @@ fn test_attribute0007() { } #[test] -#[should_panic] // Look at cookie_http_state_utils.py if this test fails fn test_attribute0008() { let r = run("http://home.example.org:8888/cookie-parser?attribute0008", &["foo=bar; Secure= aaaaa"], diff --git a/tests/unit/net/cookie_http_state_utils.py b/tests/unit/net/cookie_http_state_utils.py index 6b429b5d859..b8820c312da 100644 --- a/tests/unit/net/cookie_http_state_utils.py +++ b/tests/unit/net/cookie_http_state_utils.py @@ -23,10 +23,6 @@ SHOULD_PANIC = "\n#[should_panic] // Look at cookie_http_state_utils.py if this # Those tests should PASS. But until fixes land in servo, keep them failing FAILING_TESTS = [ - "attribute0004", # Waiting for issue 46 of alexcrichton/cookie-rs - "attribute0005", # Waiting for issue 46 of alexcrichton/cookie-rs - "attribute0007", # Waiting for issue 46 of alexcrichton/cookie-rs - "attribute0008", # Waiting for issue 46 of alexcrichton/cookie-rs "0003", # Waiting for a way to clean expired cookies "0006", # Waiting for a way to clean expired cookies "mozilla0001", # Waiting for a way to clean expired cookies