зеркало из https://github.com/mozilla/gecko-dev.git
webdriver: Merge pull request #26 from Ms2ger/cleanup
Various cleanup. Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 338dcf0716188d3fa89ba2062bb4cf14db660e22 --HG-- extra : subtree_source : http%3A//tristan.corp.lon2.mozilla.com%3A8000 extra : subtree_revision : 153d50bc115a597a019b517a87953cb12bceec92
This commit is contained in:
Родитель
c21a98c0c7
Коммит
8ad0f251b8
|
@ -11,5 +11,4 @@ license = "MPL-2.0"
|
|||
log = "0.3.5"
|
||||
regex = "0.1.47"
|
||||
rustc-serialize = "0.3.16"
|
||||
uuid = "0.1.18"
|
||||
hyper = {version = "0.8", default-features = false}
|
||||
|
|
|
@ -94,15 +94,11 @@ impl <U: WebDriverExtensionRoute> WebDriverMessage<U> {
|
|||
let body_data = if requires_body {
|
||||
debug!("Got request body {}", body);
|
||||
match Json::from_str(body) {
|
||||
Ok(x) => {
|
||||
match x {
|
||||
Json::Object(_) => x,
|
||||
_ => return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
|
||||
"Body was not a json object"))
|
||||
}
|
||||
},
|
||||
Ok(x @ Json::Object(_)) => x,
|
||||
Ok(_) => return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
|
||||
"Body was not a json object")),
|
||||
Err(_) => return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
|
||||
&format!("Failed to decode request body as json: {}", body)[..]))
|
||||
format!("Failed to decode request body as json: {}", body)))
|
||||
}
|
||||
} else {
|
||||
Json::Null
|
||||
|
@ -316,7 +312,6 @@ impl <U: WebDriverExtensionRoute> WebDriverMessage<U> {
|
|||
|
||||
impl <U:WebDriverExtensionRoute> ToJson for WebDriverMessage<U> {
|
||||
fn to_json(&self) -> Json {
|
||||
let mut data = BTreeMap::new();
|
||||
let parameters = match self.command {
|
||||
WebDriverCommand::NewSession |
|
||||
WebDriverCommand::DeleteSession | WebDriverCommand::GetCurrentUrl |
|
||||
|
@ -353,8 +348,10 @@ impl <U:WebDriverExtensionRoute> ToJson for WebDriverMessage<U> {
|
|||
WebDriverCommand::SendAlertText(ref x) => Some(x.to_json()),
|
||||
WebDriverCommand::Extension(ref x) => x.parameters_json(),
|
||||
};
|
||||
if parameters.is_some() {
|
||||
data.insert("parameters".to_string(), parameters.unwrap());
|
||||
|
||||
let mut data = BTreeMap::new();
|
||||
if let Some(parameters) = parameters {
|
||||
data.insert("parameters".to_string(), parameters);
|
||||
}
|
||||
Json::Object(data)
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ impl LocatorStrategy {
|
|||
"partial link text" => Ok(LocatorStrategy::PartialLinkText),
|
||||
"xpath" => Ok(LocatorStrategy::XPath),
|
||||
x => Err(WebDriverError::new(ErrorStatus::InvalidArgument,
|
||||
&format!("Unknown locator strategy {}", x)[..]))
|
||||
format!("Unknown locator strategy {}", x)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use hyper::status::StatusCode;
|
||||
use rustc_serialize::json::{Json, ToJson, ParserError, DecoderError};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::From;
|
||||
use std::error::Error;
|
||||
|
@ -99,7 +100,7 @@ pub type WebDriverResult<T> = Result<T, WebDriverError>;
|
|||
#[derive(Debug)]
|
||||
pub struct WebDriverError {
|
||||
pub error: ErrorStatus,
|
||||
pub message: String,
|
||||
pub message: Cow<'static, str>,
|
||||
delete_session: bool
|
||||
}
|
||||
|
||||
|
@ -110,10 +111,12 @@ impl fmt::Display for WebDriverError {
|
|||
}
|
||||
|
||||
impl WebDriverError {
|
||||
pub fn new(error: ErrorStatus, message: &str) -> WebDriverError {
|
||||
pub fn new<S>(error: ErrorStatus, message: S) -> WebDriverError
|
||||
where S: Into<Cow<'static, str>>
|
||||
{
|
||||
WebDriverError {
|
||||
error: error,
|
||||
message: message.to_string(),
|
||||
message: message.into(),
|
||||
delete_session: false
|
||||
}
|
||||
}
|
||||
|
@ -161,21 +164,20 @@ impl Error for WebDriverError {
|
|||
impl From<ParserError> for WebDriverError {
|
||||
fn from(err: ParserError) -> WebDriverError {
|
||||
WebDriverError::new(ErrorStatus::UnknownError,
|
||||
err.description())
|
||||
err.description().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IoError> for WebDriverError {
|
||||
fn from(err: IoError) -> WebDriverError {
|
||||
WebDriverError::new(ErrorStatus::UnknownError,
|
||||
err.description())
|
||||
err.description().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DecoderError> for WebDriverError {
|
||||
fn from(err: DecoderError) -> WebDriverError {
|
||||
WebDriverError::new(ErrorStatus::UnknownError,
|
||||
&format!(
|
||||
"Could not decode json string:\n{}", err.description())[..])
|
||||
format!("Could not decode json string:\n{}", err.description()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,6 +228,6 @@ impl <U: WebDriverExtensionRoute> WebDriverHttpApi<U> {
|
|||
}
|
||||
}
|
||||
Err(WebDriverError::new(error,
|
||||
&format!("{} {} did not match a known command", method, path)[..]))
|
||||
format!("{} {} did not match a known command", method, path)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,9 +104,9 @@ impl <T: WebDriverHandler<U>,
|
|||
if existing_session.id != *msg_session_id {
|
||||
Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidSessionId,
|
||||
&format!("Got unexpected session id {} expected {}",
|
||||
msg_session_id,
|
||||
existing_session.id)[..]))
|
||||
format!("Got unexpected session id {} expected {}",
|
||||
msg_session_id,
|
||||
existing_session.id)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче