webdriver: Merge pull request #72 from andreastt/set-timeouts-format

Align timeouts format with spec

Source-Repo: https://github.com/mozilla/webdriver-rust
Source-Revision: 426ea889f298133c12bdd9a4b107f130d18ac592

--HG--
extra : subtree_source : http%3A//tristan.corp.lon2.mozilla.com%3A8000
extra : subtree_revision : a985439baad85ea869a576b9bd3fb2b6413d60fa
This commit is contained in:
Andreas Tolfsen 2017-02-24 16:27:17 +00:00
Родитель 65639dddf9
Коммит 1939be5f35
2 изменённых файлов: 54 добавлений и 20 удалений

Просмотреть файл

@ -522,30 +522,48 @@ impl ToJson for GetParameters {
#[derive(PartialEq)]
pub struct TimeoutsParameters {
pub type_: String,
pub ms: f64
pub script: Option<u64>,
pub page_load: Option<u64>,
pub implicit: Option<u64>,
}
impl Parameters for TimeoutsParameters {
fn from_json(body: &Json) -> WebDriverResult<TimeoutsParameters> {
let data = try_opt!(body.as_object(), ErrorStatus::UnknownError,
let data = try_opt!(body.as_object(),
ErrorStatus::UnknownError,
"Message body was not an object");
let type_ = try_opt!(
try_opt!(data.get("type"),
ErrorStatus::InvalidArgument,
"Missing 'type' parameter").as_string(),
ErrorStatus::InvalidArgument,
"'type' not a string");
let ms = try_opt!(
try_opt!(data.get("ms"),
ErrorStatus::InvalidArgument,
"Missing 'ms' parameter").as_f64(),
ErrorStatus::InvalidArgument,
"'ms' not a float");
return Ok(TimeoutsParameters {
type_: type_.to_string(),
ms: ms
let script = match data.get("script") {
Some(json) => {
Some(try_opt!(json.as_u64(),
ErrorStatus::InvalidArgument,
"Script timeout duration was not a signed integer"))
}
None => None,
};
let page_load = match data.get("pageLoad") {
Some(json) => {
Some(try_opt!(json.as_u64(),
ErrorStatus::InvalidArgument,
"Script timeout duration was not a signed integer"))
}
None => None,
};
let implicit = match data.get("script") {
Some(json) => {
Some(try_opt!(json.as_u64(),
ErrorStatus::InvalidArgument,
"Script timeout duration was not a signed integer"))
}
None => None,
};
Ok(TimeoutsParameters {
script: script,
page_load: page_load,
implicit: implicit,
})
}
}
@ -553,8 +571,15 @@ impl Parameters for TimeoutsParameters {
impl ToJson for TimeoutsParameters {
fn to_json(&self) -> Json {
let mut data = BTreeMap::new();
data.insert("type".to_string(), self.type_.to_json());
data.insert("ms".to_string(), self.ms.to_json());
if let Some(ms) = self.script {
data.insert("script".into(), ms.to_json());
}
if let Some(ms) = self.page_load {
data.insert("pageLoad".into(), ms.to_json());
}
if let Some(ms) = self.implicit {
data.insert("implicit".into(), ms.to_json());
}
Json::Object(data)
}
}

Просмотреть файл

@ -12,6 +12,7 @@ pub enum WebDriverResponse {
ElementRect(ElementRectResponse),
Generic(ValueResponse),
NewSession(NewSessionResponse),
Timeouts(TimeoutsResponse),
Void,
WindowPosition(WindowPositionResponse),
WindowSize(WindowSizeResponse),
@ -26,6 +27,7 @@ impl WebDriverResponse {
WebDriverResponse::ElementRect(x) => json::encode(&x),
WebDriverResponse::Generic(x) => json::encode(&x),
WebDriverResponse::NewSession(x) => json::encode(&x),
WebDriverResponse::Timeouts(x) => json::encode(&x),
WebDriverResponse::Void => Ok("{}".to_string()),
WebDriverResponse::WindowPosition(x) => json::encode(&x),
WebDriverResponse::WindowSize(x) => json::encode(&x),
@ -59,6 +61,13 @@ impl NewSessionResponse {
}
}
#[derive(RustcEncodable, Debug)]
pub struct TimeoutsResponse {
pub script: u64,
pub pageLoad: u64,
pub implicit: u64,
}
#[derive(RustcEncodable, Debug)]
pub struct ValueResponse {
pub value: json::Json