diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index da87a6c0db..5ed7e06d14 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -440,6 +440,7 @@ set(SOURCES WebAssembly/WebAssemblyTablePrototype.cpp WebDriver/Error.cpp WebDriver/ExecuteScript.cpp + WebDriver/Response.cpp WebGL/WebGLContextAttributes.cpp WebGL/WebGLContextEvent.cpp WebGL/WebGLRenderingContext.cpp diff --git a/Userland/Libraries/LibWeb/WebDriver/Response.cpp b/Userland/Libraries/LibWeb/WebDriver/Response.cpp new file mode 100644 index 0000000000..c8102d35a2 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebDriver/Response.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2022, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +enum class ResponseType : u8 { + Success, + Error, +}; + +namespace Web::WebDriver { + +Response::Response(JsonValue&& value) + : m_value_or_error(move(value)) +{ +} + +Response::Response(Error&& error) + : m_value_or_error(move(error)) +{ +} + +} + +bool IPC::encode(Encoder& encoder, Web::WebDriver::Response const& response) +{ + response.visit( + [](Empty) { VERIFY_NOT_REACHED(); }, + [&](JsonValue const& value) { + encoder << ResponseType::Success; + encoder << value; + }, + [&](Web::WebDriver::Error const& error) { + encoder << ResponseType::Error; + encoder << error.http_status; + encoder << error.error; + encoder << error.message; + encoder << error.data; + }); + + return true; +} + +ErrorOr IPC::decode(Decoder& decoder, Web::WebDriver::Response& response) +{ + ResponseType type {}; + TRY(decoder.decode(type)); + + switch (type) { + case ResponseType::Success: { + JsonValue value; + TRY(decoder.decode(value)); + + response = move(value); + break; + } + + case ResponseType::Error: { + Web::WebDriver::Error error {}; + TRY(decoder.decode(error.http_status)); + TRY(decoder.decode(error.error)); + TRY(decoder.decode(error.message)); + TRY(decoder.decode(error.data)); + + response = move(error); + break; + } + } + + return {}; +} diff --git a/Userland/Libraries/LibWeb/WebDriver/Response.h b/Userland/Libraries/LibWeb/WebDriver/Response.h new file mode 100644 index 0000000000..7d7e5c4da6 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebDriver/Response.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::WebDriver { + +// FIXME: Ideally, this could be `using Response = ErrorOr`, but that won't be +// default-constructible, which is a requirement for the generated IPC. +struct Response { + Response() = default; + Response(JsonValue&&); + Response(Error&&); + + JsonValue& value() { return m_value_or_error.template get(); } + JsonValue const& value() const { return m_value_or_error.template get(); } + + Error& error() { return m_value_or_error.template get(); } + Error const& error() const { return m_value_or_error.template get(); } + + bool is_error() const { return m_value_or_error.template has(); } + + JsonValue release_value() { return move(value()); } + Error release_error() { return move(error()); } + + template + decltype(auto) visit(Visitors&&... visitors) const + { + return m_value_or_error.visit(forward(visitors)...); + } + +private: + // Note: Empty is only a possible state until the Response has been decoded by IPC. + Variant m_value_or_error; +}; + +} + +namespace IPC { + +bool encode(Encoder&, Web::WebDriver::Response const&); +ErrorOr decode(Decoder&, Web::WebDriver::Response&); + +} diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index a318f32b60..1a614f4919 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -352,7 +352,7 @@ JsonValue Client::make_json_value(JsonValue const& value) // 8.1 New Session, https://w3c.github.io/webdriver/#dfn-new-sessions // POST /session -ErrorOr Client::handle_new_session(Vector const&, JsonValue const&) +Web::WebDriver::Response Client::handle_new_session(Vector const&, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session"); @@ -418,7 +418,7 @@ ErrorOr Client::handle_new_session(Vector Client::handle_delete_session(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_delete_session(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/"); @@ -435,7 +435,7 @@ ErrorOr Client::handle_delete_session(Vector Client::handle_get_status(Vector const&, JsonValue const&) +Web::WebDriver::Response Client::handle_get_status(Vector const&, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /status"); @@ -450,12 +450,12 @@ ErrorOr Client::handle_get_status(Vector Client::handle_get_timeouts(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_timeouts(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//timeouts"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -465,7 +465,7 @@ ErrorOr Client::handle_get_timeouts(Vector Client::handle_set_timeouts(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_set_timeouts(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//timeouts"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -475,7 +475,7 @@ ErrorOr Client::handle_set_timeouts(Vector Client::handle_navigate_to(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_navigate_to(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//url"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -485,7 +485,7 @@ ErrorOr Client::handle_navigate_to(Vector Client::handle_get_current_url(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_current_url(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//url"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -495,7 +495,7 @@ ErrorOr Client::handle_get_current_url(Vector< // 10.3 Back, https://w3c.github.io/webdriver/#dfn-back // POST /session/{session id}/back -ErrorOr Client::handle_back(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_back(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//back"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -505,7 +505,7 @@ ErrorOr Client::handle_back(Vector // 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward // POST /session/{session id}/forward -ErrorOr Client::handle_forward(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_forward(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//forward"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -515,7 +515,7 @@ ErrorOr Client::handle_forward(Vector Client::handle_refresh(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_refresh(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//refresh"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -525,7 +525,7 @@ ErrorOr Client::handle_refresh(Vector Client::handle_get_title(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_title(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//title"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -535,7 +535,7 @@ ErrorOr Client::handle_get_title(Vector Client::handle_get_window_handle(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_window_handle(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//window"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -545,7 +545,7 @@ ErrorOr Client::handle_get_window_handle(Vecto // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window // DELETE /session/{session id}/window -ErrorOr Client::handle_close_window(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_close_window(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session//window"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -555,7 +555,7 @@ ErrorOr Client::handle_close_window(Vector Client::handle_get_window_handles(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_window_handles(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//window/handles"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -565,7 +565,7 @@ ErrorOr Client::handle_get_window_handles(Vect // 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect // GET /session/{session id}/window/rect -ErrorOr Client::handle_get_window_rect(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_window_rect(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//window/rect"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -575,7 +575,7 @@ ErrorOr Client::handle_get_window_rect(Vector< // 11.8.2 Set Window Rect, https://w3c.github.io/webdriver/#dfn-set-window-rect // POST /session/{session id}/window/rect -ErrorOr Client::handle_set_window_rect(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_set_window_rect(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//window/rect"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -585,7 +585,7 @@ ErrorOr Client::handle_set_window_rect(Vector< // 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window // POST /session/{session id}/window/maximize -ErrorOr Client::handle_maximize_window(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_maximize_window(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//window/maximize"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -595,7 +595,7 @@ ErrorOr Client::handle_maximize_window(Vector< // 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window // POST /session/{session id}/window/minimize -ErrorOr Client::handle_minimize_window(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_minimize_window(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//window/minimize"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -605,7 +605,7 @@ ErrorOr Client::handle_minimize_window(Vector< // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element // POST /session/{session id}/element -ErrorOr Client::handle_find_element(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_find_element(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//element"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -615,7 +615,7 @@ ErrorOr Client::handle_find_element(Vector Client::handle_find_elements(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_find_elements(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//elements"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -625,7 +625,7 @@ ErrorOr Client::handle_find_elements(Vector Client::handle_find_element_from_element(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_find_element_from_element(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//element//element"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -635,7 +635,7 @@ ErrorOr Client::handle_find_element_from_eleme // 12.3.5 Find Elements From Element, https://w3c.github.io/webdriver/#dfn-find-elements-from-element // POST /session/{session id}/element/{element id}/elements -ErrorOr Client::handle_find_elements_from_element(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_find_elements_from_element(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//element//elements"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -645,7 +645,7 @@ ErrorOr Client::handle_find_elements_from_elem // 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected // GET /session/{session id}/element/{element id}/selected -ErrorOr Client::handle_is_element_selected(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_is_element_selected(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//selected"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -655,7 +655,7 @@ ErrorOr Client::handle_is_element_selected(Vec // 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute // GET /session/{session id}/element/{element id}/attribute/{name} -ErrorOr Client::handle_get_element_attribute(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_attribute(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//attribute/"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -665,7 +665,7 @@ ErrorOr Client::handle_get_element_attribute(V // 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property // GET /session/{session id}/element/{element id}/property/{name} -ErrorOr Client::handle_get_element_property(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_property(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//property/"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -675,7 +675,7 @@ ErrorOr Client::handle_get_element_property(Ve // 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value // GET /session/{session id}/element/{element id}/css/{property name} -ErrorOr Client::handle_get_element_css_value(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_css_value(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//css/"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -685,7 +685,7 @@ ErrorOr Client::handle_get_element_css_value(V // 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text // GET /session/{session id}/element/{element id}/text -ErrorOr Client::handle_get_element_text(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_text(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//text"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -695,7 +695,7 @@ ErrorOr Client::handle_get_element_text(Vector // 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name // GET /session/{session id}/element/{element id}/name -ErrorOr Client::handle_get_element_tag_name(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_tag_name(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//name"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -705,7 +705,7 @@ ErrorOr Client::handle_get_element_tag_name(Ve // 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect // GET /session/{session id}/element/{element id}/rect -ErrorOr Client::handle_get_element_rect(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_element_rect(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//rect"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -715,7 +715,7 @@ ErrorOr Client::handle_get_element_rect(Vector // 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled // GET /session/{session id}/element/{element id}/enabled -ErrorOr Client::handle_is_element_enabled(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_is_element_enabled(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//enabled"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -725,7 +725,7 @@ ErrorOr Client::handle_is_element_enabled(Vect // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source // GET /session/{session id}/source -ErrorOr Client::handle_get_source(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_source(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//source"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -735,7 +735,7 @@ ErrorOr Client::handle_get_source(Vector Client::handle_execute_script(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_execute_script(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//execute/sync"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -745,7 +745,7 @@ ErrorOr Client::handle_execute_script(Vector Client::handle_execute_async_script(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_execute_async_script(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//execute/async"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -755,7 +755,7 @@ ErrorOr Client::handle_execute_async_script(Ve // 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies // GET /session/{session id}/cookie -ErrorOr Client::handle_get_all_cookies(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_all_cookies(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//cookie"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -765,7 +765,7 @@ ErrorOr Client::handle_get_all_cookies(Vector< // 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie // GET /session/{session id}/cookie/{name} -ErrorOr Client::handle_get_named_cookie(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_get_named_cookie(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//cookie/"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -775,7 +775,7 @@ ErrorOr Client::handle_get_named_cookie(Vector // 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie // POST /session/{session id}/cookie -ErrorOr Client::handle_add_cookie(Vector const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_add_cookie(Vector const& parameters, JsonValue const& payload) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session//cookie"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -785,7 +785,7 @@ ErrorOr Client::handle_add_cookie(Vector Client::handle_delete_cookie(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_delete_cookie(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session//cookie/"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -795,7 +795,7 @@ ErrorOr Client::handle_delete_cookie(Vector Client::handle_delete_all_cookies(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_delete_all_cookies(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session//cookie"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -805,7 +805,7 @@ ErrorOr Client::handle_delete_all_cookies(Vect // 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot // GET /session/{session id}/screenshot -ErrorOr Client::handle_take_screenshot(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_take_screenshot(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//screenshot"); auto* session = TRY(find_session_with_id(parameters[0])); @@ -815,7 +815,7 @@ ErrorOr Client::handle_take_screenshot(Vector< // 17.2 Take Element Screenshot, https://w3c.github.io/webdriver/#dfn-take-element-screenshot // GET /session/{session id}/element/{element id}/screenshot -ErrorOr Client::handle_take_element_screenshot(Vector const& parameters, JsonValue const&) +Web::WebDriver::Response Client::handle_take_element_screenshot(Vector const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session//element//screenshot"); auto* session = TRY(find_session_with_id(parameters[0])); diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index b9a9eeed7a..6caaad4a6d 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace WebDriver { @@ -35,7 +36,7 @@ private: void die(); void log_response(unsigned code, HTTP::HttpRequest const&); - using RouteHandler = ErrorOr (Client::*)(Vector const&, JsonValue const&); + using RouteHandler = Web::WebDriver::Response (Client::*)(Vector const&, JsonValue const&); struct Route { HTTP::HttpRequest::Method method; Vector path; @@ -48,46 +49,46 @@ private: }; ErrorOr match_route(HTTP::HttpRequest::Method method, String const& resource); - ErrorOr handle_new_session(Vector const&, JsonValue const& payload); - ErrorOr handle_delete_session(Vector const&, JsonValue const& payload); - ErrorOr handle_get_status(Vector const&, JsonValue const& payload); - ErrorOr handle_get_timeouts(Vector const&, JsonValue const& payload); - ErrorOr handle_set_timeouts(Vector const&, JsonValue const& payload); - ErrorOr handle_navigate_to(Vector const&, JsonValue const& payload); - ErrorOr handle_get_current_url(Vector const&, JsonValue const& payload); - ErrorOr handle_back(Vector const&, JsonValue const& payload); - ErrorOr handle_forward(Vector const&, JsonValue const& payload); - ErrorOr handle_refresh(Vector const&, JsonValue const& payload); - ErrorOr handle_get_title(Vector const&, JsonValue const& payload); - ErrorOr handle_get_window_handle(Vector const&, JsonValue const& payload); - ErrorOr handle_close_window(Vector const&, JsonValue const& payload); - ErrorOr handle_get_window_handles(Vector const&, JsonValue const& payload); - ErrorOr handle_get_window_rect(Vector const&, JsonValue const& payload); - ErrorOr handle_set_window_rect(Vector const&, JsonValue const& payload); - ErrorOr handle_maximize_window(Vector const&, JsonValue const& payload); - ErrorOr handle_minimize_window(Vector const&, JsonValue const& payload); - ErrorOr handle_find_element(Vector const&, JsonValue const& payload); - ErrorOr handle_find_elements(Vector const&, JsonValue const& payload); - ErrorOr handle_find_element_from_element(Vector const&, JsonValue const& payload); - ErrorOr handle_find_elements_from_element(Vector const&, JsonValue const& payload); - ErrorOr handle_is_element_selected(Vector const& parameters, JsonValue const& payload); - ErrorOr handle_get_element_attribute(Vector const&, JsonValue const& payload); - ErrorOr handle_get_element_property(Vector const&, JsonValue const& payload); - ErrorOr handle_get_element_css_value(Vector const&, JsonValue const& payload); - ErrorOr handle_get_element_text(Vector const&, JsonValue const& payload); - ErrorOr handle_get_element_tag_name(Vector const&, JsonValue const& payload); - ErrorOr handle_get_element_rect(Vector const&, JsonValue const& payload); - ErrorOr handle_is_element_enabled(Vector const&, JsonValue const& payload); - ErrorOr handle_get_source(Vector const&, JsonValue const& payload); - ErrorOr handle_execute_script(Vector const&, JsonValue const& payload); - ErrorOr handle_execute_async_script(Vector const&, JsonValue const& payload); - ErrorOr handle_get_all_cookies(Vector const&, JsonValue const& payload); - ErrorOr handle_get_named_cookie(Vector const&, JsonValue const& payload); - ErrorOr handle_add_cookie(Vector const&, JsonValue const& payload); - ErrorOr handle_delete_cookie(Vector const&, JsonValue const& payload); - ErrorOr handle_delete_all_cookies(Vector const&, JsonValue const& payload); - ErrorOr handle_take_screenshot(Vector const&, JsonValue const& payload); - ErrorOr handle_take_element_screenshot(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_new_session(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_delete_session(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_status(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_timeouts(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_set_timeouts(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_navigate_to(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_current_url(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_back(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_forward(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_refresh(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_title(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_window_handle(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_close_window(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_window_handles(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_window_rect(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_set_window_rect(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_maximize_window(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_minimize_window(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_find_element(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_find_elements(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_find_element_from_element(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_find_elements_from_element(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_is_element_selected(Vector const& parameters, JsonValue const& payload); + Web::WebDriver::Response handle_get_element_attribute(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_element_property(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_element_css_value(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_element_text(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_element_tag_name(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_element_rect(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_is_element_enabled(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_source(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_execute_script(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_execute_async_script(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_all_cookies(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_get_named_cookie(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_add_cookie(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_delete_cookie(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_delete_all_cookies(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_take_screenshot(Vector const&, JsonValue const& payload); + Web::WebDriver::Response handle_take_element_screenshot(Vector const&, JsonValue const& payload); ErrorOr find_session_with_id(StringView session_id); JsonValue make_json_value(JsonValue const&); diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index d494eeb323..a36801ed7a 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -107,7 +107,7 @@ JsonObject Session::get_timeouts() } // 9.2 Set Timeouts, https://w3c.github.io/webdriver/#dfn-set-timeouts -ErrorOr Session::set_timeouts(JsonValue const& payload) +Web::WebDriver::Response Session::set_timeouts(JsonValue const& payload) { // 1. Let timeouts be the result of trying to JSON deserialize as a timeouts configuration the request’s parameters. auto timeouts = TRY(json_deserialize_as_a_timeouts_configuration(payload)); @@ -120,7 +120,7 @@ ErrorOr Session::set_timeouts(JsonValue const& } // 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to -ErrorOr Session::navigate_to(JsonValue const& payload) +Web::WebDriver::Response Session::navigate_to(JsonValue const& payload) { // 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()); @@ -154,7 +154,7 @@ ErrorOr Session::navigate_to(JsonValue const& } // 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url -ErrorOr Session::get_current_url() +Web::WebDriver::Response Session::get_current_url() { // 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()); @@ -169,7 +169,7 @@ ErrorOr Session::get_current_url() } // 10.3 Back, https://w3c.github.io/webdriver/#dfn-back -ErrorOr Session::back() +Web::WebDriver::Response Session::back() { // 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()); @@ -190,7 +190,7 @@ ErrorOr Session::back() } // 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward -ErrorOr Session::forward() +Web::WebDriver::Response Session::forward() { // 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()); @@ -211,7 +211,7 @@ ErrorOr Session::forward() } // 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh -ErrorOr Session::refresh() +Web::WebDriver::Response Session::refresh() { // 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()); @@ -234,7 +234,7 @@ ErrorOr Session::refresh() } // 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title -ErrorOr Session::get_title() +Web::WebDriver::Response Session::get_title() { // 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()); @@ -247,13 +247,13 @@ ErrorOr Session::get_title() } // 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle -ErrorOr Session::get_window_handle() +Web::WebDriver::Response Session::get_window_handle() { // 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()); // 2. Return success with data being the window handle associated with the current top-level browsing context. - return m_current_window_handle; + return JsonValue { m_current_window_handle }; } // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window @@ -277,7 +277,7 @@ ErrorOr> Session::close_window() } // 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles -ErrorOr Session::get_window_handles() const +Web::WebDriver::Response Session::get_window_handles() const { // 1. Let handles be a JSON List. auto handles = JsonArray {}; @@ -287,10 +287,10 @@ ErrorOr Session::get_window_handles() const handles.append(window_handle); // 3. Return success with data handles. - return handles; + return JsonValue { handles }; } -static JsonObject serialize_rect(Gfx::IntRect const& rect) +static JsonValue serialize_rect(Gfx::IntRect const& rect) { JsonObject serialized_rect = {}; serialized_rect.set("x", rect.x()); @@ -302,7 +302,7 @@ static JsonObject serialize_rect(Gfx::IntRect const& rect) } // 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect -ErrorOr Session::get_window_rect() +Web::WebDriver::Response 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()); @@ -314,7 +314,7 @@ ErrorOr Session::get_window_rect() } // 11.8.2 Set Window Rect, https://w3c.github.io/webdriver/#dfn-set-window-rect -ErrorOr Session::set_window_rect(JsonValue const& payload) +Web::WebDriver::Response Session::set_window_rect(JsonValue const& payload) { if (!payload.is_object()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); @@ -386,7 +386,7 @@ ErrorOr Session::set_window_rect(JsonValue con } // 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window -ErrorOr Session::maximize_window() +Web::WebDriver::Response 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. @@ -407,7 +407,7 @@ ErrorOr Session::maximize_window() } // 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window -ErrorOr Session::minimize_window() +Web::WebDriver::Response 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. @@ -561,7 +561,7 @@ ErrorOr, Web::WebDriver::Error> Session::locator_s } // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element -ErrorOr Session::find_element(JsonValue const& payload) +Web::WebDriver::Response Session::find_element(JsonValue const& payload) { if (!payload.is_object()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); @@ -616,7 +616,7 @@ ErrorOr Session::find_element(JsonValue const& } // 12.3.3 Find Elements, https://w3c.github.io/webdriver/#dfn-find-elements -ErrorOr Session::find_elements(JsonValue const& payload) +Web::WebDriver::Response Session::find_elements(JsonValue const& payload) { if (!payload.is_object()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); @@ -666,7 +666,7 @@ ErrorOr Session::find_elements(JsonValue const } // 12.3.4 Find Element From Element, https://w3c.github.io/webdriver/#dfn-find-element-from-element -ErrorOr Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id) +Web::WebDriver::Response Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id) { if (!payload.is_object()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); @@ -715,7 +715,7 @@ ErrorOr Session::find_element_from_element(Jso } // 12.3.5 Find Elements From Element, https://w3c.github.io/webdriver/#dfn-find-elements-from-element -ErrorOr Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id) +Web::WebDriver::Response Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id) { if (!payload.is_object()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); @@ -759,7 +759,7 @@ ErrorOr Session::find_elements_from_element(Js } // 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected -ErrorOr Session::is_element_selected(StringView parameter_element_id) +Web::WebDriver::Response Session::is_element_selected(StringView parameter_element_id) { // 1. If the current 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()); @@ -779,11 +779,11 @@ ErrorOr Session::is_element_selected(StringVie auto selected = m_browser_connection->is_element_selected(element_id); // 5. Return success with data selected. - return selected; + return JsonValue { selected }; } // 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute -ErrorOr Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name) +Web::WebDriver::Response Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name) { // 1. If the current 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()); @@ -811,7 +811,7 @@ ErrorOr Session::get_element_attribute(JsonVal } // 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property -ErrorOr Session::get_element_property(JsonValue const&, StringView parameter_element_id, StringView name) +Web::WebDriver::Response Session::get_element_property(JsonValue const&, StringView parameter_element_id, StringView name) { // 1. If the current 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()); @@ -833,7 +833,7 @@ ErrorOr Session::get_element_property(JsonValu } // 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value -ErrorOr Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name) +Web::WebDriver::Response Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name) { // 1. If the current 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()); @@ -859,7 +859,7 @@ ErrorOr Session::get_element_css_value(JsonVal } // 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text -ErrorOr Session::get_element_text(JsonValue const&, StringView parameter_element_id) +Web::WebDriver::Response Session::get_element_text(JsonValue const&, StringView parameter_element_id) { // 1. If the current 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()); @@ -882,7 +882,7 @@ ErrorOr Session::get_element_text(JsonValue co } // 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name -ErrorOr Session::get_element_tag_name(JsonValue const&, StringView parameter_element_id) +Web::WebDriver::Response Session::get_element_tag_name(JsonValue const&, StringView parameter_element_id) { // 1. If the current 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()); @@ -900,7 +900,7 @@ ErrorOr Session::get_element_tag_name(JsonValu } // 12.4.7 Get Element Rect, https://w3c.github.io/webdriver/#dfn-get-element-rect -ErrorOr Session::get_element_rect(StringView parameter_element_id) +Web::WebDriver::Response Session::get_element_rect(StringView parameter_element_id) { // 1. If the current 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()); @@ -930,7 +930,7 @@ ErrorOr Session::get_element_rect(StringView p } // 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled -ErrorOr Session::is_element_enabled(StringView parameter_element_id) +Web::WebDriver::Response Session::is_element_enabled(StringView parameter_element_id) { // 1. If the current 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()); @@ -946,11 +946,11 @@ ErrorOr Session::is_element_enabled(StringView auto enabled = m_browser_connection->is_element_enabled(element_id); // 7. Return success with data enabled. - return enabled; + return JsonValue { enabled }; } // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source -ErrorOr Session::get_source() +Web::WebDriver::Response Session::get_source() { // 1. If the current 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()); @@ -963,7 +963,7 @@ ErrorOr Session::get_source() auto source = m_browser_connection->serialize_source(); // 5. Return success with data source. - return source; + return JsonValue { source }; } struct ScriptArguments { @@ -999,7 +999,7 @@ static ErrorOr extract_the_script_argume } // 13.2.1 Execute Script, https://w3c.github.io/webdriver/#dfn-execute-script -ErrorOr Session::execute_script(JsonValue const& payload) +Web::WebDriver::Response Session::execute_script(JsonValue const& payload) { // 1. Let body and arguments be the result of trying to extract the script arguments from a request with argument parameters. auto const& [body, arguments] = TRY(extract_the_script_arguments_from_a_request(payload)); @@ -1040,7 +1040,7 @@ ErrorOr Session::execute_script(JsonValue cons } // 13.2.2 Execute Async Script, https://w3c.github.io/webdriver/#dfn-execute-async-script -ErrorOr Session::execute_async_script(JsonValue const& parameters) +Web::WebDriver::Response Session::execute_async_script(JsonValue const& parameters) { // 1. Let body and arguments by the result of trying to extract the script arguments from a request with argument parameters. auto [body, arguments] = TRY(extract_the_script_arguments_from_a_request(parameters)); @@ -1096,7 +1096,7 @@ static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie) } // 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies -ErrorOr Session::get_all_cookies() +Web::WebDriver::Response Session::get_all_cookies() { // 1. If the current 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()); @@ -1120,7 +1120,7 @@ ErrorOr Session::get_all_cookies() } // 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie -ErrorOr Session::get_named_cookie(String const& name) +Web::WebDriver::Response Session::get_named_cookie(String const& name) { // 1. If the current 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()); @@ -1141,7 +1141,7 @@ ErrorOr Session::get_named_cookie(String const } // 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie -ErrorOr Session::add_cookie(JsonValue const& payload) +Web::WebDriver::Response Session::add_cookie(JsonValue const& payload) { // 1. Let data be the result of getting a property named cookie from the parameters argument. if (!payload.is_object() || !payload.as_object().has_object("cookie"sv)) @@ -1277,7 +1277,7 @@ void Session::delete_cookies(Optional const& name) } // 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie -ErrorOr Session::delete_cookie(StringView name) +Web::WebDriver::Response Session::delete_cookie(StringView name) { // 1. If the current 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()); @@ -1292,7 +1292,7 @@ ErrorOr Session::delete_cookie(StringView name } // 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies -ErrorOr Session::delete_all_cookies() +Web::WebDriver::Response Session::delete_all_cookies() { // 1. If the current 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()); @@ -1333,7 +1333,7 @@ static ErrorOr encode_bitmap_as_canvas_element(Gf } // 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot -ErrorOr Session::take_screenshot() +Web::WebDriver::Response Session::take_screenshot() { // 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()); @@ -1351,11 +1351,11 @@ ErrorOr Session::take_screenshot() auto encoded_string = TRY(encode_bitmap_as_canvas_element(*screenshot.bitmap())); // 3. Return success with data encoded string. - return encoded_string; + return JsonValue { encoded_string }; } // 17.2 Take Element Screenshot, https://w3c.github.io/webdriver/#dfn-take-element-screenshot -ErrorOr Session::take_element_screenshot(StringView parameter_element_id) +Web::WebDriver::Response Session::take_element_screenshot(StringView parameter_element_id) { // 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()); @@ -1381,7 +1381,7 @@ ErrorOr Session::take_element_screenshot(Strin auto encoded_string = TRY(encode_bitmap_as_canvas_element(*screenshot.bitmap())); // 6. Return success with data encoded string. - return encoded_string; + return JsonValue { encoded_string }; } } diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index d1ffcfa09f..7a1d33bf91 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -41,42 +42,42 @@ public: ErrorOr start(); ErrorOr stop(); JsonObject get_timeouts(); - ErrorOr set_timeouts(JsonValue const& payload); - ErrorOr navigate_to(JsonValue const& url); - ErrorOr get_current_url(); - ErrorOr back(); - ErrorOr forward(); - ErrorOr refresh(); - ErrorOr get_title(); - ErrorOr get_window_handle(); + Web::WebDriver::Response set_timeouts(JsonValue const& payload); + Web::WebDriver::Response navigate_to(JsonValue const& url); + Web::WebDriver::Response get_current_url(); + Web::WebDriver::Response back(); + Web::WebDriver::Response forward(); + Web::WebDriver::Response refresh(); + Web::WebDriver::Response get_title(); + Web::WebDriver::Response get_window_handle(); ErrorOr> close_window(); - ErrorOr get_window_handles() const; - ErrorOr get_window_rect(); - ErrorOr set_window_rect(JsonValue const& payload); - ErrorOr maximize_window(); - ErrorOr minimize_window(); - ErrorOr find_element(JsonValue const& payload); - ErrorOr find_elements(JsonValue const& payload); - ErrorOr find_element_from_element(JsonValue const& payload, StringView parameter_element_id); - ErrorOr find_elements_from_element(JsonValue const& payload, StringView parameter_element_id); - ErrorOr is_element_selected(StringView element_id); - ErrorOr get_element_attribute(JsonValue const& payload, StringView element_id, StringView name); - ErrorOr get_element_property(JsonValue const& payload, StringView element_id, StringView name); - ErrorOr get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name); - ErrorOr get_element_text(JsonValue const& payload, StringView element_id); - ErrorOr get_element_tag_name(JsonValue const& payload, StringView element_id); - ErrorOr get_element_rect(StringView element_id); - ErrorOr is_element_enabled(StringView element_id); - ErrorOr get_source(); - ErrorOr execute_script(JsonValue const& payload); - ErrorOr execute_async_script(JsonValue const& payload); - ErrorOr get_all_cookies(); - ErrorOr get_named_cookie(String const& name); - ErrorOr add_cookie(JsonValue const& payload); - ErrorOr delete_cookie(StringView name); - ErrorOr delete_all_cookies(); - ErrorOr take_screenshot(); - ErrorOr take_element_screenshot(StringView element_id); + Web::WebDriver::Response get_window_handles() const; + Web::WebDriver::Response get_window_rect(); + Web::WebDriver::Response set_window_rect(JsonValue const& payload); + Web::WebDriver::Response maximize_window(); + Web::WebDriver::Response minimize_window(); + Web::WebDriver::Response find_element(JsonValue const& payload); + Web::WebDriver::Response find_elements(JsonValue const& payload); + Web::WebDriver::Response find_element_from_element(JsonValue const& payload, StringView parameter_element_id); + Web::WebDriver::Response find_elements_from_element(JsonValue const& payload, StringView parameter_element_id); + Web::WebDriver::Response is_element_selected(StringView element_id); + Web::WebDriver::Response get_element_attribute(JsonValue const& payload, StringView element_id, StringView name); + Web::WebDriver::Response get_element_property(JsonValue const& payload, StringView element_id, StringView name); + Web::WebDriver::Response get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name); + Web::WebDriver::Response get_element_text(JsonValue const& payload, StringView element_id); + Web::WebDriver::Response get_element_tag_name(JsonValue const& payload, StringView element_id); + Web::WebDriver::Response get_element_rect(StringView element_id); + Web::WebDriver::Response is_element_enabled(StringView element_id); + Web::WebDriver::Response get_source(); + Web::WebDriver::Response execute_script(JsonValue const& payload); + Web::WebDriver::Response execute_async_script(JsonValue const& payload); + Web::WebDriver::Response get_all_cookies(); + Web::WebDriver::Response get_named_cookie(String const& name); + Web::WebDriver::Response add_cookie(JsonValue const& payload); + Web::WebDriver::Response delete_cookie(StringView name); + Web::WebDriver::Response delete_all_cookies(); + Web::WebDriver::Response take_screenshot(); + Web::WebDriver::Response take_element_screenshot(StringView element_id); private: void delete_cookies(Optional const& name = {});