forked from mirrors/gecko-dev
Bug 1895738 - [geckodriver] Update validation of "unhandledPromptBehavior" capability for WebDriver BiDi. r=webdriver-reviewers,jgraham,jdescottes
Depends on D210730 Differential Revision: https://phabricator.services.mozilla.com/D210731
This commit is contained in:
parent
ca131ac9dc
commit
cb35fc63ba
1 changed files with 92 additions and 11 deletions
|
|
@ -180,7 +180,7 @@ impl SpecNewSessionParameters {
|
|||
"proxy" => SpecNewSessionParameters::validate_proxy(value)?,
|
||||
"timeouts" => SpecNewSessionParameters::validate_timeouts(value)?,
|
||||
"unhandledPromptBehavior" => {
|
||||
SpecNewSessionParameters::validate_unhandled_prompt_behaviour(value)?
|
||||
SpecNewSessionParameters::validate_unhandled_prompt_behavior(value)?
|
||||
}
|
||||
x => {
|
||||
if !x.contains(':') {
|
||||
|
|
@ -415,19 +415,65 @@ impl SpecNewSessionParameters {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_unhandled_prompt_behaviour(value: &Value) -> WebDriverResult<()> {
|
||||
let behaviour = try_opt!(
|
||||
value.as_str(),
|
||||
ErrorStatus::InvalidArgument,
|
||||
format!("unhandledPromptBehavior is not a string: {}", value)
|
||||
);
|
||||
fn validate_unhandled_prompt_behavior(value: &Value) -> WebDriverResult<()> {
|
||||
match value {
|
||||
Value::Object(obj) => {
|
||||
// Unhandled Prompt Behavior type as used by WebDriver BiDi
|
||||
for (key, value) in obj {
|
||||
match &**key {
|
||||
x @ "alert"
|
||||
| x @ "beforeUnload"
|
||||
| x @ "confirm"
|
||||
| x @ "default"
|
||||
| x @ "prompt" => {
|
||||
let behavior = try_opt!(
|
||||
value.as_str(),
|
||||
ErrorStatus::InvalidArgument,
|
||||
format!(
|
||||
"'{}' unhandledPromptBehavior value is not a string: {}",
|
||||
x, value
|
||||
)
|
||||
);
|
||||
|
||||
match behaviour {
|
||||
"accept" | "accept and notify" | "dismiss" | "dismiss and notify" | "ignore" => {}
|
||||
x => {
|
||||
match behavior {
|
||||
"accept" | "accept and notify" | "dismiss"
|
||||
| "dismiss and notify" | "ignore" => {}
|
||||
x => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidArgument,
|
||||
format!(
|
||||
"'{}' unhandledPromptBehavior value is invalid: {}",
|
||||
x, behavior
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
x => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidArgument,
|
||||
format!("Invalid unhandledPromptBehavior entry: {}", x),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Value::String(behavior) => match behavior.as_str() {
|
||||
"accept" | "accept and notify" | "dismiss" | "dismiss and notify" | "ignore" => {}
|
||||
x => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidArgument,
|
||||
format!("Invalid unhandledPromptBehavior value: {}", x),
|
||||
))
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidArgument,
|
||||
format!("Invalid unhandledPromptBehavior value: {}", x),
|
||||
format!(
|
||||
"unhandledPromptBehavior is neither an object nor a string: {}",
|
||||
value
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
@ -793,6 +839,41 @@ mod tests {
|
|||
assert_de(&caps, json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_unhandled_prompt_behavior() {
|
||||
fn validate_prompt_behavior(v: Value) -> WebDriverResult<()> {
|
||||
SpecNewSessionParameters::validate_unhandled_prompt_behavior(&v)
|
||||
}
|
||||
|
||||
// capability as string
|
||||
validate_prompt_behavior(json!("accept")).unwrap();
|
||||
validate_prompt_behavior(json!("accept and notify")).unwrap();
|
||||
validate_prompt_behavior(json!("dismiss")).unwrap();
|
||||
validate_prompt_behavior(json!("dismiss and notify")).unwrap();
|
||||
validate_prompt_behavior(json!("ignore")).unwrap();
|
||||
assert!(validate_prompt_behavior(json!("foo")).is_err());
|
||||
|
||||
// capability as object
|
||||
let types = ["alert", "beforeUnload", "confirm", "default", "prompt"];
|
||||
let handlers = [
|
||||
"accept",
|
||||
"accept and notify",
|
||||
"dismiss",
|
||||
"dismiss and notify",
|
||||
"ignore",
|
||||
];
|
||||
for promptType in types {
|
||||
assert!(validate_prompt_behavior(json!({promptType: "foo"})).is_err());
|
||||
for handler in handlers {
|
||||
validate_prompt_behavior(json!({promptType: handler})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
for handler in handlers {
|
||||
assert!(validate_prompt_behavior(json!({"foo": handler})).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_proxy() {
|
||||
fn validate_proxy(v: Value) -> WebDriverResult<()> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue