webdriver: Add handle any user prompts step for all commands (#38035)

- Add `handler any user prompt` step for all commands.
- Enable webdriver tests which were blocked by `handle any user prompt`
step.

---------

Signed-off-by: batu_hoang <hoang.binh.trong@huawei.com>
This commit is contained in:
batu_hoang 2025-07-17 17:47:47 +08:00 committed by GitHub
parent 18d1a62add
commit 345733a5c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 859 additions and 472 deletions

View file

@ -577,8 +577,17 @@ impl App {
webdriver_script_command,
));
},
WebDriverCommandMsg::CurrentUserPrompt(webview_id, response_sender) => {
let current_dialog =
running_state.get_current_active_dialog_webdriver_type(webview_id);
if let Err(error) = response_sender.send(current_dialog) {
warn!("Failed to send response of CurrentUserPrompt: {error}");
};
},
WebDriverCommandMsg::HandleUserPrompt(webview_id, action, response_sender) => {
let response = if running_state.webview_has_active_dialog(webview_id) {
let alert_text = running_state.alert_text_of_newest_dialog(webview_id);
match action {
WebDriverUserPromptAction::Accept => {
running_state.accept_active_dialogs(webview_id)
@ -586,9 +595,14 @@ impl App {
WebDriverUserPromptAction::Dismiss => {
running_state.dismiss_active_dialogs(webview_id)
},
WebDriverUserPromptAction::Ignore => {},
};
Ok(())
// Return success for AcceptAlert and DismissAlert commands.
Ok(alert_text)
} else {
// Return error for AcceptAlert and DismissAlert commands
// if there is no active dialog.
Err(())
};
@ -622,7 +636,8 @@ impl App {
running_state: &RunningAppState,
) {
match msg {
WebDriverScriptCommand::ExecuteScript(_webview_id, response_sender) => {
WebDriverScriptCommand::ExecuteScript(_webview_id, response_sender) |
WebDriverScriptCommand::ExecuteAsyncScript(_webview_id, response_sender) => {
// Give embedder a chance to interrupt the script command.
// Webdriver only handles 1 script command at a time, so we can
// safely set a new interrupt sender and remove the previous one here.

View file

@ -21,7 +21,7 @@ use servo::{
AllowOrDenyRequest, AuthenticationRequest, FilterPattern, FormControl, GamepadHapticEffectType,
KeyboardEvent, LoadStatus, PermissionRequest, Servo, ServoDelegate, ServoError, SimpleDialog,
TraversalId, WebDriverCommandMsg, WebDriverJSResult, WebDriverJSValue, WebDriverLoadStatus,
WebView, WebViewBuilder, WebViewDelegate,
WebDriverUserPrompt, WebView, WebViewBuilder, WebViewDelegate,
};
use url::Url;
@ -340,13 +340,23 @@ impl RunningAppState {
}
pub(crate) fn webview_has_active_dialog(&self, webview_id: WebViewId) -> bool {
let inner = self.inner();
inner
self.inner()
.dialogs
.get(&webview_id)
.is_some_and(|dialogs| !dialogs.is_empty())
}
pub(crate) fn get_current_active_dialog_webdriver_type(
&self,
webview_id: WebViewId,
) -> Option<WebDriverUserPrompt> {
self.inner()
.dialogs
.get(&webview_id)
.and_then(|dialogs| dialogs.last())
.map(|dialog| dialog.webdriver_diaglog_type())
}
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| {

View file

@ -14,7 +14,7 @@ use servo::servo_geometry::DeviceIndependentPixel;
use servo::{
AlertResponse, AuthenticationRequest, ColorPicker, ConfirmResponse, FilterPattern,
PermissionRequest, PromptResponse, RgbColor, SelectElement, SelectElementOption,
SelectElementOptionOrOptgroup, SimpleDialog,
SelectElementOptionOrOptgroup, SimpleDialog, WebDriverUserPrompt,
};
pub enum Dialog {
@ -582,6 +582,16 @@ impl Dialog {
},
}
}
pub fn webdriver_diaglog_type(&self) -> WebDriverUserPrompt {
match self {
Dialog::File { .. } => WebDriverUserPrompt::File,
Dialog::SimpleDialog(SimpleDialog::Alert { .. }) => WebDriverUserPrompt::Alert,
Dialog::SimpleDialog(SimpleDialog::Confirm { .. }) => WebDriverUserPrompt::Confirm,
Dialog::SimpleDialog(SimpleDialog::Prompt { .. }) => WebDriverUserPrompt::Prompt,
_ => WebDriverUserPrompt::Default,
}
}
}
fn make_dialog_label(message: &str, ui: &mut egui::Ui, input_text: Option<&mut String>) {