From 11d0489fa3b0fe5d904ca896089eaabe7ad6681d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 2 Nov 2022 10:01:51 -0400 Subject: WebDriver+Browser: Implement `POST /session/{id}/window/minimize` --- Userland/Applications/Browser/WebDriverConnection.cpp | 7 +++++++ Userland/Applications/Browser/WebDriverConnection.h | 1 + .../Applications/Browser/WebDriverSessionClient.ipc | 1 + Userland/Services/WebDriver/Client.cpp | 11 +++++++++++ Userland/Services/WebDriver/Client.h | 1 + Userland/Services/WebDriver/Session.cpp | 18 ++++++++++++++++++ Userland/Services/WebDriver/Session.h | 1 + 7 files changed, 40 insertions(+) diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 3c286ce927..2e77ba0e80 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -109,6 +109,13 @@ void WebDriverConnection::maximize_window() browser_window->set_maximized(true); } +void WebDriverConnection::minimize_window() +{ + dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: minimize_window"); + if (auto browser_window = m_browser_window.strong_ref()) + browser_window->set_minimized(true); +} + Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies() { dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies"); diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 89cae679a2..658000761f 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -48,6 +48,7 @@ public: virtual void set_window_size(Gfx::IntSize const&) override; virtual void set_window_position(Gfx::IntPoint const&) override; virtual void maximize_window() override; + virtual void minimize_window() override; virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override; virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override; virtual void add_cookie(Web::Cookie::ParsedCookie const&) override; diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 44a1868ee5..0cbd4f761f 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -20,6 +20,7 @@ endpoint WebDriverSessionClient { set_window_size(Gfx::IntSize size) =| set_window_position(Gfx::IntPoint position) =| maximize_window() =| + minimize_window() =| get_all_cookies() => (Vector cookies) get_named_cookie(String name) => (Optional cookie) add_cookie(Web::Cookie::ParsedCookie cookie) =| diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 0ba89fecff..fd6a1e223c 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -39,6 +39,7 @@ Vector Client::s_routes = { { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "window", "rect" }, &Client::handle_get_window_rect }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "rect" }, &Client::handle_set_window_rect }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "maximize" }, &Client::handle_maximize_window }, + { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "minimize" }, &Client::handle_minimize_window }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element" }, &Client::handle_find_element }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "elements" }, &Client::handle_find_elements }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element", ":element_id", "element" }, &Client::handle_find_element_from_element }, @@ -576,6 +577,16 @@ ErrorOr Client::handle_maximize_window(Vector Client::handle_minimize_window(Vector const& parameters, JsonValue const&) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//window/minimize"); + auto* session = TRY(find_session_with_id(parameters[0])); + auto result = TRY(session->minimize_window()); + return make_json_value(result); +} + // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element // POST /session/{session id}/element ErrorOr Client::handle_find_element(Vector const& parameters, JsonValue const& payload) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index 35270c4640..86508a4c0f 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -64,6 +64,7 @@ private: ErrorOr handle_get_window_rect(Vector const&, JsonValue const& payload); ErrorOr handle_set_window_rect(Vector const&, JsonValue const& payload); ErrorOr handle_maximize_window(Vector const&, JsonValue const& payload); + ErrorOr handle_minimize_window(Vector const&, JsonValue const& payload); ErrorOr handle_find_element(Vector const&, JsonValue const& payload); ErrorOr handle_find_elements(Vector const&, JsonValue const& payload); ErrorOr handle_find_element_from_element(Vector const&, JsonValue const& payload); diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 2c7c10e98c..17e6b25046 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -401,6 +401,24 @@ ErrorOr Session::maximize_window() return serialize_window_rect(m_browser_connection->get_window_rect()); } +// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window +ErrorOr Session::minimize_window() +{ + // 1. If the remote end does not support the Minimize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation. + + // 2. If the current top-level browsing context is no longer open, return error with error code no such window. + TRY(check_for_open_top_level_browsing_context_or_return_error()); + + // FIXME: 3. Handle any user prompts and return its value if it is an error. + // FIXME: 4. Fully exit fullscreen. + + // 5. Iconify the window. + m_browser_connection->async_minimize_window(); + + // 6. Return success with data set to the WindowRect object for the current top-level browsing context. + return serialize_window_rect(m_browser_connection->get_window_rect()); +} + // https://w3c.github.io/webdriver/#dfn-get-or-create-a-web-element-reference static String get_or_create_a_web_element_reference(Session::LocalElement const& element) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 8640cdbc0f..a63abdfbcd 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -53,6 +53,7 @@ public: ErrorOr get_window_rect(); ErrorOr set_window_rect(JsonValue const& payload); ErrorOr maximize_window(); + ErrorOr minimize_window(); ErrorOr find_element(JsonValue const& payload); ErrorOr find_elements(JsonValue const& payload); ErrorOr find_element_from_element(JsonValue const& payload, StringView parameter_element_id); -- cgit v1.2.3