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

WebDriver: Rename HttpError -> WebDriverError

This commit is contained in:
Sam Atkins 2022-10-20 12:04:39 +01:00 committed by Linus Groh
parent 87a9462b7f
commit 89c3e0b567
7 changed files with 220 additions and 219 deletions

View file

@ -206,7 +206,7 @@ ErrorOr<void> Client::send_response(StringView content, HTTP::HttpRequest const&
}
// https://w3c.github.io/webdriver/#dfn-send-an-error
ErrorOr<void> Client::send_error_response(HttpError const& error, HTTP::HttpRequest const& request)
ErrorOr<void> Client::send_error_response(WebDriverError const& error, HTTP::HttpRequest const& request)
{
// FIXME: Implement to spec.
@ -241,7 +241,7 @@ void Client::log_response(unsigned code, HTTP::HttpRequest const& request)
}
// https://w3c.github.io/webdriver/#dfn-match-a-request
ErrorOr<Client::RoutingResult, HttpError> Client::match_route(HTTP::HttpRequest::Method method, String const& resource)
ErrorOr<Client::RoutingResult, WebDriverError> Client::match_route(HTTP::HttpRequest::Method method, String const& resource)
{
// FIXME: Implement to spec.
@ -249,7 +249,7 @@ ErrorOr<Client::RoutingResult, HttpError> Client::match_route(HTTP::HttpRequest:
// https://w3c.github.io/webdriver/webdriver-spec.html#routing-requests
if (!resource.starts_with(m_prefix))
return HttpError { 404, "unknown command", "The resource doesn't start with the prefix." };
return WebDriverError { 404, "unknown command", "The resource doesn't start with the prefix." };
Vector<StringView> resource_split = resource.substring_view(m_prefix.length()).split_view('/', true);
Vector<StringView> parameters;
@ -288,25 +288,25 @@ ErrorOr<Client::RoutingResult, HttpError> Client::match_route(HTTP::HttpRequest:
// Matched a path, but didn't match a known method
if (matched_path) {
dbgln_if(WEBDRIVER_DEBUG, "- A path matched, but method didn't. :^(");
return HttpError { 405, "unknown method", "The command matched a known URL but did not match a method for that URL." };
return WebDriverError { 405, "unknown method", "The command matched a known URL but did not match a method for that URL." };
}
// Didn't have any match
dbgln_if(WEBDRIVER_DEBUG, "- No matches. :^(");
return HttpError { 404, "unknown command", "The command was not recognized." };
return WebDriverError { 404, "unknown command", "The command was not recognized." };
}
ErrorOr<Session*, HttpError> Client::find_session_with_id(StringView session_id)
ErrorOr<Session*, WebDriverError> Client::find_session_with_id(StringView session_id)
{
auto session_id_or_error = session_id.to_uint<>();
if (!session_id_or_error.has_value())
return HttpError { 404, "invalid session id", "Invalid session id" };
return WebDriverError { 404, "invalid session id", "Invalid session id" };
for (auto& session : Client::s_sessions) {
if (session.session_id() == session_id_or_error.value())
return &session;
}
return HttpError { 404, "invalid session id", "Invalid session id" };
return WebDriverError { 404, "invalid session id", "Invalid session id" };
}
void Client::close_session(unsigned session_id)
@ -330,7 +330,7 @@ JsonValue Client::make_json_value(JsonValue const& value)
// 8.1 New Session, https://w3c.github.io/webdriver/#dfn-new-sessions
// POST /session
ErrorOr<JsonValue, HttpError> Client::handle_new_session(Vector<StringView> const&, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_new_session(Vector<StringView> const&, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session");
@ -360,7 +360,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_new_session(Vector<StringView> cons
NonnullOwnPtr<Session> session = make<Session>(session_id, *this);
auto start_result = session->start();
if (start_result.is_error()) {
return HttpError { 500, "Failed to start session", start_result.error().string_literal() };
return WebDriverError { 500, "Failed to start session", start_result.error().string_literal() };
}
// FIXME: 8. Set the current session to session.
@ -396,7 +396,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_new_session(Vector<StringView> cons
// 8.2 Delete Session, https://w3c.github.io/webdriver/#dfn-delete-session
// DELETE /session/{session id}
ErrorOr<JsonValue, HttpError> Client::handle_delete_session(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_delete_session(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>");
@ -405,7 +405,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_delete_session(Vector<StringView> c
auto stop_result = session->stop();
if (stop_result.is_error()) {
return HttpError { 500, "unsupported operation", stop_result.error().string_literal() };
return WebDriverError { 500, "unsupported operation", stop_result.error().string_literal() };
}
// 2. Return success with data null.
@ -414,7 +414,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_delete_session(Vector<StringView> c
// 8.3 Status, https://w3c.github.io/webdriver/#dfn-status
// GET /status
ErrorOr<JsonValue, HttpError> Client::handle_get_status(Vector<StringView> const&, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_status(Vector<StringView> const&, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /status");
@ -434,7 +434,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_status(Vector<StringView> const
// 9.1 Get Timeouts, https://w3c.github.io/webdriver/#dfn-get-timeouts
// GET /session/{session id}/timeouts
ErrorOr<JsonValue, HttpError> Client::handle_get_timeouts(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_timeouts(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session id>/timeouts");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -444,7 +444,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_timeouts(Vector<StringView> con
// 9.2 Set Timeouts, https://w3c.github.io/webdriver/#dfn-set-timeouts
// POST /session/{session id}/timeouts
ErrorOr<JsonValue, HttpError> Client::handle_set_timeouts(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_set_timeouts(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session id>/timeouts");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -454,7 +454,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_set_timeouts(Vector<StringView> con
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
// POST /session/{session id}/url
ErrorOr<JsonValue, HttpError> Client::handle_navigate_to(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_navigate_to(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/url");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -464,7 +464,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_navigate_to(Vector<StringView> cons
// 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
// GET /session/{session id}/url
ErrorOr<JsonValue, HttpError> Client::handle_get_current_url(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_current_url(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -474,7 +474,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_current_url(Vector<StringView>
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
// POST /session/{session id}/back
ErrorOr<JsonValue, HttpError> Client::handle_back(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_back(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/back");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -484,7 +484,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_back(Vector<StringView> const& para
// 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward
// POST /session/{session id}/forward
ErrorOr<JsonValue, HttpError> Client::handle_forward(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_forward(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/forward");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -494,7 +494,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_forward(Vector<StringView> const& p
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
// POST /session/{session id}/refresh
ErrorOr<JsonValue, HttpError> Client::handle_refresh(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_refresh(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/refresh");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -504,7 +504,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_refresh(Vector<StringView> const& p
// 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title
// GET /session/{session id}/title
ErrorOr<JsonValue, HttpError> Client::handle_get_title(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_title(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/title");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -514,7 +514,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_title(Vector<StringView> const&
// 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle
// GET /session/{session id}/window
ErrorOr<JsonValue, HttpError> Client::handle_get_window_handle(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handle(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -524,7 +524,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_window_handle(Vector<StringView
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
// DELETE /session/{session id}/window
ErrorOr<JsonValue, HttpError> Client::handle_close_window(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_close_window(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -534,7 +534,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_close_window(Vector<StringView> con
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
// GET /session/{session id}/window/handles
ErrorOr<JsonValue, HttpError> Client::handle_get_window_handles(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_window_handles(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window/handles");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -544,7 +544,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_window_handles(Vector<StringVie
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
// POST /session/{session id}/element
ErrorOr<JsonValue, HttpError> 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)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -554,7 +554,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_find_element(Vector<StringView> con
// 12.3.3 Find Elements, https://w3c.github.io/webdriver/#dfn-find-elements
// POST /session/{session id}/elements
ErrorOr<JsonValue, HttpError> Client::handle_find_elements(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/elements");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -564,7 +564,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_find_elements(Vector<StringView> co
// 12.3.4 Find Element From Element, https://w3c.github.io/webdriver/#dfn-find-element-from-element
// POST /session/{session id}/element/{element id}/element
ErrorOr<JsonValue, HttpError> Client::handle_find_element_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_find_element_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element/<element_id>/element");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -574,7 +574,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_find_element_from_element(Vector<St
// 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<JsonValue, HttpError> Client::handle_find_elements_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_find_elements_from_element(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/element/<element_id>/elements");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -584,7 +584,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_find_elements_from_element(Vector<S
// 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<JsonValue, HttpError> Client::handle_get_element_attribute(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_attribute(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/attribute/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -594,7 +594,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_element_attribute(Vector<String
// 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<JsonValue, HttpError> Client::handle_get_element_property(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_property(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/property/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -604,7 +604,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_element_property(Vector<StringV
// 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<JsonValue, HttpError> Client::handle_get_element_css_value(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_element_css_value(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/css/<property_name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -614,7 +614,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_element_css_value(Vector<String
// 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies
// GET /session/{session id}/cookie
ErrorOr<JsonValue, HttpError> Client::handle_get_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/cookie");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -624,7 +624,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_all_cookies(Vector<StringView>
// 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie
// GET /session/{session id}/cookie/{name}
ErrorOr<JsonValue, HttpError> Client::handle_get_named_cookie(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_get_named_cookie(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/cookie/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -634,7 +634,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_named_cookie(Vector<StringView>
// 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie
// POST /session/{session id}/cookie
ErrorOr<JsonValue, HttpError> Client::handle_add_cookie(Vector<StringView> const& parameters, JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Client::handle_add_cookie(Vector<StringView> const& parameters, JsonValue const& payload)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/cookie");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -644,7 +644,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_add_cookie(Vector<StringView> const
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
// DELETE /session/{session id}/cookie/{name}
ErrorOr<JsonValue, HttpError> Client::handle_delete_cookie(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_delete_cookie(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie/<name>");
auto* session = TRY(find_session_with_id(parameters[0]));
@ -654,7 +654,7 @@ ErrorOr<JsonValue, HttpError> Client::handle_delete_cookie(Vector<StringView> co
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
// DELETE /session/{session id}/cookie
ErrorOr<JsonValue, HttpError> Client::handle_delete_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
ErrorOr<JsonValue, WebDriverError> Client::handle_delete_all_cookies(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie");
auto* session = TRY(find_session_with_id(parameters[0]));

View file

@ -12,8 +12,8 @@
#include <LibCore/Stream.h>
#include <LibHTTP/Forward.h>
#include <LibHTTP/HttpRequest.h>
#include <WebDriver/HttpError.h>
#include <WebDriver/Session.h>
#include <WebDriver/WebDriverError.h>
namespace WebDriver {
@ -30,11 +30,11 @@ private:
ErrorOr<JsonValue> read_body_as_json(HTTP::HttpRequest const&);
ErrorOr<bool> handle_request(HTTP::HttpRequest const&, JsonValue const& body);
ErrorOr<void> send_response(StringView content, HTTP::HttpRequest const&);
ErrorOr<void> send_error_response(HttpError const& error, HTTP::HttpRequest const&);
ErrorOr<void> send_error_response(WebDriverError const& error, HTTP::HttpRequest const&);
void die();
void log_response(unsigned code, HTTP::HttpRequest const&);
using RouteHandler = ErrorOr<JsonValue, HttpError> (Client::*)(Vector<StringView> const&, JsonValue const&);
using RouteHandler = ErrorOr<JsonValue, WebDriverError> (Client::*)(Vector<StringView> const&, JsonValue const&);
struct Route {
HTTP::HttpRequest::Method method;
Vector<String> path;
@ -46,56 +46,56 @@ private:
Vector<StringView> parameters;
};
ErrorOr<RoutingResult, HttpError> match_route(HTTP::HttpRequest::Method method, String const& resource);
ErrorOr<JsonValue, HttpError> handle_new_session(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_delete_session(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_status(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_timeouts(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_set_timeouts(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_navigate_to(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_current_url(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_back(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_forward(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_refresh(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_title(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_window_handle(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_close_window(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_window_handles(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_find_element(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_find_elements(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_find_elements_from_element(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_element_attribute(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_element_property(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_element_css_value(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_all_cookies(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_get_named_cookie(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_add_cookie(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_delete_cookie(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_delete_all_cookies(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<RoutingResult, WebDriverError> match_route(HTTP::HttpRequest::Method method, String const& resource);
ErrorOr<JsonValue, WebDriverError> handle_new_session(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_delete_session(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_status(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_timeouts(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_set_timeouts(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_navigate_to(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_current_url(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_back(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_forward(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_refresh(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_title(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_window_handle(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_close_window(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_window_handles(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);
ErrorOr<JsonValue, WebDriverError> handle_find_elements_from_element(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_element_attribute(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_element_property(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_element_css_value(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_all_cookies(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_get_named_cookie(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_add_cookie(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_delete_cookie(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> handle_delete_all_cookies(Vector<StringView> const&, JsonValue const& payload);
ErrorOr<Session*, HttpError> find_session_with_id(StringView session_id);
ErrorOr<Session*, WebDriverError> find_session_with_id(StringView session_id);
JsonValue make_json_value(JsonValue const&);
template<typename T>
static ErrorOr<T, HttpError> unwrap_result(ErrorOr<T, Variant<HttpError, Error>> result)
static ErrorOr<T, WebDriverError> unwrap_result(ErrorOr<T, Variant<WebDriverError, Error>> result)
{
if (result.is_error()) {
Variant<HttpError, Error> error = result.release_error();
if (error.has<HttpError>())
return error.get<HttpError>();
return HttpError { 500, "unsupported operation", error.get<Error>().string_literal() };
Variant<WebDriverError, Error> error = result.release_error();
if (error.has<WebDriverError>())
return error.get<WebDriverError>();
return WebDriverError { 500, "unsupported operation", error.get<Error>().string_literal() };
}
return result.release_value();
}
static ErrorOr<void, HttpError> unwrap_result(ErrorOr<void, Variant<HttpError, Error>> result)
static ErrorOr<void, WebDriverError> unwrap_result(ErrorOr<void, Variant<WebDriverError, Error>> result)
{
if (result.is_error()) {
Variant<HttpError, Error> error = result.release_error();
if (error.has<HttpError>())
return error.get<HttpError>();
return HttpError { 500, "unsupported operation", error.get<Error>().string_literal() };
Variant<WebDriverError, Error> error = result.release_error();
if (error.has<WebDriverError>())
return error.get<WebDriverError>();
return WebDriverError { 500, "unsupported operation", error.get<Error>().string_literal() };
}
return {};
}

View file

@ -84,7 +84,7 @@ JsonObject Session::get_timeouts()
}
// 9.2 Set Timeouts, https://w3c.github.io/webdriver/#dfn-set-timeouts
ErrorOr<JsonValue, HttpError> Session::set_timeouts(JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Session::set_timeouts(JsonValue const& payload)
{
// 1. Let timeouts be the result of trying to JSON deserialize as a timeouts configuration the requests parameters.
auto timeouts = TRY(json_deserialize_as_a_timeouts_configuration(payload));
@ -97,18 +97,18 @@ ErrorOr<JsonValue, HttpError> Session::set_timeouts(JsonValue const& payload)
}
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
ErrorOr<JsonValue, HttpError> Session::navigate_to(JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> 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.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME 2. Handle any user prompts and return its value if it is an error.
// 3. If the url property is missing from the parameters argument or it is not a string, return error with error code invalid argument.
if (!payload.is_object() || !payload.as_object().has_string("url"sv)) {
return HttpError { 400, "invalid argument", "Payload doesn't have a string url" };
return WebDriverError { 400, "invalid argument", "Payload doesn't have a string url" };
}
// 4. Let url be the result of getting a property named url from the parameters argument.
@ -133,12 +133,12 @@ ErrorOr<JsonValue, HttpError> Session::navigate_to(JsonValue const& payload)
}
// 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
ErrorOr<JsonValue, HttpError> Session::get_current_url()
ErrorOr<JsonValue, WebDriverError> Session::get_current_url()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -150,12 +150,12 @@ ErrorOr<JsonValue, HttpError> Session::get_current_url()
}
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
ErrorOr<JsonValue, HttpError> Session::back()
ErrorOr<JsonValue, WebDriverError> Session::back()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -173,12 +173,12 @@ ErrorOr<JsonValue, HttpError> Session::back()
}
// 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward
ErrorOr<JsonValue, HttpError> Session::forward()
ErrorOr<JsonValue, WebDriverError> Session::forward()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -196,12 +196,12 @@ ErrorOr<JsonValue, HttpError> Session::forward()
}
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
ErrorOr<JsonValue, HttpError> Session::refresh()
ErrorOr<JsonValue, WebDriverError> Session::refresh()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -221,12 +221,12 @@ ErrorOr<JsonValue, HttpError> Session::refresh()
}
// 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title
ErrorOr<JsonValue, HttpError> Session::get_title()
ErrorOr<JsonValue, WebDriverError> Session::get_title()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -236,24 +236,24 @@ ErrorOr<JsonValue, HttpError> Session::get_title()
}
// 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle
ErrorOr<JsonValue, HttpError> Session::get_window_handle()
ErrorOr<JsonValue, WebDriverError> 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 = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 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()
ErrorOr<void, Variant<WebDriverError, Error>> Session::close_window()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return Variant<HttpError, Error>(HttpError { 404, "no such window", "Window not found" });
return Variant<WebDriverError, Error>(WebDriverError { 404, "no such window", "Window not found" });
// 2. Close the current top-level browsing context.
m_windows.remove(m_current_window_handle);
@ -262,7 +262,7 @@ ErrorOr<void, Variant<HttpError, Error>> Session::close_window()
if (m_windows.is_empty()) {
auto result = stop();
if (result.is_error()) {
return Variant<HttpError, Error>(result.release_error());
return Variant<WebDriverError, Error>(result.release_error());
}
}
@ -270,7 +270,7 @@ ErrorOr<void, Variant<HttpError, Error>> Session::close_window()
}
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
ErrorOr<JsonValue, HttpError> Session::get_window_handles() const
ErrorOr<JsonValue, WebDriverError> Session::get_window_handles() const
{
// 1. Let handles be a JSON List.
auto handles = JsonArray {};
@ -312,7 +312,7 @@ static JsonObject web_element_reference_object(Session::LocalElement const& elem
}
// https://w3c.github.io/webdriver/#dfn-find
ErrorOr<JsonArray, HttpError> Session::find(Session::LocalElement const& start_node, StringView const& using_, StringView const& value)
ErrorOr<JsonArray, WebDriverError> Session::find(Session::LocalElement const& start_node, StringView const& using_, StringView const& value)
{
// 1. Let end time be the current time plus the session implicit wait timeout.
auto end_time = Time::now_monotonic() + Time::from_milliseconds(static_cast<i64>(m_timeouts_configuration.implicit_wait_timeout));
@ -326,13 +326,13 @@ ErrorOr<JsonArray, HttpError> Session::find(Session::LocalElement const& start_n
// 4. Let elements returned be the result of trying to call the relevant element location strategy with arguments start node, and selector.
auto location_strategy_handler = s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; });
if (!location_strategy_handler.has_value())
return HttpError { 400, "invalid argument", "No valid location strategy" };
return WebDriverError { 400, "invalid argument", "No valid location strategy" };
auto elements_or_error = (this->*location_strategy_handler.value().handler)(start_node, selector);
// 5. If a DOMException, SyntaxError, XPathException, or other error occurs during the execution of the element location strategy, return error invalid selector.
if (elements_or_error.is_error())
return HttpError { 400, "invalid selector", String::formatted("The location strategy could not finish: {}", elements_or_error.release_error().message) };
return WebDriverError { 400, "invalid selector", String::formatted("The location strategy could not finish: {}", elements_or_error.release_error().message) };
auto elements = elements_or_error.release_value();
@ -361,14 +361,14 @@ Vector<Session::LocatorStrategy> Session::s_locator_strategies = {
};
// https://w3c.github.io/webdriver/#css-selectors
ErrorOr<Vector<Session::LocalElement>, HttpError> Session::locator_strategy_css_selectors(Session::LocalElement const& start_node, StringView const& selector)
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_css_selectors(Session::LocalElement const& start_node, StringView const& selector)
{
// 1. Let elements be the result of calling querySelectorAll() with start node as this and selector as the argument.
// If this causes an exception to be thrown, return error with error code invalid selector.
auto elements_ids = m_browser_connection->query_selector_all(start_node.id, selector);
if (!elements_ids.has_value())
return HttpError { 400, "invalid selector", "query_selector_all returned failed!" };
return WebDriverError { 400, "invalid selector", "query_selector_all returned failed!" };
Vector<Session::LocalElement> elements;
for (auto id : elements_ids.release_value()) {
@ -380,67 +380,67 @@ ErrorOr<Vector<Session::LocalElement>, HttpError> Session::locator_strategy_css_
}
// https://w3c.github.io/webdriver/#link-text
ErrorOr<Vector<Session::LocalElement>, HttpError> Session::locator_strategy_link_text(Session::LocalElement const&, StringView const&)
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_link_text(Session::LocalElement const&, StringView const&)
{
// FIXME: Implement
return HttpError { 501, "not implemented", "locator strategy link text" };
return WebDriverError { 501, "not implemented", "locator strategy link text" };
}
// https://w3c.github.io/webdriver/#partial-link-text
ErrorOr<Vector<Session::LocalElement>, HttpError> Session::locator_strategy_partial_link_text(Session::LocalElement const&, StringView const&)
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_partial_link_text(Session::LocalElement const&, StringView const&)
{
// FIXME: Implement
return HttpError { 501, "not implemented", "locator strategy partial link text" };
return WebDriverError { 501, "not implemented", "locator strategy partial link text" };
}
// https://w3c.github.io/webdriver/#tag-name
ErrorOr<Vector<Session::LocalElement>, HttpError> Session::locator_strategy_tag_name(Session::LocalElement const&, StringView const&)
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_tag_name(Session::LocalElement const&, StringView const&)
{
// FIXME: Implement
return HttpError { 501, "not implemented", "locator strategy tag name" };
return WebDriverError { 501, "not implemented", "locator strategy tag name" };
}
// https://w3c.github.io/webdriver/#xpath
ErrorOr<Vector<Session::LocalElement>, HttpError> Session::locator_strategy_x_path(Session::LocalElement const&, StringView const&)
ErrorOr<Vector<Session::LocalElement>, WebDriverError> Session::locator_strategy_x_path(Session::LocalElement const&, StringView const&)
{
// FIXME: Implement
return HttpError { 501, "not implemented", "locator strategy XPath" };
return WebDriverError { 501, "not implemented", "locator strategy XPath" };
}
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
ErrorOr<JsonValue, HttpError> Session::find_element(JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Session::find_element(JsonValue const& payload)
{
if (!payload.is_object())
return HttpError { 400, "invalid argument", "Payload is not a JSON object" };
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" };
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
return HttpError { 400, "invalid argument", "No property called 'using' present" };
return WebDriverError { 400, "invalid argument", "No property called 'using' present" };
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
return HttpError { 400, "invalid argument", "Property 'using' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" };
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return HttpError { 400, "invalid argument", "No valid location strategy" };
return WebDriverError { 400, "invalid argument", "No valid location strategy" };
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
return HttpError { 400, "invalid argument", "No property called 'value' present" };
return WebDriverError { 400, "invalid argument", "No property called 'value' present" };
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
return HttpError { 400, "invalid argument", "Property 'value' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" };
auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -449,7 +449,7 @@ ErrorOr<JsonValue, HttpError> Session::find_element(JsonValue const& payload)
// 8. If start node is null, return error with error code no such element.
if (!maybe_start_node_id.has_value())
return HttpError { 404, "no such element", "document element does not exist" };
return WebDriverError { 404, "no such element", "document element does not exist" };
auto start_node_id = maybe_start_node_id.release_value();
LocalElement start_node = { start_node_id };
@ -459,45 +459,45 @@ ErrorOr<JsonValue, HttpError> Session::find_element(JsonValue const& payload)
// 10. If result is empty, return error with error code no such element. Otherwise, return the first element of result.
if (result.is_empty())
return HttpError { 404, "no such element", "the requested element does not exist" };
return WebDriverError { 404, "no such element", "the requested element does not exist" };
return JsonValue(result.at(0));
}
// 12.3.3 Find Elements, https://w3c.github.io/webdriver/#dfn-find-elements
ErrorOr<JsonValue, HttpError> Session::find_elements(JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> Session::find_elements(JsonValue const& payload)
{
if (!payload.is_object())
return HttpError { 400, "invalid argument", "Payload is not a JSON object" };
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" };
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
return HttpError { 400, "invalid argument", "No property called 'using' present" };
return WebDriverError { 400, "invalid argument", "No property called 'using' present" };
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
return HttpError { 400, "invalid argument", "Property 'using' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" };
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return HttpError { 400, "invalid argument", "No valid location strategy" };
return WebDriverError { 400, "invalid argument", "No valid location strategy" };
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
return HttpError { 400, "invalid argument", "No property called 'value' present" };
return WebDriverError { 400, "invalid argument", "No property called 'value' present" };
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
return HttpError { 400, "invalid argument", "Property 'value' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" };
auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -506,7 +506,7 @@ ErrorOr<JsonValue, HttpError> Session::find_elements(JsonValue const& payload)
// 8. If start node is null, return error with error code no such element.
if (!maybe_start_node_id.has_value())
return HttpError { 404, "no such element", "document element does not exist" };
return WebDriverError { 404, "no such element", "document element does not exist" };
auto start_node_id = maybe_start_node_id.release_value();
LocalElement start_node = { start_node_id };
@ -517,39 +517,39 @@ ErrorOr<JsonValue, HttpError> Session::find_elements(JsonValue const& payload)
}
// 12.3.4 Find Element From Element, https://w3c.github.io/webdriver/#dfn-find-element-from-element
ErrorOr<JsonValue, HttpError> Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id)
ErrorOr<JsonValue, WebDriverError> Session::find_element_from_element(JsonValue const& payload, StringView parameter_element_id)
{
if (!payload.is_object())
return HttpError { 400, "invalid argument", "Payload is not a JSON object" };
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" };
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
return HttpError { 400, "invalid argument", "No property called 'using' present" };
return WebDriverError { 400, "invalid argument", "No property called 'using' present" };
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
return HttpError { 400, "invalid argument", "Property 'using' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" };
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return HttpError { 400, "invalid argument", "No valid location strategy" };
return WebDriverError { 400, "invalid argument", "No valid location strategy" };
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
return HttpError { 400, "invalid argument", "No property called 'value' present" };
return WebDriverError { 400, "invalid argument", "No property called 'value' present" };
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
return HttpError { 400, "invalid argument", "Property 'value' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" };
auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -559,7 +559,7 @@ ErrorOr<JsonValue, HttpError> Session::find_element_from_element(JsonValue const
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
return HttpError { 400, "invalid argument", "Element ID is not an i32" };
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" };
auto element_id = maybe_element_id.release_value();
LocalElement start_node = { element_id };
@ -569,45 +569,45 @@ ErrorOr<JsonValue, HttpError> Session::find_element_from_element(JsonValue const
// 9. If result is empty, return error with error code no such element. Otherwise, return the first element of result.
if (result.is_empty())
return HttpError { 404, "no such element", "the requested element does not exist" };
return WebDriverError { 404, "no such element", "the requested element does not exist" };
return JsonValue(result.at(0));
}
// 12.3.5 Find Elements From Element, https://w3c.github.io/webdriver/#dfn-find-elements-from-element
ErrorOr<JsonValue, HttpError> Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id)
ErrorOr<JsonValue, WebDriverError> Session::find_elements_from_element(JsonValue const& payload, StringView parameter_element_id)
{
if (!payload.is_object())
return HttpError { 400, "invalid argument", "Payload is not a JSON object" };
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" };
auto const& properties = payload.as_object();
// 1. Let location strategy be the result of getting a property called "using".
if (!properties.has("using"sv))
return HttpError { 400, "invalid argument", "No property called 'using' present" };
return WebDriverError { 400, "invalid argument", "No property called 'using' present" };
auto const& maybe_location_strategy = properties.get("using"sv);
if (!maybe_location_strategy.is_string())
return HttpError { 400, "invalid argument", "Property 'using' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'using' is not a String" };
auto location_strategy = maybe_location_strategy.to_string();
// 2. If location strategy is not present as a keyword in the table of location strategies, return error with error code invalid argument.
if (!s_locator_strategies.first_matching([&](LocatorStrategy const& match) { return match.name == location_strategy; }).has_value())
return HttpError { 400, "invalid argument", "No valid location strategy" };
return WebDriverError { 400, "invalid argument", "No valid location strategy" };
// 3. Let selector be the result of getting a property called "value".
// 4. If selector is undefined, return error with error code invalid argument.
if (!properties.has("value"sv))
return HttpError { 400, "invalid argument", "No property called 'value' present" };
return WebDriverError { 400, "invalid argument", "No property called 'value' present" };
auto const& maybe_selector = properties.get("value"sv);
if (!maybe_selector.is_string())
return HttpError { 400, "invalid argument", "Property 'value' is not a String" };
return WebDriverError { 400, "invalid argument", "Property 'value' is not a String" };
auto selector = maybe_selector.to_string();
// 5. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 6. Handle any user prompts and return its value if it is an error.
@ -617,7 +617,7 @@ ErrorOr<JsonValue, HttpError> Session::find_elements_from_element(JsonValue cons
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
return HttpError { 400, "invalid argument", "Element ID is not an i32" };
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" };
auto element_id = maybe_element_id.release_value();
LocalElement start_node = { element_id };
@ -628,12 +628,12 @@ ErrorOr<JsonValue, HttpError> Session::find_elements_from_element(JsonValue cons
}
// 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute
ErrorOr<JsonValue, HttpError> Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name)
ErrorOr<JsonValue, WebDriverError> 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.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -642,7 +642,7 @@ ErrorOr<JsonValue, HttpError> Session::get_element_attribute(JsonValue const&, S
// For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
return HttpError { 400, "invalid argument", "Element ID is not an i32" };
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" };
auto element_id = maybe_element_id.release_value();
@ -664,12 +664,12 @@ ErrorOr<JsonValue, HttpError> Session::get_element_attribute(JsonValue const&, S
}
// 12.4.3 Get Element Property, https://w3c.github.io/webdriver/#dfn-get-element-property
ErrorOr<JsonValue, HttpError> Session::get_element_property(JsonValue const&, StringView parameter_element_id, StringView name)
ErrorOr<JsonValue, WebDriverError> 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.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -678,7 +678,7 @@ ErrorOr<JsonValue, HttpError> Session::get_element_property(JsonValue const&, St
// For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
return HttpError { 400, "invalid argument", "Element ID is not an i32" };
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" };
auto element_id = maybe_element_id.release_value();
@ -694,12 +694,12 @@ ErrorOr<JsonValue, HttpError> Session::get_element_property(JsonValue const&, St
}
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
ErrorOr<JsonValue, HttpError> Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name)
ErrorOr<JsonValue, WebDriverError> 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.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts and return its value if it is an error.
@ -708,7 +708,7 @@ ErrorOr<JsonValue, HttpError> Session::get_element_css_value(JsonValue const&, S
// For now the element is only represented by its ID
auto maybe_element_id = parameter_element_id.to_int();
if (!maybe_element_id.has_value())
return HttpError { 400, "invalid argument", "Element ID is not an i32" };
return WebDriverError { 400, "invalid argument", "Element ID is not an i32" };
auto element_id = maybe_element_id.release_value();
@ -744,12 +744,12 @@ static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie)
}
// 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies
ErrorOr<JsonValue, HttpError> Session::get_all_cookies()
ErrorOr<JsonValue, WebDriverError> Session::get_all_cookies()
{
// 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts, and return its value if it is an error.
@ -770,12 +770,12 @@ ErrorOr<JsonValue, HttpError> Session::get_all_cookies()
}
// 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie
ErrorOr<JsonValue, HttpError> Session::get_named_cookie(String const& name)
ErrorOr<JsonValue, WebDriverError> 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.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts, and return its value if it is an error.
@ -789,15 +789,15 @@ ErrorOr<JsonValue, HttpError> Session::get_named_cookie(String const& name)
}
// 4. Otherwise, return error with error code no such cookie.
return HttpError { 404, "no such cookie", "Cookie not found" };
return WebDriverError { 404, "no such cookie", "Cookie not found" };
}
// 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie
ErrorOr<JsonValue, HttpError> Session::add_cookie(JsonValue const& payload)
ErrorOr<JsonValue, WebDriverError> 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))
return HttpError { 400, "invalid argument", "Payload doesn't have a cookie object" };
return WebDriverError { 400, "invalid argument", "Payload doesn't have a cookie object" };
auto const& maybe_data = payload.as_object().get("cookie"sv);
@ -805,17 +805,17 @@ ErrorOr<JsonValue, HttpError> Session::add_cookie(JsonValue const& payload)
// return error with error code invalid argument.
// NOTE: Table is here: https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion
if (!maybe_data.is_object())
return HttpError { 400, "invalid argument", "Value \"cookie\' is not an object" };
return WebDriverError { 400, "invalid argument", "Value \"cookie\' is not an object" };
auto const& data = maybe_data.as_object();
if (!data.has("name"sv) || !data.has("value"sv))
return HttpError { 400, "invalid argument", "Cookie-Object doesn't contain all required keys" };
return WebDriverError { 400, "invalid argument", "Cookie-Object doesn't contain all required keys" };
// 3. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 4. Handle any user prompts, and return its value if it is an error.
@ -828,17 +828,17 @@ ErrorOr<JsonValue, HttpError> Session::add_cookie(JsonValue const& payload)
// or cookie expiry time is not an integer type, or it less than 0 or greater than the maximum safe integer,
// return error with error code invalid argument.
if (data.get("name"sv).is_null() || data.get("value"sv).is_null())
return HttpError { 400, "invalid argument", "Cookie-Object is malformed: name or value are null" };
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: name or value are null" };
if (data.has("secure"sv) && !data.get("secure"sv).is_bool())
return HttpError { 400, "invalid argument", "Cookie-Object is malformed: secure is not bool" };
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: secure is not bool" };
if (data.has("httpOnly"sv) && !data.get("httpOnly"sv).is_bool())
return HttpError { 400, "invalid argument", "Cookie-Object is malformed: httpOnly is not bool" };
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: httpOnly is not bool" };
Optional<Core::DateTime> expiry_time;
if (data.has("expiry"sv)) {
auto expiry_argument = data.get("expiry"sv);
if (!expiry_argument.is_u32()) {
// NOTE: less than 0 or greater than safe integer are handled by the JSON parser
return HttpError { 400, "invalid argument", "Cookie-Object is malformed: expiry is not u32" };
return WebDriverError { 400, "invalid argument", "Cookie-Object is malformed: expiry is not u32" };
}
expiry_time = Core::DateTime::from_timestamp(expiry_argument.as_u32());
}
@ -850,12 +850,12 @@ ErrorOr<JsonValue, HttpError> Session::add_cookie(JsonValue const& payload)
if (auto name_attribute = data.get("name"sv); name_attribute.is_string())
cookie.name = name_attribute.as_string();
else
return HttpError { 400, "invalid argument", "Expect name attribute to be string" };
return WebDriverError { 400, "invalid argument", "Expect name attribute to be string" };
if (auto value_attribute = data.get("value"sv); value_attribute.is_string())
cookie.value = value_attribute.as_string();
else
return HttpError { 400, "invalid argument", "Expect value attribute to be string" };
return WebDriverError { 400, "invalid argument", "Expect value attribute to be string" };
// Cookie path
// The value if the entry exists, otherwise "/".
@ -863,7 +863,7 @@ ErrorOr<JsonValue, HttpError> Session::add_cookie(JsonValue const& payload)
if (auto path_attribute = data.get("path"sv); path_attribute.is_string())
cookie.path = path_attribute.as_string();
else
return HttpError { 400, "invalid argument", "Expect path attribute to be string" };
return WebDriverError { 400, "invalid argument", "Expect path attribute to be string" };
} else {
cookie.path = "/";
}
@ -875,7 +875,7 @@ ErrorOr<JsonValue, HttpError> Session::add_cookie(JsonValue const& payload)
if (auto domain_attribute = data.get("domain"sv); domain_attribute.is_string())
cookie.domain = domain_attribute.as_string();
else
return HttpError { 400, "invalid argument", "Expect domain attribute to be string" };
return WebDriverError { 400, "invalid argument", "Expect domain attribute to be string" };
}
// Cookie secure only
@ -931,12 +931,12 @@ void Session::delete_cookies(Optional<StringView> const& name)
}
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
ErrorOr<JsonValue, HttpError> Session::delete_cookie(StringView const& name)
ErrorOr<JsonValue, WebDriverError> Session::delete_cookie(StringView const& name)
{
// 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts, and return its value if it is an error.
@ -948,12 +948,12 @@ ErrorOr<JsonValue, HttpError> Session::delete_cookie(StringView const& name)
}
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
ErrorOr<JsonValue, HttpError> Session::delete_all_cookies()
ErrorOr<JsonValue, WebDriverError> Session::delete_all_cookies()
{
// 1. If the current browsing context is no longer open, return error with error code no such window.
auto current_window = this->current_window();
if (!current_window.has_value())
return HttpError { 404, "no such window", "Window not found" };
return WebDriverError { 404, "no such window", "Window not found" };
// FIXME: 2. Handle any user prompts, and return its value if it is an error.

View file

@ -11,8 +11,8 @@
#include <AK/JsonValue.h>
#include <AK/RefPtr.h>
#include <WebDriver/BrowserConnection.h>
#include <WebDriver/HttpError.h>
#include <WebDriver/TimeoutsConfiguration.h>
#include <WebDriver/WebDriverError.h>
#include <unistd.h>
namespace WebDriver {
@ -39,34 +39,34 @@ public:
ErrorOr<void> start();
ErrorOr<void> stop();
JsonObject get_timeouts();
ErrorOr<JsonValue, HttpError> set_timeouts(JsonValue const& payload);
ErrorOr<JsonValue, HttpError> navigate_to(JsonValue const& url);
ErrorOr<JsonValue, HttpError> get_current_url();
ErrorOr<JsonValue, HttpError> back();
ErrorOr<JsonValue, HttpError> forward();
ErrorOr<JsonValue, HttpError> refresh();
ErrorOr<JsonValue, HttpError> get_title();
ErrorOr<JsonValue, HttpError> get_window_handle();
ErrorOr<void, Variant<HttpError, Error>> close_window();
ErrorOr<JsonValue, HttpError> get_window_handles() const;
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);
ErrorOr<JsonValue, HttpError> find_elements_from_element(JsonValue const& payload, StringView parameter_element_id);
ErrorOr<JsonValue, HttpError> get_element_attribute(JsonValue const& payload, StringView element_id, StringView name);
ErrorOr<JsonValue, HttpError> get_element_property(JsonValue const& payload, StringView element_id, StringView name);
ErrorOr<JsonValue, HttpError> get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name);
ErrorOr<JsonValue, HttpError> get_all_cookies();
ErrorOr<JsonValue, HttpError> get_named_cookie(String const& name);
ErrorOr<JsonValue, HttpError> add_cookie(JsonValue const& payload);
ErrorOr<JsonValue, HttpError> delete_cookie(StringView const& name);
ErrorOr<JsonValue, HttpError> delete_all_cookies();
ErrorOr<JsonValue, WebDriverError> set_timeouts(JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> navigate_to(JsonValue const& url);
ErrorOr<JsonValue, WebDriverError> get_current_url();
ErrorOr<JsonValue, WebDriverError> back();
ErrorOr<JsonValue, WebDriverError> forward();
ErrorOr<JsonValue, WebDriverError> refresh();
ErrorOr<JsonValue, WebDriverError> get_title();
ErrorOr<JsonValue, WebDriverError> get_window_handle();
ErrorOr<void, Variant<WebDriverError, Error>> close_window();
ErrorOr<JsonValue, WebDriverError> get_window_handles() const;
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);
ErrorOr<JsonValue, WebDriverError> find_elements_from_element(JsonValue const& payload, StringView parameter_element_id);
ErrorOr<JsonValue, WebDriverError> get_element_attribute(JsonValue const& payload, StringView element_id, StringView name);
ErrorOr<JsonValue, WebDriverError> get_element_property(JsonValue const& payload, StringView element_id, StringView name);
ErrorOr<JsonValue, WebDriverError> get_element_css_value(JsonValue const& payload, StringView element_id, StringView property_name);
ErrorOr<JsonValue, WebDriverError> get_all_cookies();
ErrorOr<JsonValue, WebDriverError> get_named_cookie(String const& name);
ErrorOr<JsonValue, WebDriverError> add_cookie(JsonValue const& payload);
ErrorOr<JsonValue, WebDriverError> delete_cookie(StringView const& name);
ErrorOr<JsonValue, WebDriverError> delete_all_cookies();
private:
void delete_cookies(Optional<StringView> const& name = {});
ErrorOr<JsonArray, HttpError> find(LocalElement const& start_node, StringView const& location_strategy, StringView const& selector);
ErrorOr<JsonArray, WebDriverError> find(LocalElement const& start_node, StringView const& location_strategy, StringView const& selector);
using ElementLocationStrategyHandler = ErrorOr<Vector<LocalElement>, HttpError> (Session::*)(LocalElement const&, StringView const&);
using ElementLocationStrategyHandler = ErrorOr<Vector<LocalElement>, WebDriverError> (Session::*)(LocalElement const&, StringView const&);
struct LocatorStrategy {
String name;
ElementLocationStrategyHandler handler;
@ -74,11 +74,11 @@ private:
static Vector<LocatorStrategy> s_locator_strategies;
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_css_selectors(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_link_text(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_partial_link_text(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_tag_name(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, HttpError> locator_strategy_x_path(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_css_selectors(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_link_text(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_partial_link_text(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_tag_name(LocalElement const&, StringView const&);
ErrorOr<Vector<LocalElement>, WebDriverError> locator_strategy_x_path(LocalElement const&, StringView const&);
NonnullRefPtr<Client> m_client;
bool m_started { false };

View file

@ -5,8 +5,8 @@
*/
#include <AK/JsonObject.h>
#include <WebDriver/HttpError.h>
#include <WebDriver/TimeoutsConfiguration.h>
#include <WebDriver/WebDriverError.h>
namespace WebDriver {
@ -35,7 +35,7 @@ JsonObject timeouts_object(TimeoutsConfiguration const& timeouts)
}
// https://w3c.github.io/webdriver/#ref-for-dfn-json-deserialize-3
ErrorOr<TimeoutsConfiguration, HttpError> json_deserialize_as_a_timeouts_configuration(JsonValue const& value)
ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_configuration(JsonValue const& value)
{
constexpr i64 max_safe_integer = 9007199254740991;
@ -44,7 +44,7 @@ ErrorOr<TimeoutsConfiguration, HttpError> json_deserialize_as_a_timeouts_configu
// 2. If value is not a JSON Object, return error with error code invalid argument.
if (!value.is_object())
return HttpError { 400, "invalid argument", "Payload is not a JSON object" };
return WebDriverError { 400, "invalid argument", "Payload is not a JSON object" };
// 3. If value has a property with the key "script":
if (value.as_object().has("script"sv)) {
@ -53,7 +53,7 @@ ErrorOr<TimeoutsConfiguration, HttpError> json_deserialize_as_a_timeouts_configu
// 2. If script duration is a number and less than 0 or greater than maximum safe integer, or it is not null, return error with error code invalid argument.
if ((script_duration.is_number() && (script_duration.to_i64() < 0 || script_duration.to_i64() > max_safe_integer)) || !script_duration.is_null())
return HttpError { 400, "invalid argument", "Invalid script duration" };
return WebDriverError { 400, "invalid argument", "Invalid script duration" };
// 3. Set timeoutss script timeout to script duration.
timeouts.script_timeout = script_duration.is_null() ? Optional<u64> {} : script_duration.to_u64();
@ -66,7 +66,7 @@ ErrorOr<TimeoutsConfiguration, HttpError> json_deserialize_as_a_timeouts_configu
// 2. If page load duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
if (!page_load_duration.is_number() || page_load_duration.to_i64() < 0 || page_load_duration.to_i64() > max_safe_integer)
return HttpError { 400, "invalid argument", "Invalid page load duration" };
return WebDriverError { 400, "invalid argument", "Invalid page load duration" };
// 3. Set timeoutss page load timeout to page load duration.
timeouts.page_load_timeout = page_load_duration.to_u64();
@ -79,7 +79,7 @@ ErrorOr<TimeoutsConfiguration, HttpError> json_deserialize_as_a_timeouts_configu
// 2. If implicit duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
if (!implicit_duration.is_number() || implicit_duration.to_i64() < 0 || implicit_duration.to_i64() > max_safe_integer)
return HttpError { 400, "invalid argument", "Invalid implicit duration" };
return WebDriverError { 400, "invalid argument", "Invalid implicit duration" };
// 3. Set timeoutss implicit wait timeout to implicit duration.
timeouts.implicit_wait_timeout = implicit_duration.to_u64();

View file

@ -6,6 +6,7 @@
#pragma once
#include "WebDriverError.h"
#include <AK/Forward.h>
#include <AK/Optional.h>
@ -19,6 +20,6 @@ struct TimeoutsConfiguration {
};
JsonObject timeouts_object(TimeoutsConfiguration const&);
ErrorOr<TimeoutsConfiguration, HttpError> json_deserialize_as_a_timeouts_configuration(JsonValue const&);
ErrorOr<TimeoutsConfiguration, WebDriverError> json_deserialize_as_a_timeouts_configuration(JsonValue const&);
}

View file

@ -11,7 +11,7 @@
namespace WebDriver {
struct HttpError {
struct WebDriverError {
unsigned http_status;
String error;
String message;
@ -20,8 +20,8 @@ struct HttpError {
}
template<>
struct AK::Formatter<WebDriver::HttpError> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, WebDriver::HttpError const& error)
struct AK::Formatter<WebDriver::WebDriverError> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, WebDriver::WebDriverError const& error)
{
return Formatter<StringView>::format(builder, String::formatted("Error {}, {}: {}", error.http_status, error.error, error.message));
}