[WebDriver] Fully implement "switch to (parent) frame" (#37685)

1. Separate the handling of ["switch to parent
frame"](https://w3c.github.io/webdriver/#switch-to-parent-frame) from
the rest as the processing is a bit different
2. Implement "Select frame by 16-bits numbered ID" for ["switch to
frame"](https://w3c.github.io/webdriver/#switch-to-frame)
3. Implement other missing steps

Testing: All WebDriver Conformance test with new passing cases

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-06-26 15:44:16 +08:00 committed by GitHub
parent 253fb247f5
commit f9880637e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 79 additions and 61 deletions

View file

@ -2494,6 +2494,9 @@ impl ScriptThread {
can_gc,
)
},
WebDriverScriptCommand::GetParentFrameId(reply) => {
webdriver_handlers::handle_get_parent_frame_id(&documents, pipeline_id, reply)
},
WebDriverScriptCommand::GetBrowsingContextId(webdriver_frame_id, reply) => {
webdriver_handlers::handle_get_browsing_context_id(
&documents,

View file

@ -586,6 +586,30 @@ pub(crate) fn handle_execute_async_script(
}
}
/// Get BrowsingContextId for <https://w3c.github.io/webdriver/#switch-to-parent-frame>
pub(crate) fn handle_get_parent_frame_id(
documents: &DocumentCollection,
pipeline: PipelineId,
reply: IpcSender<Result<BrowsingContextId, ErrorStatus>>,
) {
// Step 2. If session's current parent browsing context is no longer open,
// return error with error code no such window.
reply
.send(
documents
.find_window(pipeline)
.and_then(|window| {
window
.window_proxy()
.parent()
.map(|parent| parent.browsing_context_id())
})
.ok_or(ErrorStatus::NoSuchWindow),
)
.unwrap();
}
/// Get the BrowsingContextId for <https://w3c.github.io/webdriver/#dfn-switch-to-frame>
pub(crate) fn handle_get_browsing_context_id(
documents: &DocumentCollection,
pipeline: PipelineId,
@ -594,9 +618,20 @@ pub(crate) fn handle_get_browsing_context_id(
) {
reply
.send(match webdriver_frame_id {
WebDriverFrameId::Short(_) => {
// This isn't supported yet
Err(ErrorStatus::UnsupportedOperation)
WebDriverFrameId::Short(id) => {
// Step 5. If id is not a supported property index of window,
// return error with error code no such frame.
documents
.find_document(pipeline)
.ok_or(ErrorStatus::NoSuchWindow)
.and_then(|document| {
document
.iframes()
.iter()
.nth(id as usize)
.and_then(|iframe| iframe.browsing_context_id())
.ok_or(ErrorStatus::NoSuchFrame)
})
},
WebDriverFrameId::Element(element_id) => {
get_known_element(documents, pipeline, element_id).and_then(|element| {
@ -606,15 +641,6 @@ pub(crate) fn handle_get_browsing_context_id(
.ok_or(ErrorStatus::NoSuchFrame)
})
},
WebDriverFrameId::Parent => documents
.find_window(pipeline)
.and_then(|window| {
window
.window_proxy()
.parent()
.map(|parent| parent.browsing_context_id())
})
.ok_or(ErrorStatus::NoSuchFrame),
})
.unwrap();
}