From 83050645226dfe5f6fab449ae644f026bc386d4d Mon Sep 17 00:00:00 2001 From: Euclid Ye Date: Fri, 29 Aug 2025 17:37:48 +0800 Subject: [PATCH] webdriver: Improve parsing of Frame and Window (#39012) In #38745, we changed the id of Frame and Window as the result of `ToString` trait. This PR - adapts the parsing of frame/window accordingly. - for frame, return the [WindowProxy](https://developer.mozilla.org/en-US/docs/Web/API/WindowProxy) object of the iframe as it's supposed to do. Testing: `execute_{async_}script/arguments.py` --------- Signed-off-by: Euclid Ye --- components/script/dom/window.rs | 23 +++++++++++-------- .../script_bindings/webidls/Window.webidl | 2 +- .../execute_async_script/arguments.py.ini | 6 ----- .../classic/execute_script/arguments.py.ini | 6 ----- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 27ee62a7552..73a1502666a 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1468,13 +1468,21 @@ impl WindowMethods for Window { find_node_by_unique_id_in_document(&self.Document(), id.into()).and_then(Root::downcast) } - fn WebdriverFrame(&self, id: DOMString) -> Option> { - find_node_by_unique_id_in_document(&self.Document(), id.into()) - .and_then(Root::downcast::) - .map(Root::upcast::) + fn WebdriverFrame(&self, browsing_context_id: DOMString) -> Option> { + self.Document() + .iframes() + .iter() + .find(|iframe| { + iframe + .browsing_context_id() + .as_ref() + .map(BrowsingContextId::to_string) == + Some(browsing_context_id.to_string()) + }) + .and_then(|iframe| iframe.GetContentWindow()) } - fn WebdriverWindow(&self, id: DOMString) -> Option> { + fn WebdriverWindow(&self, webview_id: DOMString) -> Option> { let window_proxy = self.window_proxy.get()?; // Window must be top level browsing context. @@ -1482,10 +1490,7 @@ impl WindowMethods for Window { return None; } - let pipeline_id = window_proxy.currently_active()?; - let document = ScriptThread::find_document(pipeline_id)?; - - if document.upcast::().unique_id(pipeline_id) == id.str() { + if self.webview_id().to_string() == webview_id.str() { Some(DomRoot::from_ref(&window_proxy)) } else { None diff --git a/components/script_bindings/webidls/Window.webidl b/components/script_bindings/webidls/Window.webidl index ec95eadfab5..f62842a22b6 100644 --- a/components/script_bindings/webidls/Window.webidl +++ b/components/script_bindings/webidls/Window.webidl @@ -151,7 +151,7 @@ partial interface Window { undefined webdriverException(optional any result); undefined webdriverTimeout(); Element? webdriverElement(DOMString id); - Element? webdriverFrame(DOMString id); + WindowProxy? webdriverFrame(DOMString id); WindowProxy? webdriverWindow(DOMString id); ShadowRoot? webdriverShadowRoot(DOMString id); }; diff --git a/tests/wpt/meta/webdriver/tests/classic/execute_async_script/arguments.py.ini b/tests/wpt/meta/webdriver/tests/classic/execute_async_script/arguments.py.ini index 5f1d34e6018..57516fe7f2a 100644 --- a/tests/wpt/meta/webdriver/tests/classic/execute_async_script/arguments.py.ini +++ b/tests/wpt/meta/webdriver/tests/classic/execute_async_script/arguments.py.ini @@ -31,9 +31,3 @@ [test_no_such_window_for_window_with_invalid_value] expected: FAIL - - [test_element_reference[frame\]] - expected: FAIL - - [test_element_reference[window\]] - expected: FAIL diff --git a/tests/wpt/meta/webdriver/tests/classic/execute_script/arguments.py.ini b/tests/wpt/meta/webdriver/tests/classic/execute_script/arguments.py.ini index 5f1d34e6018..57516fe7f2a 100644 --- a/tests/wpt/meta/webdriver/tests/classic/execute_script/arguments.py.ini +++ b/tests/wpt/meta/webdriver/tests/classic/execute_script/arguments.py.ini @@ -31,9 +31,3 @@ [test_no_such_window_for_window_with_invalid_value] expected: FAIL - - [test_element_reference[frame\]] - expected: FAIL - - [test_element_reference[window\]] - expected: FAIL