From 4c598037a5ea4f6848afd82e447bdc3a7a902b19 Mon Sep 17 00:00:00 2001 From: batu_hoang <55729155+longvatrong111@users.noreply.github.com> Date: Fri, 13 Jun 2025 16:32:59 +0800 Subject: [PATCH] Verify `webview` still open in webdriver switch frame command (#37411) SwitchToParentFrame webdriver commands do not handle the case where the current top-level browsing context has been closed. Tests: `./tests/wpt/tests/webdriver/tests/classic/switch_to_parent_frame/switch.py` `./tests/wpt/tests/webdriver/tests/classic/switch_to_frame/switch.py` Signed-off-by: batu_hoang --- components/webdriver_server/lib.rs | 7 +++++++ .../tests/classic/switch_to_frame/switch.py.ini | 9 --------- .../tests/classic/switch_to_parent_frame/switch.py.ini | 3 --- 3 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 tests/wpt/meta/webdriver/tests/classic/switch_to_parent_frame/switch.py.ini diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 0b71e69532d..c2df2d100a8 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -1043,6 +1043,8 @@ impl Handler { &mut self, parameters: &SwitchToFrameParameters, ) -> WebDriverResult { + self.verify_top_level_browsing_context_is_open(self.session()?.webview_id)?; + use webdriver::common::FrameId; let frame_id = match parameters.id { FrameId::Top => { @@ -1058,6 +1060,11 @@ impl Handler { } fn handle_switch_to_parent_frame(&mut self) -> WebDriverResult { + let webview_id = self.session()?.webview_id; + self.verify_top_level_browsing_context_is_open(webview_id)?; + if self.session()?.browsing_context_id == webview_id { + return Ok(WebDriverResponse::Void); + } self.switch_to_frame(WebDriverFrameId::Parent) } diff --git a/tests/wpt/meta/webdriver/tests/classic/switch_to_frame/switch.py.ini b/tests/wpt/meta/webdriver/tests/classic/switch_to_frame/switch.py.ini index b26241b424d..ca864f6b6c5 100644 --- a/tests/wpt/meta/webdriver/tests/classic/switch_to_frame/switch.py.ini +++ b/tests/wpt/meta/webdriver/tests/classic/switch_to_frame/switch.py.ini @@ -1,15 +1,6 @@ [switch.py] - [test_no_top_browsing_context[None\]] - expected: FAIL - - [test_no_top_browsing_context[0\]] - expected: FAIL - [test_no_browsing_context[0\]] expected: FAIL [test_no_browsing_context[id2\]] expected: FAIL - - [test_no_browsing_context_when_already_top_level] - expected: FAIL diff --git a/tests/wpt/meta/webdriver/tests/classic/switch_to_parent_frame/switch.py.ini b/tests/wpt/meta/webdriver/tests/classic/switch_to_parent_frame/switch.py.ini deleted file mode 100644 index 352421f84c1..00000000000 --- a/tests/wpt/meta/webdriver/tests/classic/switch_to_parent_frame/switch.py.ini +++ /dev/null @@ -1,3 +0,0 @@ -[switch.py] - [test_switch_from_top_level] - expected: FAIL