webdriver: Merge pull request #38 from jgraham/jgraham/remove_capabilities
authorJames Graham <james@hoppipolla.co.uk>
Fri, 22 Jul 2016 17:06:53 +0100
changeset 428076 fbf946c2053a2aa9d678ac77127e0318d4a6e25d
parent 428075 56bf13f38c12204a6d25917d50af6f1c5adcf7d7
child 428077 3a1ca45c98d060672d60c2de08323324d89fe8b1
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
webdriver: Merge pull request #38 from jgraham/jgraham/remove_capabilities Add ability to consume capabilities. Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 03bb9a05d6d2f1c5d2ede4ca479b2a73fec27e85
testing/webdriver/src/command.rs
testing/webdriver/src/server.rs
--- a/testing/webdriver/src/command.rs
+++ b/testing/webdriver/src/command.rs
@@ -379,19 +379,28 @@ pub trait Parameters: Sized {
 #[derive(PartialEq)]
 pub struct NewSessionParameters {
     pub desired: BTreeMap<String, Json>,
     pub required: BTreeMap<String, Json>,
 }
 
 impl NewSessionParameters {
     pub fn get(&self, name: &str) -> Option<&Json> {
-        debug!("Getting {} from capabilities", name);
         self.required.get(name).or_else(|| self.desired.get(name))
     }
+
+    pub fn consume(&mut self, name: &str) -> Option<Json> {
+        let required = self.required.remove(name);
+        let desired = self.desired.remove(name);
+        if required.is_some() {
+            required
+        } else {
+            desired
+        }
+    }
 }
 
 impl Parameters for NewSessionParameters {
     fn from_json(body: &Json) -> WebDriverResult<NewSessionParameters> {
         let data = try_opt!(body.as_object(),
                             ErrorStatus::UnknownError,
                             "Message body was not an object");
 
--- a/testing/webdriver/src/server.rs
+++ b/testing/webdriver/src/server.rs
@@ -30,17 +30,17 @@ impl Session {
     fn new(id: String) -> Session {
         Session {
             id: id
         }
     }
 }
 
 pub trait WebDriverHandler<U: WebDriverExtensionRoute=VoidWebDriverExtensionRoute> : Send {
-    fn handle_command(&mut self, session: &Option<Session>, msg: &WebDriverMessage<U>) -> WebDriverResult<WebDriverResponse>;
+    fn handle_command(&mut self, session: &Option<Session>, msg: WebDriverMessage<U>) -> WebDriverResult<WebDriverResponse>;
     fn delete_session(&mut self, session: &Option<Session>);
 }
 
 struct Dispatcher<T: WebDriverHandler<U>,
                   U: WebDriverExtensionRoute> {
     handler: T,
     session: Option<Session>,
     extension_type: PhantomData<U>,
@@ -56,17 +56,17 @@ impl <T: WebDriverHandler<U>,
         }
     }
 
     fn run(&mut self, msg_chan: Receiver<DispatchMessage<U>>) {
         loop {
             match msg_chan.recv() {
                 Ok(DispatchMessage::HandleWebDriver(msg, resp_chan)) => {
                     let resp = match self.check_session(&msg) {
-                        Ok(_) => self.handler.handle_command(&self.session, &msg),
+                        Ok(_) => self.handler.handle_command(&self.session, msg),
                         Err(e) => Err(e)
                     };
 
                     match resp {
                         Ok(WebDriverResponse::NewSession(ref new_session)) => {
                             self.session = Some(Session::new(new_session.sessionId.clone()));
                         },
                         Ok(WebDriverResponse::DeleteSession) => {