mirror of
https://github.com/servo/servo.git
synced 2025-07-17 04:13:42 +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
|
@ -8,6 +8,7 @@
|
|||
|
||||
mod actions;
|
||||
mod capabilities;
|
||||
mod user_prompt;
|
||||
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::{Cell, LazyCell, RefCell};
|
||||
|
@ -515,6 +516,11 @@ impl Handler {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// This function is called only if session and webview are verified.
|
||||
fn verified_webview_id(&self) -> WebViewId {
|
||||
self.session().unwrap().webview_id
|
||||
}
|
||||
|
||||
fn focus_webview_id(&self) -> WebDriverResult<WebViewId> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.send_message_to_embedder(WebDriverCommandMsg::GetFocusedWebView(sender.clone()))?;
|
||||
|
@ -782,7 +788,19 @@ impl Handler {
|
|||
debug!("waiting for load");
|
||||
let timeout = self.session()?.load_timeout;
|
||||
let result = select! {
|
||||
recv(self.load_status_receiver) -> _ => Ok(WebDriverResponse::Void),
|
||||
recv(self.load_status_receiver) -> res => {
|
||||
match res {
|
||||
Ok(WebDriverLoadStatus::Blocked) => {
|
||||
Err(WebDriverError::new(
|
||||
ErrorStatus::UnexpectedAlertOpen,
|
||||
"Load is blocked",
|
||||
))
|
||||
}
|
||||
_ => {
|
||||
Ok(WebDriverResponse::Void)
|
||||
}
|
||||
}
|
||||
},
|
||||
recv(after(Duration::from_millis(timeout))) -> _ => Err(
|
||||
WebDriverError::new(ErrorStatus::Timeout, "Load timed out")
|
||||
),
|
||||
|
@ -1605,15 +1623,6 @@ impl Handler {
|
|||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dismiss-alert
|
||||
fn handle_dismiss_alert(&mut self) -> WebDriverResult<WebDriverResponse> {
|
||||
// Step 1. If session's current top-level browsing context is no longer open,
|
||||
// return error with error code no such window.
|
||||
self.verify_top_level_browsing_context_is_open(self.session()?.webview_id)?;
|
||||
// Since user prompts are not yet implement this will always succeed
|
||||
Ok(WebDriverResponse::Void)
|
||||
}
|
||||
|
||||
fn handle_get_timeouts(&mut self) -> WebDriverResult<WebDriverResponse> {
|
||||
let session = self
|
||||
.session
|
||||
|
@ -2231,6 +2240,8 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
|
|||
},
|
||||
WebDriverCommand::ElementClick(ref element) => self.handle_element_click(element),
|
||||
WebDriverCommand::DismissAlert => self.handle_dismiss_alert(),
|
||||
WebDriverCommand::AcceptAlert => self.handle_accept_alert(),
|
||||
WebDriverCommand::GetAlertText => self.handle_get_alert_text(),
|
||||
WebDriverCommand::DeleteCookies => self.handle_delete_cookies(),
|
||||
WebDriverCommand::DeleteCookie(name) => self.handle_delete_cookie(name),
|
||||
WebDriverCommand::GetTimeouts => self.handle_get_timeouts(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue