diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-02 09:44:43 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-02 15:41:19 +0000 |
commit | 89b2ff72f7b63ec378595f5931ff1166a512c792 (patch) | |
tree | 7d5044d44ae38c08e6208af6c159f1f26aeedf9a /Userland/Services/WebDriver | |
parent | 174248678e63547e4f52d36cf911ac0e1995c6a4 (diff) | |
download | serenity-89b2ff72f7b63ec378595f5931ff1166a512c792.zip |
WebDriver+Browser: Implement `POST /session/{id}/window/maximize`
Diffstat (limited to 'Userland/Services/WebDriver')
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 11 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.cpp | 21 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.h | 1 |
4 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 625c83c4f4..0ba89fecff 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -38,6 +38,7 @@ Vector<Client::Route> Client::s_routes = { { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "window", "handles" }, &Client::handle_get_window_handles }, { 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", "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 }, @@ -565,6 +566,16 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_set_window_rect(Vector<StringV return make_json_value(result); } +// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window +// POST /session/{session id}/window/maximize +ErrorOr<JsonValue, WebDriverError> Client::handle_maximize_window(Vector<StringView> const& parameters, JsonValue const&) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/maximize"); + auto* session = TRY(find_session_with_id(parameters[0])); + auto result = TRY(session->maximize_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<JsonValue, WebDriverError> Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index 23cf1bcceb..35270c4640 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -63,6 +63,7 @@ private: ErrorOr<JsonValue, WebDriverError> handle_get_window_handles(Vector<StringView> const&, JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> handle_get_window_rect(Vector<StringView> const&, JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> handle_set_window_rect(Vector<StringView> const&, JsonValue const& payload); + ErrorOr<JsonValue, WebDriverError> handle_maximize_window(Vector<StringView> const&, JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> handle_find_element(Vector<StringView> const&, JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> handle_find_elements(Vector<StringView> const&, JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload); diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 957b3b6167..2c7c10e98c 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -380,6 +380,27 @@ ErrorOr<JsonValue, WebDriverError> Session::set_window_rect(JsonValue const& pay return serialize_window_rect(m_browser_connection->get_window_rect()); } +// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window +ErrorOr<JsonValue, WebDriverError> Session::maximize_window() +{ + // 1. If the remote end does not support the Maximize 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. Restore the window. + m_browser_connection->async_restore_window(); + + // 6. Maximize the window of the current top-level browsing context. + m_browser_connection->async_maximize_window(); + + // 7. 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 4967d1087b..8640cdbc0f 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -52,6 +52,7 @@ public: ErrorOr<JsonValue, WebDriverError> get_window_handles() const; ErrorOr<JsonValue, WebDriverError> get_window_rect(); ErrorOr<JsonValue, WebDriverError> set_window_rect(JsonValue const& payload); + ErrorOr<JsonValue, WebDriverError> maximize_window(); ErrorOr<JsonValue, WebDriverError> find_element(JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> find_elements(JsonValue const& payload); ErrorOr<JsonValue, WebDriverError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id); |