Implement wb element send keys for file input (#37224)

We can now send keys to file input, which results in uploading file with
given filename. Needs
`pref=dom_testing_html_input_element_select_files_enabled` flag to work.

https://w3c.github.io/webdriver/#element-send-keys

Testing:
`tests/wpt/meta/webdriver/tests/classic/element_send_keys/{events,
file_upload}.py.`

Signed-off-by: PotatoCP <kenzieradityatirtarahardja18@gmail.com>
This commit is contained in:
Kenzie Raditya Tirtarahardja 2025-06-05 14:48:14 +08:00 committed by GitHub
parent 165ac32f18
commit d66e4fc459
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 78 additions and 55 deletions

View file

@ -1619,14 +1619,23 @@ impl Handler {
let (sender, receiver) = ipc::channel().unwrap();
let cmd = WebDriverScriptCommand::FocusElement(element.to_string(), sender);
let cmd = WebDriverScriptCommand::WillSendKeys(
element.to_string(),
keys.text.to_string(),
self.session()?.strict_file_interactability,
sender,
);
let cmd_msg = WebDriverCommandMsg::ScriptCommand(browsing_context_id, cmd);
self.constellation_chan
.send(EmbedderToConstellationMessage::WebDriverCommand(cmd_msg))
.unwrap();
// TODO: distinguish the not found and not focusable cases
wait_for_script_response(receiver)?.map_err(|error| WebDriverError::new(error, ""))?;
// File input and non-typeable form control should have
// been handled in `webdriver_handler.rs`.
if wait_for_script_response(receiver)?.map_err(|error| WebDriverError::new(error, ""))? {
return Ok(WebDriverResponse::Void);
}
let input_events = send_keys(&keys.text);