Просмотр исходного кода

WebDriver: Activate the browser tab during the Switch To Window command

Timothy Flynn 2 лет назад
Родитель
Сommit
a96ba912b3

+ 1 - 0
Userland/Services/WebContent/WebDriverClient.ipc

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

+ 10 - 0
Userland/Services/WebContent/WebDriverConnection.cpp

@@ -545,6 +545,16 @@ Messages::WebDriverClient::CloseWindowResponse WebDriverConnection::close_window
     return JsonValue {};
 }
 
+// 11.3 Switch to Window, https://w3c.github.io/webdriver/#dfn-switch-to-window
+Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to_window()
+{
+    // 5. Update any implementation-specific state that would result from the user selecting the current
+    //    browsing context for interaction, without altering OS-level focus.
+    m_page_client.page_did_request_activate_tab();
+
+    return JsonValue {};
+}
+
 // 11.5 New Window, https://w3c.github.io/webdriver/#dfn-new-window
 Messages::WebDriverClient::NewWindowResponse WebDriverConnection::new_window(JsonValue const&)
 {

+ 1 - 0
Userland/Services/WebContent/WebDriverConnection.h

@@ -54,6 +54,7 @@ private:
     virtual Messages::WebDriverClient::GetTitleResponse get_title() override;
     virtual Messages::WebDriverClient::GetWindowHandleResponse get_window_handle() override;
     virtual Messages::WebDriverClient::CloseWindowResponse close_window() override;
+    virtual Messages::WebDriverClient::SwitchToWindowResponse switch_to_window() override;
     virtual Messages::WebDriverClient::NewWindowResponse new_window(JsonValue const& payload) override;
     virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override;
     virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override;

+ 3 - 2
Userland/Services/WebDriver/Session.cpp

@@ -144,8 +144,9 @@ Web::WebDriver::Response Session::switch_to_window(StringView handle)
     else
         return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found");
 
-    // FIXME: 5. Update any implementation-specific state that would result from the user selecting the current
-    //          browsing context for interaction, without altering OS-level focus.
+    // 5. Update any implementation-specific state that would result from the user selecting the current
+    //    browsing context for interaction, without altering OS-level focus.
+    TRY(web_content_connection().switch_to_window());
 
     // 6. Return success with data null.
     return JsonValue {};