mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 1509513 - [webdriver] Add support for the "New Window" command. r=ato
Differential Revision: https://phabricator.services.mozilla.com/D16503 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f3368c5273
commit
bc9d3b2007
@ -23,6 +23,7 @@ pub enum WebDriverCommand<T: WebDriverExtensionCommand> {
|
||||
GetPageSource,
|
||||
GetWindowHandle,
|
||||
GetWindowHandles,
|
||||
NewWindow(NewWindowParameters),
|
||||
CloseWindow,
|
||||
GetWindowRect,
|
||||
SetWindowRect(WindowRectParameters),
|
||||
@ -120,6 +121,7 @@ impl<U: WebDriverExtensionRoute> WebDriverMessage<U> {
|
||||
Route::GetPageSource => WebDriverCommand::GetPageSource,
|
||||
Route::GetWindowHandle => WebDriverCommand::GetWindowHandle,
|
||||
Route::GetWindowHandles => WebDriverCommand::GetWindowHandles,
|
||||
Route::NewWindow => WebDriverCommand::NewWindow(serde_json::from_str(raw_body)?),
|
||||
Route::CloseWindow => WebDriverCommand::CloseWindow,
|
||||
Route::GetTimeouts => WebDriverCommand::GetTimeouts,
|
||||
Route::SetTimeouts => WebDriverCommand::SetTimeouts(serde_json::from_str(raw_body)?),
|
||||
@ -469,6 +471,12 @@ impl CapabilitiesMatching for NewSessionParameters {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NewWindowParameters {
|
||||
#[serde(rename = "type")]
|
||||
pub type_hint: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SendKeysParameters {
|
||||
pub text: String,
|
||||
@ -939,6 +947,45 @@ mod tests {
|
||||
check_deserialize(&json, &data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_new_window_parameters_without_type() {
|
||||
let json = r#"{}"#;
|
||||
let data = NewWindowParameters { type_hint: None };
|
||||
|
||||
check_deserialize(&json, &data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_new_window_parameters_with_optional_null_type() {
|
||||
let json = r#"{"type":null}"#;
|
||||
let data = NewWindowParameters { type_hint: None };
|
||||
|
||||
check_deserialize(&json, &data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_new_window_parameters_with_supported_type() {
|
||||
let json = r#"{"type":"tab"}"#;
|
||||
let data = NewWindowParameters { type_hint: Some("tab".into()) };
|
||||
|
||||
check_deserialize(&json, &data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_new_window_parameters_with_unknown_type() {
|
||||
let json = r#"{"type":"foo"}"#;
|
||||
let data = NewWindowParameters { type_hint: Some("foo".into()) };
|
||||
|
||||
check_deserialize(&json, &data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_new_window_parameters_with_invalid_type() {
|
||||
let json = r#"{"type":3}"#;
|
||||
|
||||
assert!(serde_json::from_str::<NewWindowParameters>(&json).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_send_keys_parameters_with_value() {
|
||||
let json = r#"{"text":"foo"}"#;
|
||||
|
@ -25,6 +25,7 @@ fn standard_routes<U: WebDriverExtensionRoute>() -> Vec<(Method, &'static str, R
|
||||
"/session/{sessionId}/window/handles",
|
||||
Route::GetWindowHandles,
|
||||
),
|
||||
(Method::POST, "/session/{sessionId}/window/new", Route::NewWindow),
|
||||
(Method::DELETE, "/session/{sessionId}/window", Route::CloseWindow),
|
||||
(
|
||||
Method::GET,
|
||||
@ -229,6 +230,7 @@ pub enum Route<U: WebDriverExtensionRoute> {
|
||||
GetPageSource,
|
||||
GetWindowHandle,
|
||||
GetWindowHandles,
|
||||
NewWindow,
|
||||
CloseWindow,
|
||||
GetWindowSize, // deprecated
|
||||
SetWindowSize, // deprecated
|
||||
|
@ -5,6 +5,7 @@ use serde_json::Value;
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
#[serde(untagged, remote = "Self")]
|
||||
pub enum WebDriverResponse {
|
||||
NewWindow(NewWindowResponse),
|
||||
CloseWindow(CloseWindowResponse),
|
||||
Cookie(CookieResponse),
|
||||
Cookies(CookiesResponse),
|
||||
@ -32,6 +33,13 @@ impl Serialize for WebDriverResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
pub struct NewWindowResponse {
|
||||
pub handle: String,
|
||||
#[serde(rename = "type")]
|
||||
pub typ: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
pub struct CloseWindowResponse(pub Vec<String>);
|
||||
|
||||
@ -133,6 +141,17 @@ mod tests {
|
||||
use crate::test::check_serialize;
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn test_json_new_window_response() {
|
||||
let json = r#"{"value":{"handle":"42","type":"window"}}"#;
|
||||
let data = WebDriverResponse::NewWindow(NewWindowResponse {
|
||||
handle: "42".into(),
|
||||
typ: "window".into(),
|
||||
});
|
||||
|
||||
check_serialize(&json, &data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_close_window_response() {
|
||||
let json = r#"{"value":["1234"]}"#;
|
||||
|
Loading…
Reference in New Issue
Block a user