summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-11-02 10:01:51 -0400
committerLinus Groh <mail@linusgroh.de>2022-11-02 15:41:19 +0000
commit11d0489fa3b0fe5d904ca896089eaabe7ad6681d (patch)
tree3d69e5f98975bd307f3dd0c757f1351fab45ef34 /Userland
parent0d5209cee67fa29aac7bb92529aa465b6748de19 (diff)
downloadserenity-11d0489fa3b0fe5d904ca896089eaabe7ad6681d.zip
WebDriver+Browser: Implement `POST /session/{id}/window/minimize`
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Browser/WebDriverConnection.cpp7
-rw-r--r--Userland/Applications/Browser/WebDriverConnection.h1
-rw-r--r--Userland/Applications/Browser/WebDriverSessionClient.ipc1
-rw-r--r--Userland/Services/WebDriver/Client.cpp11
-rw-r--r--Userland/Services/WebDriver/Client.h1
-rw-r--r--Userland/Services/WebDriver/Session.cpp18
-rw-r--r--Userland/Services/WebDriver/Session.h1
7 files changed, 40 insertions, 0 deletions
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<Web::Cookie::Cookie> cookies)
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> 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::Route> 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<JsonValue, WebDriverError> Client::handle_maximize_window(Vector<StringV
return make_json_value(result);
}
+// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window
+// POST /session/{session id}/window/minimize
+ErrorOr<JsonValue, WebDriverError> Client::handle_minimize_window(Vector<StringView> const& parameters, JsonValue const&)
+{
+ dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/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<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 35270c4640..86508a4c0f 100644
--- a/Userland/Services/WebDriver/Client.h
+++ b/Userland/Services/WebDriver/Client.h
@@ -64,6 +64,7 @@ private:
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_minimize_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 2c7c10e98c..17e6b25046 100644
--- a/Userland/Services/WebDriver/Session.cpp
+++ b/Userland/Services/WebDriver/Session.cpp
@@ -401,6 +401,24 @@ ErrorOr<JsonValue, WebDriverError> 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<JsonValue, WebDriverError> 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<JsonValue, WebDriverError> get_window_rect();
ErrorOr<JsonValue, WebDriverError> set_window_rect(JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> maximize_window();
+ ErrorOr<JsonValue, WebDriverError> minimize_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);