mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +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
|
@ -337,6 +337,38 @@ impl RunningAppState {
|
|||
.is_some_and(|dialogs| !dialogs.is_empty())
|
||||
}
|
||||
|
||||
pub(crate) fn webview_has_active_dialog(&self, webview_id: WebViewId) -> bool {
|
||||
let inner = self.inner();
|
||||
inner
|
||||
.dialogs
|
||||
.get(&webview_id)
|
||||
.is_some_and(|dialogs| !dialogs.is_empty())
|
||||
}
|
||||
|
||||
pub(crate) fn accept_active_dialogs(&self, webview_id: WebViewId) {
|
||||
if let Some(dialogs) = self.inner_mut().dialogs.get_mut(&webview_id) {
|
||||
dialogs.drain(..).for_each(|dialog| {
|
||||
dialog.accept();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dismiss_active_dialogs(&self, webview_id: WebViewId) {
|
||||
if let Some(dialogs) = self.inner_mut().dialogs.get_mut(&webview_id) {
|
||||
dialogs.drain(..).for_each(|dialog| {
|
||||
dialog.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn alert_text_of_newest_dialog(&self, webview_id: WebViewId) -> Option<String> {
|
||||
self.inner()
|
||||
.dialogs
|
||||
.get(&webview_id)
|
||||
.and_then(|dialogs| dialogs.last())
|
||||
.and_then(|dialog| dialog.message())
|
||||
}
|
||||
|
||||
pub(crate) fn get_focused_webview_index(&self) -> Option<usize> {
|
||||
let focused_id = self.inner().focused_webview_id?;
|
||||
self.webviews()
|
||||
|
@ -486,6 +518,17 @@ impl WebViewDelegate for RunningAppState {
|
|||
fn show_simple_dialog(&self, webview: servo::WebView, dialog: SimpleDialog) {
|
||||
self.interrupt_webdriver_script_evaluation();
|
||||
|
||||
// Dialogs block the page load, so need need to notify WebDriver
|
||||
let webview_id = webview.id();
|
||||
if let Some(sender) = self
|
||||
.webdriver_senders
|
||||
.borrow_mut()
|
||||
.load_status_senders
|
||||
.get(&webview_id)
|
||||
{
|
||||
let _ = sender.send(WebDriverLoadStatus::Blocked);
|
||||
};
|
||||
|
||||
if self.servoshell_preferences.headless &&
|
||||
self.servoshell_preferences.webdriver_port.is_none()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue