Bug 1569100 - Add SetTimeouts command to Marionette. r=ato

Differential Revision: https://phabricator.services.mozilla.com/D39662

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nupur Baghel 2019-07-29 11:36:34 +00:00
Родитель 141bcffcc8
Коммит 417c0e949d
4 изменённых файлов: 45 добавлений и 20 удалений

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

@ -20,9 +20,15 @@ pub struct WebElement {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Timeouts {
pub implicit: u64,
#[serde(rename = "pageLoad", alias = "page load")]
pub page_load: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub implicit: Option<u64>,
#[serde(
rename = "pageLoad",
alias = "page load",
skip_serializing_if = "Option::is_none"
)]
pub page_load: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub script: Option<u64>,
}
@ -41,10 +47,10 @@ mod tests {
}
#[test]
fn test_timeouts() {
fn test_timeouts_with_all_params() {
let data = Timeouts {
implicit: 1000,
page_load: 200000,
implicit: Some(1000),
page_load: Some(200000),
script: Some(60000),
};
assert_ser_de(
@ -56,4 +62,14 @@ mod tests {
json!({"implicit":1000,"page load":200000,"script":60000}),
);
}
#[test]
fn test_timeouts_with_missing_params() {
let data = Timeouts {
implicit: Some(1000),
page_load: None,
script: None,
};
assert_ser_de(&data, json!({"implicit":1000}));
}
}

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

@ -6,14 +6,14 @@ use crate::common::{Timeouts, WebElement};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MarionetteResult {
#[serde(deserialize_with = "from_value", serialize_with = "to_empty_value")]
Null,
#[serde(deserialize_with = "from_value", serialize_with = "to_value")]
String(String),
Timeouts(Timeouts),
#[serde(deserialize_with = "from_value", serialize_with = "to_value")]
WebElement(WebElement),
WebElements(Vec<WebElement>),
#[serde(deserialize_with = "from_value", serialize_with = "to_empty_value")]
Null,
Timeouts(Timeouts),
}
fn to_value<T, S>(data: T, serializer: S) -> Result<S::Ok, S::Error>
@ -91,8 +91,8 @@ mod tests {
#[test]
fn test_timeouts_response() {
let data = Timeouts {
implicit: 1000,
page_load: 200000,
implicit: Some(1000),
page_load: Some(200000),
script: Some(60000),
};
assert_ser_de(

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

@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::common::Timeouts;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Locator {
pub using: Selector,
@ -28,6 +30,8 @@ pub enum Command {
FindElements(Locator),
#[serde(rename = "WebDriver:GetTimeouts")]
GetTimeouts,
#[serde(rename = "WebDriver:SetTimeouts")]
SetTimeouts(Timeouts)
}
#[cfg(test)]

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

@ -2,6 +2,7 @@ use crate::command::{
AddonInstallParameters, AddonUninstallParameters, GeckoContextParameters,
GeckoExtensionCommand, GeckoExtensionRoute, XblLocatorParameters, CHROME_ELEMENT_KEY,
};
use marionette_rs::common::Timeouts as MarionetteTimeouts;
use marionette_rs::message::{Command, Message, MessageId, Request};
use marionette_rs::webdriver::{
Command as MarionetteWebDriverCommand, Locator as MarionetteLocator,
@ -801,6 +802,9 @@ fn try_convert_to_marionette_message(
MarionetteWebDriverCommand::FindElements(x.to_marionette()?),
)),
GetTimeouts => Some(Command::WebDriver(MarionetteWebDriverCommand::GetTimeouts)),
SetTimeouts(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::SetTimeouts(
x.to_marionette()?,
))),
_ => None,
})
}
@ -995,7 +999,6 @@ impl MarionetteCommand {
);
(Some("WebDriver:SendAlertText"), Some(Ok(data)))
}
SetTimeouts(ref x) => (Some("WebDriver:SetTimeouts"), Some(x.to_marionette())),
SetWindowRect(ref x) => (Some("WebDriver:SetWindowRect"), Some(x.to_marionette())),
SwitchToFrame(ref x) => (Some("WebDriver:SwitchToFrame"), Some(x.to_marionette())),
SwitchToParentFrame => (Some("WebDriver:SwitchToParentFrame"), None),
@ -1558,14 +1561,16 @@ impl ToMarionette<Map<String, Value>> for SwitchToWindowParameters {
}
}
impl ToMarionette<Map<String, Value>> for TimeoutsParameters {
fn to_marionette(&self) -> WebDriverResult<Map<String, Value>> {
Ok(try_opt!(
serde_json::to_value(self)?.as_object(),
ErrorStatus::UnknownError,
"Expected an object"
)
.clone())
impl ToMarionette<MarionetteTimeouts> for TimeoutsParameters {
fn to_marionette(&self) -> WebDriverResult<MarionetteTimeouts> {
Ok(MarionetteTimeouts {
implicit: self.implicit.clone(),
page_load: self.page_load.clone(),
script: match self.script {
Some(x) => x,
None => None,
},
})
}
}