mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
webdriver: Implement support for simple dialogs (#37913)
Implement webdriver user prompt: accept alert, dismiss alert, get alert text. Tests: https://github.com/longvatrong111/servo/actions/runs/16175408035 https://github.com/longvatrong111/servo/actions/runs/16175409545 Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
parent
84f0cd5801
commit
2e44aba753
9 changed files with 296 additions and 42 deletions
|
@ -160,6 +160,59 @@ pub enum SimpleDialog {
|
|||
},
|
||||
}
|
||||
|
||||
impl SimpleDialog {
|
||||
/// Returns the message of the dialog.
|
||||
pub fn message(&self) -> &str {
|
||||
match self {
|
||||
SimpleDialog::Alert { message, .. } => message,
|
||||
SimpleDialog::Confirm { message, .. } => message,
|
||||
SimpleDialog::Prompt { message, .. } => message,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dismiss(&self) {
|
||||
match self {
|
||||
SimpleDialog::Alert {
|
||||
response_sender, ..
|
||||
} => {
|
||||
let _ = response_sender.send(AlertResponse::Ok);
|
||||
},
|
||||
SimpleDialog::Confirm {
|
||||
response_sender, ..
|
||||
} => {
|
||||
let _ = response_sender.send(ConfirmResponse::Cancel);
|
||||
},
|
||||
SimpleDialog::Prompt {
|
||||
response_sender, ..
|
||||
} => {
|
||||
let _ = response_sender.send(PromptResponse::Cancel);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn accept(&self) {
|
||||
match self {
|
||||
SimpleDialog::Alert {
|
||||
response_sender, ..
|
||||
} => {
|
||||
let _ = response_sender.send(AlertResponse::Ok);
|
||||
},
|
||||
SimpleDialog::Confirm {
|
||||
response_sender, ..
|
||||
} => {
|
||||
let _ = response_sender.send(ConfirmResponse::Ok);
|
||||
},
|
||||
SimpleDialog::Prompt {
|
||||
default,
|
||||
response_sender,
|
||||
..
|
||||
} => {
|
||||
let _ = response_sender.send(PromptResponse::Ok(default.clone()));
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||
pub struct AuthenticationResponse {
|
||||
/// Username for http request authentication
|
||||
|
|
|
@ -28,6 +28,12 @@ use crate::{MouseButton, MouseButtonAction};
|
|||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub struct WebDriverMessageId(pub usize);
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverUserPromptAction {
|
||||
Accept,
|
||||
Dismiss,
|
||||
}
|
||||
|
||||
/// Messages to the constellation originating from the WebDriver server.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverCommandMsg {
|
||||
|
@ -115,6 +121,12 @@ pub enum WebDriverCommandMsg {
|
|||
IsWebViewOpen(WebViewId, IpcSender<bool>),
|
||||
/// Check whether browsing context is open.
|
||||
IsBrowsingContextOpen(BrowsingContextId, IpcSender<bool>),
|
||||
HandleUserPrompt(
|
||||
WebViewId,
|
||||
WebDriverUserPromptAction,
|
||||
IpcSender<Result<(), ()>>,
|
||||
),
|
||||
GetAlertText(WebViewId, IpcSender<Result<String, ()>>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
@ -237,4 +249,5 @@ pub enum WebDriverLoadStatus {
|
|||
Complete,
|
||||
Timeout,
|
||||
Canceled,
|
||||
Blocked,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue