mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
WebDriver: Put endpoint functions in spec order
This commit is contained in:
parent
eafb924580
commit
727e982c50
4 changed files with 107 additions and 107 deletions
|
@ -25,11 +25,11 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::GET, { "status" }, &Client::handle_get_status },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "url" }, &Client::handle_post_url },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "url" }, &Client::handle_get_url },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "title" }, &Client::handle_get_title },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_delete_window },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "refresh" }, &Client::handle_refresh },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "back" }, &Client::handle_back },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "forward" }, &Client::handle_forward },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "refresh" }, &Client::handle_refresh },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "title" }, &Client::handle_get_title },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_delete_window },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie" }, &Client::handle_get_all_cookies },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie", ":name" }, &Client::handle_get_named_cookie },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "cookie" }, &Client::handle_add_cookie },
|
||||
|
@ -441,6 +441,42 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_url(Vector<StringView> paramete
|
|||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
|
||||
// POST /session/{session id}/back
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_back(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/back");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::back().
|
||||
auto result = TRY(session->back());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward
|
||||
// POST /session/{session id}/forward
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_forward(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/forward");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::forward().
|
||||
auto result = TRY(session->forward());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
|
||||
// POST /session/{session id}/refresh
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_refresh(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/refresh");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::refresh().
|
||||
auto result = TRY(session->refresh());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 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> parameters, JsonValue const&)
|
||||
|
@ -467,42 +503,6 @@ ErrorOr<JsonValue, HttpError> Client::handle_delete_window(Vector<StringView> pa
|
|||
return make_json_value(JsonValue());
|
||||
}
|
||||
|
||||
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
|
||||
// POST /session/{session id}/refresh
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_refresh(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/refresh");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::refresh().
|
||||
auto result = TRY(session->refresh());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
|
||||
// POST /session/{session id}/back
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_back(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/back");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::back().
|
||||
auto result = TRY(session->back());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 10.4 Forward, https://w3c.github.io/webdriver/#dfn-forward
|
||||
// POST /session/{session id}/forward
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_forward(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/forward");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::forward().
|
||||
auto result = TRY(session->forward());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 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> parameters, JsonValue const&)
|
||||
|
|
|
@ -51,11 +51,11 @@ private:
|
|||
ErrorOr<JsonValue, HttpError> handle_get_status(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_post_url(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_url(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_title(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_delete_window(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_refresh(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_back(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_forward(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_refresh(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_title(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_delete_window(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_all_cookies(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_named_cookie(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_add_cookie(Vector<StringView>, JsonValue const& payload);
|
||||
|
|
|
@ -71,28 +71,6 @@ ErrorOr<void> Session::stop()
|
|||
return {};
|
||||
}
|
||||
|
||||
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
|
||||
ErrorOr<void, Variant<HttpError, Error>> Session::delete_window()
|
||||
{
|
||||
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
auto current_window = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return Variant<HttpError, Error>(HttpError { 404, "no such window", "Window not found" });
|
||||
|
||||
// 2. Close the current top-level browsing context.
|
||||
m_windows.remove(m_current_window_handle);
|
||||
|
||||
// 3. If there are no more open top-level browsing contexts, then close the session.
|
||||
if (m_windows.is_empty()) {
|
||||
auto result = stop();
|
||||
if (result.is_error()) {
|
||||
return Variant<HttpError, Error>(result.release_error());
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
|
||||
ErrorOr<JsonValue, HttpError> Session::post_url(JsonValue const& payload)
|
||||
{
|
||||
|
@ -146,46 +124,6 @@ ErrorOr<JsonValue, HttpError> Session::get_url()
|
|||
return JsonValue(url);
|
||||
}
|
||||
|
||||
// 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title
|
||||
ErrorOr<JsonValue, HttpError> 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 = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return HttpError { 404, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Let title be the initial value of the title IDL attribute of the current top-level browsing context's active document.
|
||||
// 4. Return success with data title.
|
||||
return JsonValue(m_browser_connection->get_title());
|
||||
}
|
||||
|
||||
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
|
||||
ErrorOr<JsonValue, HttpError> 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 = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return HttpError { 404, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Initiate an overridden reload of the current top-level browsing context’s active document.
|
||||
m_browser_connection->async_refresh();
|
||||
|
||||
// FIXME: 4. If url is special except for file:
|
||||
|
||||
// FIXME: 1. Try to wait for navigation to complete.
|
||||
|
||||
// FIXME: 2. Try to run the post-navigation checks.
|
||||
|
||||
// FIXME: 5. Set the current browsing context with current top-level browsing context.
|
||||
|
||||
// 6. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
// 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
|
||||
ErrorOr<JsonValue, HttpError> Session::back()
|
||||
{
|
||||
|
@ -232,6 +170,68 @@ ErrorOr<JsonValue, HttpError> Session::forward()
|
|||
return JsonValue();
|
||||
}
|
||||
|
||||
// 10.5 Refresh, https://w3c.github.io/webdriver/#dfn-refresh
|
||||
ErrorOr<JsonValue, HttpError> 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 = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return HttpError { 404, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Initiate an overridden reload of the current top-level browsing context’s active document.
|
||||
m_browser_connection->async_refresh();
|
||||
|
||||
// FIXME: 4. If url is special except for file:
|
||||
|
||||
// FIXME: 1. Try to wait for navigation to complete.
|
||||
|
||||
// FIXME: 2. Try to run the post-navigation checks.
|
||||
|
||||
// FIXME: 5. Set the current browsing context with current top-level browsing context.
|
||||
|
||||
// 6. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
// 10.6 Get Title, https://w3c.github.io/webdriver/#dfn-get-title
|
||||
ErrorOr<JsonValue, HttpError> 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 = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return HttpError { 404, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Let title be the initial value of the title IDL attribute of the current top-level browsing context's active document.
|
||||
// 4. Return success with data title.
|
||||
return JsonValue(m_browser_connection->get_title());
|
||||
}
|
||||
|
||||
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
|
||||
ErrorOr<void, Variant<HttpError, Error>> Session::delete_window()
|
||||
{
|
||||
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
auto current_window = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return Variant<HttpError, Error>(HttpError { 404, "no such window", "Window not found" });
|
||||
|
||||
// 2. Close the current top-level browsing context.
|
||||
m_windows.remove(m_current_window_handle);
|
||||
|
||||
// 3. If there are no more open top-level browsing contexts, then close the session.
|
||||
if (m_windows.is_empty()) {
|
||||
auto result = stop();
|
||||
if (result.is_error()) {
|
||||
return Variant<HttpError, Error>(result.release_error());
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-serialized-cookie
|
||||
static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie)
|
||||
{
|
||||
|
|
|
@ -33,13 +33,13 @@ public:
|
|||
|
||||
ErrorOr<void> start();
|
||||
ErrorOr<void> stop();
|
||||
ErrorOr<void, Variant<HttpError, Error>> delete_window();
|
||||
ErrorOr<JsonValue, HttpError> post_url(JsonValue const& url);
|
||||
ErrorOr<JsonValue, HttpError> get_url();
|
||||
ErrorOr<JsonValue, HttpError> get_title();
|
||||
ErrorOr<JsonValue, HttpError> refresh();
|
||||
ErrorOr<JsonValue, HttpError> back();
|
||||
ErrorOr<JsonValue, HttpError> forward();
|
||||
ErrorOr<JsonValue, HttpError> refresh();
|
||||
ErrorOr<JsonValue, HttpError> get_title();
|
||||
ErrorOr<void, Variant<HttpError, Error>> delete_window();
|
||||
ErrorOr<JsonValue, HttpError> get_all_cookies();
|
||||
ErrorOr<JsonValue, HttpError> get_named_cookie(String const& name);
|
||||
ErrorOr<JsonValue, HttpError> add_cookie(JsonValue const& payload);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue