webdriver: Focus when "switch to window" (#38889)

Add logic that was accidentally removed in #38745. Otherwise it is very
weird when using webdriver as a human, as we still stays on the original
tab.

Testing: ~this should not affect any test. Even if the tab is not
"visible" previously, all programmatic interaction works fine.~ Stably
pass `test_history_pushstate` in `back.py` and `forward.py`.

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
Euclid Ye 2025-08-24 21:36:58 +08:00 committed by GitHub
parent 71db9494bb
commit 0b5bcfbf17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 7 deletions

View file

@ -1067,7 +1067,7 @@ impl Handler {
/// <https://w3c.github.io/webdriver/#get-window-handles>
fn handle_window_handles(&mut self) -> WebDriverResult<WebDriverResponse> {
let mut handles = self.get_window_handles();
handles.sort();
handles.sort_unstable();
Ok(WebDriverResponse::Generic(ValueResponse(
serde_json::to_value(handles)?,
@ -1266,6 +1266,12 @@ impl Handler {
let session = self.session_mut()?;
session.set_webview_id(webview_id);
session.set_browsing_context_id(BrowsingContextId::from(webview_id));
// Step 5. Update any implementation-specific state that would result
// from the user selecting session's current browsing context for interaction,
// without altering OS-level focus.
self.focus_webview(webview_id)?;
Ok(WebDriverResponse::Void)
}

View file

@ -7,6 +7,3 @@
[test_seen_nodes[https coop\]]
expected: FAIL
[test_history_pushstate]
expected: FAIL

View file

@ -13,6 +13,3 @@
[test_removed_iframe]
expected: FAIL
[test_history_pushstate]
expected: FAIL