WebDriver: Move GET /session/{session id}/window impl into Session

This commit is contained in:
Linus Groh 2022-10-19 19:39:54 +02:00
parent 0064d2e8c8
commit 24ee5a2202
Notes: sideshowbarker 2024-07-17 05:20:51 +09:00
3 changed files with 16 additions and 7 deletions

View file

@ -533,13 +533,9 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_window_handle(Vector<StringView
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = session->get_window_object();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
// 2. Return success with data being the window handle associated with the current top-level browsing context.
return make_json_value(session->current_window_handle());
// NOTE: Spec steps handled in Session::get_title().
auto result = TRY(session->get_window_handle());
return make_json_value(result);
}
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window

View file

@ -235,6 +235,18 @@ ErrorOr<JsonValue, HttpError> Session::get_title()
return JsonValue(m_browser_connection->get_title());
}
// 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle
ErrorOr<JsonValue, HttpError> Session::get_window_handle()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = get_window_object();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
// 2. Return success with data being the window handle associated with the current top-level browsing context.
return m_current_window_handle;
}
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
ErrorOr<void, Variant<HttpError, Error>> Session::close_window()
{

View file

@ -47,6 +47,7 @@ public:
ErrorOr<JsonValue, HttpError> forward();
ErrorOr<JsonValue, HttpError> refresh();
ErrorOr<JsonValue, HttpError> get_title();
ErrorOr<JsonValue, HttpError> get_window_handle();
ErrorOr<JsonValue, HttpError> find_element(JsonValue const& payload);
ErrorOr<JsonValue, HttpError> find_elements(JsonValue const& payload);
ErrorOr<JsonValue, HttpError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);