mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:47:35 +00:00
WebDriver+Browser: Implement POST /session/{id}/window/maximize
This commit is contained in:
parent
174248678e
commit
89b2ff72f7
7 changed files with 43 additions and 0 deletions
|
@ -102,6 +102,13 @@ void WebDriverConnection::set_window_position(Gfx::IntPoint const& position)
|
|||
browser_window->move_to(position);
|
||||
}
|
||||
|
||||
void WebDriverConnection::maximize_window()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: maximize_window");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
browser_window->set_maximized(true);
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
virtual void restore_window() override;
|
||||
virtual void set_window_size(Gfx::IntSize const&) override;
|
||||
virtual void set_window_position(Gfx::IntPoint const&) override;
|
||||
virtual void maximize_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;
|
||||
|
|
|
@ -19,6 +19,7 @@ endpoint WebDriverSessionClient {
|
|||
restore_window() =|
|
||||
set_window_size(Gfx::IntSize size) =|
|
||||
set_window_position(Gfx::IntPoint position) =|
|
||||
maximize_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) =|
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue