1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

WebDriver+Browser: Implement GET /session/{id}/window/rect

This commit is contained in:
Timothy Flynn 2022-11-02 10:19:58 -04:00 committed by Linus Groh
parent 7561308af1
commit dac91c5790
8 changed files with 49 additions and 1 deletions

View file

@ -14,6 +14,7 @@
#include <LibCore/LocalServer.h>
#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibGfx/Rect.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <unistd.h>
@ -281,6 +282,29 @@ ErrorOr<JsonValue, WebDriverError> Session::get_window_handles() const
return handles;
}
static JsonObject serialize_window_rect(Gfx::IntRect const& rect)
{
JsonObject serialized_rect = {};
serialized_rect.set("x", rect.x());
serialized_rect.set("y", rect.y());
serialized_rect.set("width", rect.width());
serialized_rect.set("height", rect.height());
return serialized_rect;
}
// 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect
ErrorOr<JsonValue, WebDriverError> Session::get_window_rect()
{
// 1. 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: 2. Handle any user prompts and return its value if it is an error.
// 3. 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)
{