WebContent+WebDriver: Update the current BC when switching windows

We had only implemented this step in the WebDriver process, but we need
to update the remote WebContent process as well.
This commit is contained in:
Timothy Flynn 2024-09-14 13:02:44 -04:00 committed by Tim Ledbetter
parent 4a6d0e0f90
commit 5fc51b2ff9
Notes: github-actions[bot] 2024-09-14 23:57:32 +00:00
4 changed files with 23 additions and 4 deletions

View file

@ -17,7 +17,7 @@ endpoint WebDriverClient {
get_title() => (Web::WebDriver::Response response) get_title() => (Web::WebDriver::Response response)
get_window_handle() => (String handle) get_window_handle() => (String handle)
close_window() => (Web::WebDriver::Response response) close_window() => (Web::WebDriver::Response response)
switch_to_window() => (Web::WebDriver::Response response) switch_to_window(String handle) => (Web::WebDriver::Response response)
new_window(JsonValue payload) => (Web::WebDriver::Response response) new_window(JsonValue payload) => (Web::WebDriver::Response response)
switch_to_frame(JsonValue payload) => (Web::WebDriver::Response response) switch_to_frame(JsonValue payload) => (Web::WebDriver::Response response)
switch_to_parent_frame(JsonValue payload) => (Web::WebDriver::Response response) switch_to_parent_frame(JsonValue payload) => (Web::WebDriver::Response response)

View file

@ -523,8 +523,27 @@ Messages::WebDriverClient::CloseWindowResponse WebDriverConnection::close_window
} }
// 11.3 Switch to Window, https://w3c.github.io/webdriver/#dfn-switch-to-window // 11.3 Switch to Window, https://w3c.github.io/webdriver/#dfn-switch-to-window
Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to_window() Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to_window(String const& handle)
{ {
// 4. If handle is equal to the associated window handle for some top-level browsing context in the
// current session, let context be the that browsing context, and set the current top-level
// browsing context with context.
// Otherwise, return error with error code no such window.
bool found_matching_context = false;
current_top_level_browsing_context()->for_each_in_inclusive_subtree([&](Web::HTML::BrowsingContext& context) {
if (handle != context.top_level_traversable()->window_handle())
return Web::TraversalDecision::Continue;
m_current_browsing_context = context;
found_matching_context = true;
return Web::TraversalDecision::Break;
});
if (!found_matching_context)
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found");
// 5. Update any implementation-specific state that would result from the user selecting the current // 5. Update any implementation-specific state that would result from the user selecting the current
// browsing context for interaction, without altering OS-level focus. // browsing context for interaction, without altering OS-level focus.
current_browsing_context().page().client().page_did_request_activate_tab(); current_browsing_context().page().client().page_did_request_activate_tab();

View file

@ -54,7 +54,7 @@ private:
virtual Messages::WebDriverClient::GetTitleResponse get_title() override; virtual Messages::WebDriverClient::GetTitleResponse get_title() override;
virtual Messages::WebDriverClient::GetWindowHandleResponse get_window_handle() override; virtual Messages::WebDriverClient::GetWindowHandleResponse get_window_handle() override;
virtual Messages::WebDriverClient::CloseWindowResponse close_window() override; virtual Messages::WebDriverClient::CloseWindowResponse close_window() override;
virtual Messages::WebDriverClient::SwitchToWindowResponse switch_to_window() override; virtual Messages::WebDriverClient::SwitchToWindowResponse switch_to_window(String const& handle) override;
virtual Messages::WebDriverClient::NewWindowResponse new_window(JsonValue const& payload) override; virtual Messages::WebDriverClient::NewWindowResponse new_window(JsonValue const& payload) override;
virtual Messages::WebDriverClient::SwitchToFrameResponse switch_to_frame(JsonValue const& payload) override; virtual Messages::WebDriverClient::SwitchToFrameResponse switch_to_frame(JsonValue const& payload) override;
virtual Messages::WebDriverClient::SwitchToParentFrameResponse switch_to_parent_frame(JsonValue const& payload) override; virtual Messages::WebDriverClient::SwitchToParentFrameResponse switch_to_parent_frame(JsonValue const& payload) override;

View file

@ -148,7 +148,7 @@ Web::WebDriver::Response Session::switch_to_window(StringView handle)
// 5. Update any implementation-specific state that would result from the user selecting the current // 5. Update any implementation-specific state that would result from the user selecting the current
// browsing context for interaction, without altering OS-level focus. // browsing context for interaction, without altering OS-level focus.
TRY(web_content_connection().switch_to_window()); TRY(web_content_connection().switch_to_window(m_current_window_handle));
// 6. Return success with data null. // 6. Return success with data null.
return JsonValue {}; return JsonValue {};