Implement webdriver extract script arguments (#38357)

Fix script parsing step.
Implement webdriver `extract script arguments`.
Implement `deserialize_web_element` and `deserialize_shadow_root` from
script command argument.

Testing:
`/tests/wpt/tests/webdriver/tests/classic/execute_script/`
`/tests/wpt/tests/webdriver/tests/classic/execute_async_script/`

cc: @xiaochengh

---------

Signed-off-by: batu_hoang <hoang.binh.trong@huawei.com>
This commit is contained in:
batu_hoang 2025-08-12 14:57:19 +08:00 committed by GitHub
parent c0d884ddb2
commit 9effdce5a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 228 additions and 169 deletions

View file

@ -1524,9 +1524,22 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
.map(Root::upcast::<Element>)
}
fn WebdriverWindow(&self, _id: DOMString) -> Option<DomRoot<Window>> {
warn!("Window references are not supported in webdriver yet");
None
fn WebdriverWindow(&self, id: DOMString) -> Option<DomRoot<WindowProxy>> {
let window_proxy = self.window_proxy.get()?;
// Window must be top level browsing context.
if window_proxy.browsing_context_id() != window_proxy.webview_id() {
return None;
}
let pipeline_id = window_proxy.currently_active()?;
let document = ScriptThread::find_document(pipeline_id)?;
if document.upcast::<Node>().unique_id(pipeline_id) == id.str() {
Some(DomRoot::from_ref(&window_proxy))
} else {
None
}
}
fn WebdriverShadowRoot(&self, id: DOMString) -> Option<DomRoot<ShadowRoot>> {

View file

@ -2396,6 +2396,22 @@ impl ScriptThread {
can_gc,
)
},
WebDriverScriptCommand::GetKnownElement(element_id, reply) => {
webdriver_handlers::handle_get_known_element(
&documents,
pipeline_id,
element_id,
reply,
)
},
WebDriverScriptCommand::GetKnownShadowRoot(element_id, reply) => {
webdriver_handlers::handle_get_known_shadow_root(
&documents,
pipeline_id,
element_id,
reply,
)
},
WebDriverScriptCommand::GetActiveElement(reply) => {
webdriver_handlers::handle_get_active_element(&documents, pipeline_id, reply)
},

View file

@ -122,6 +122,18 @@ fn is_disabled(element: &Element) -> bool {
element.is_actually_disabled()
}
pub(crate) fn handle_get_known_shadow_root(
documents: &DocumentCollection,
pipeline: PipelineId,
shadow_root_id: String,
reply: IpcSender<Result<(), ErrorStatus>>,
) {
let result = get_known_shadow_root(documents, pipeline, shadow_root_id).map(|_| ());
if reply.send(result).is_err() {
error!("Webdriver get known shadow root reply failed");
}
}
/// <https://w3c.github.io/webdriver/#dfn-get-a-known-shadow-root>
fn get_known_shadow_root(
documents: &DocumentCollection,
@ -170,6 +182,18 @@ fn get_known_shadow_root(
Ok(shadow_root)
}
pub(crate) fn handle_get_known_element(
documents: &DocumentCollection,
pipeline: PipelineId,
element_id: String,
reply: IpcSender<Result<(), ErrorStatus>>,
) {
let result = get_known_element(documents, pipeline, element_id).map(|_| ());
if reply.send(result).is_err() {
error!("Webdriver get known element reply failed");
}
}
/// <https://w3c.github.io/webdriver/#dfn-get-a-known-element>
fn get_known_element(
documents: &DocumentCollection,