Bläddra i källkod

WebDriver+Browser: Implement `POST /session/{id}/window/minimize`

Timothy Flynn 2 år sedan
förälder
incheckning
11d0489fa3

+ 7 - 0
Userland/Applications/Browser/WebDriverConnection.cpp

@@ -109,6 +109,13 @@ void WebDriverConnection::maximize_window()
         browser_window->set_maximized(true);
         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()
 Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
 {
 {
     dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");
     dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");

+ 1 - 0
Userland/Applications/Browser/WebDriverConnection.h

@@ -48,6 +48,7 @@ public:
     virtual void set_window_size(Gfx::IntSize const&) override;
     virtual void set_window_size(Gfx::IntSize const&) override;
     virtual void set_window_position(Gfx::IntPoint const&) override;
     virtual void set_window_position(Gfx::IntPoint const&) override;
     virtual void maximize_window() override;
     virtual void maximize_window() override;
+    virtual void minimize_window() override;
     virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
     virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
     virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
     virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
     virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
     virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;

+ 1 - 0
Userland/Applications/Browser/WebDriverSessionClient.ipc

@@ -20,6 +20,7 @@ endpoint WebDriverSessionClient {
     set_window_size(Gfx::IntSize size) =|
     set_window_size(Gfx::IntSize size) =|
     set_window_position(Gfx::IntPoint position) =|
     set_window_position(Gfx::IntPoint position) =|
     maximize_window() =|
     maximize_window() =|
+    minimize_window() =|
     get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
     get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
     get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
     get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
     add_cookie(Web::Cookie::ParsedCookie cookie) =|
     add_cookie(Web::Cookie::ParsedCookie cookie) =|

+ 11 - 0
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::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", "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", "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", "element" }, &Client::handle_find_element },
     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "elements" }, &Client::handle_find_elements },
     { 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 },
     { 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);
     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
 // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
 // POST /session/{session id}/element
 // POST /session/{session id}/element
 ErrorOr<JsonValue, WebDriverError> Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload)
 ErrorOr<JsonValue, WebDriverError> Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload)

+ 1 - 0
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_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_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_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_element(Vector<StringView> const&, JsonValue const& payload);
     ErrorOr<JsonValue, WebDriverError> handle_find_elements(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);
     ErrorOr<JsonValue, WebDriverError> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);

+ 18 - 0
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());
     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
 // 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)
 static String get_or_create_a_web_element_reference(Session::LocalElement const& element)
 {
 {

+ 1 - 0
Userland/Services/WebDriver/Session.h

@@ -53,6 +53,7 @@ public:
     ErrorOr<JsonValue, WebDriverError> get_window_rect();
     ErrorOr<JsonValue, WebDriverError> get_window_rect();
     ErrorOr<JsonValue, WebDriverError> set_window_rect(JsonValue const& payload);
     ErrorOr<JsonValue, WebDriverError> set_window_rect(JsonValue const& payload);
     ErrorOr<JsonValue, WebDriverError> maximize_window();
     ErrorOr<JsonValue, WebDriverError> maximize_window();
+    ErrorOr<JsonValue, WebDriverError> minimize_window();
     ErrorOr<JsonValue, WebDriverError> find_element(JsonValue const& payload);
     ErrorOr<JsonValue, WebDriverError> find_element(JsonValue const& payload);
     ErrorOr<JsonValue, WebDriverError> find_elements(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);
     ErrorOr<JsonValue, WebDriverError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);