From dd4e5d5028f888d9c701764d2f1ac79b33b729cc Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 18 Oct 2022 22:27:06 +0200 Subject: [PATCH] WebDriver: Make functions always match their spec command name This is easier to grasp than sometimes naming it after the HTTP method, and sometimes not. --- Userland/Services/WebDriver/Client.cpp | 28 ++++++++++++------------- Userland/Services/WebDriver/Client.h | 8 +++---- Userland/Services/WebDriver/Session.cpp | 6 +++--- Userland/Services/WebDriver/Session.h | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 13bbb7f31b..9bbd047f76 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -21,17 +21,17 @@ namespace WebDriver { Atomic Client::s_next_session_id; NonnullOwnPtrVector Client::s_sessions; Vector Client::s_routes = { - { HTTP::HttpRequest::Method::POST, { "session" }, &Client::handle_post_session }, + { HTTP::HttpRequest::Method::POST, { "session" }, &Client::handle_new_session }, { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id" }, &Client::handle_delete_session }, { 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::POST, { "session", ":session_id", "url" }, &Client::handle_navigate_to }, + { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "url" }, &Client::handle_get_current_url }, { 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::GET, { "session", ":session_id", "window" }, &Client::handle_get_window_handle }, - { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_delete_window }, + { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_close_window }, { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element" }, &Client::handle_find_element }, { 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 }, @@ -320,7 +320,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_post_session(Vector const&, JsonValue const&) +ErrorOr Client::handle_new_session(Vector const&, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session"); @@ -422,25 +422,25 @@ ErrorOr Client::handle_get_status(Vector const // 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to // POST /session/{session id}/url -ErrorOr Client::handle_post_url(Vector const& parameters, JsonValue const& payload) +ErrorOr 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])); - // NOTE: Spec steps handled in Session::post_url(). - auto result = TRY(session->post_url(payload)); + // NOTE: Spec steps handled in Session::navigate_to(). + auto result = TRY(session->navigate_to(payload)); return make_json_value(result); } // 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url // GET /session/{session id}/url -ErrorOr Client::handle_get_url(Vector const& parameters, JsonValue const&) +ErrorOr 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])); - // NOTE: Spec steps handled in Session::get_url(). - auto result = TRY(session->get_url()); + // NOTE: Spec steps handled in Session::get_current_url(). + auto result = TRY(session->get_current_url()); return make_json_value(result); } @@ -511,13 +511,13 @@ ErrorOr Client::handle_get_window_handle(Vector Client::handle_delete_window(Vector const& parameters, JsonValue const&) +ErrorOr 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])); - // NOTE: Spec steps handled in Session::delete_window(). - TRY(unwrap_result(session->delete_window())); + // NOTE: Spec steps handled in Session::close_window(). + TRY(unwrap_result(session->close_window())); return make_json_value(JsonValue()); } diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index 797bea5ee2..c3ee278353 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -46,17 +46,17 @@ private: }; ErrorOr match_route(HTTP::HttpRequest::Method method, String const& resource); - ErrorOr handle_post_session(Vector const&, JsonValue const& payload); + 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_post_url(Vector const&, JsonValue const& payload); - ErrorOr handle_get_url(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_delete_window(Vector const&, JsonValue const& payload); + ErrorOr handle_close_window(Vector const&, JsonValue const& payload); ErrorOr handle_find_element(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); diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index a8ec4d19ce..b36a5480a7 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -73,7 +73,7 @@ ErrorOr Session::stop() } // 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to -ErrorOr Session::post_url(JsonValue const& payload) +ErrorOr 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 = get_window_object(); @@ -109,7 +109,7 @@ ErrorOr Session::post_url(JsonValue const& payload) } // 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url -ErrorOr Session::get_url() +ErrorOr 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 = get_window_object(); @@ -212,7 +212,7 @@ ErrorOr Session::get_title() } // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window -ErrorOr> Session::delete_window() +ErrorOr> 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 = get_window_object(); diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index d973e937ec..91c4a4b9eb 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -37,14 +37,14 @@ public: ErrorOr start(); ErrorOr stop(); - ErrorOr post_url(JsonValue const& url); - ErrorOr get_url(); + ErrorOr navigate_to(JsonValue const& url); + ErrorOr get_current_url(); ErrorOr back(); ErrorOr forward(); ErrorOr refresh(); ErrorOr get_title(); ErrorOr find_element(JsonValue const& payload); - ErrorOr> delete_window(); + ErrorOr> close_window(); ErrorOr get_all_cookies(); ErrorOr get_named_cookie(String const& name); ErrorOr add_cookie(JsonValue const& payload);