summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2022-10-16 19:55:47 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-17 11:31:30 +0200
commitfefe447cf567ac95514c7e36d10185610172b023 (patch)
tree62f0e7c85adce4e0e63e762a0c487076d1f9ce58 /Userland/Services
parent0d6dc2492d24a76be8f91b47f21a18d51850b660 (diff)
downloadserenity-fefe447cf567ac95514c7e36d10185610172b023.zip
WebDriver: Implement `DELETE /session/{id}/cookie/{name}` endpoint
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WebDriver/Client.cpp12
-rw-r--r--Userland/Services/WebDriver/Client.h1
-rw-r--r--Userland/Services/WebDriver/Session.cpp17
-rw-r--r--Userland/Services/WebDriver/Session.h1
4 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp
index 5105486b08..cb2ede70a8 100644
--- a/Userland/Services/WebDriver/Client.cpp
+++ b/Userland/Services/WebDriver/Client.cpp
@@ -32,6 +32,7 @@ Vector<Client::Route> Client::s_routes = {
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "forward" }, &Client::handle_forward },
{ 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::DELETE, { "session", ":session_id", "cookie", ":name" }, &Client::handle_delete_cookie },
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie" }, &Client::handle_delete_all_cookies },
};
@@ -515,6 +516,17 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_named_cookie(Vector<StringView>
return make_json_value(cookies);
}
+// DELETE /session/{session id}/cookie/{name} https://w3c.github.io/webdriver/#dfn-delete-cookie
+ErrorOr<JsonValue, HttpError> Client::handle_delete_cookie(Vector<StringView> parameters, JsonValue const&)
+{
+ dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie/<name>");
+ Session* session = TRY(find_session_with_id(parameters[0]));
+
+ // NOTE: Spec steps handled in Session::delete_cookie().
+ auto result = TRY(session->delete_cookie(parameters[1]));
+ return make_json_value(result);
+}
+
// DELETE /session/{session id}/cookie https://w3c.github.io/webdriver/#dfn-delete-all-cookies
ErrorOr<JsonValue, HttpError> Client::handle_delete_all_cookies(Vector<StringView> parameters, JsonValue const&)
{
diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h
index 88209927bc..2b50bb6631 100644
--- a/Userland/Services/WebDriver/Client.h
+++ b/Userland/Services/WebDriver/Client.h
@@ -58,6 +58,7 @@ private:
ErrorOr<JsonValue, HttpError> handle_forward(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_delete_cookie(Vector<StringView>, JsonValue const& payload);
ErrorOr<JsonValue, HttpError> handle_delete_all_cookies(Vector<StringView>, JsonValue const& payload);
ErrorOr<Session*, HttpError> find_session_with_id(StringView session_id);
diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp
index a7dde357ae..5f2456b3c1 100644
--- a/Userland/Services/WebDriver/Session.cpp
+++ b/Userland/Services/WebDriver/Session.cpp
@@ -315,6 +315,23 @@ void Session::delete_cookies(Optional<StringView> const& name)
}
}
+// DELETE /session/{session id}/cookie/{name} https://w3c.github.io/webdriver/#dfn-delete-cookie
+ErrorOr<JsonValue, HttpError> 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 = 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. Delete cookies using the url variable name parameter as the filter argument.
+ delete_cookies(name);
+
+ // 4. Return success with data null.
+ return JsonValue();
+}
+
// DELETE /session/{session id}/cookie https://w3c.github.io/webdriver/#dfn-delete-all-cookies
ErrorOr<JsonValue, HttpError> Session::delete_all_cookies()
{
diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h
index 802824e05a..4dfa61c299 100644
--- a/Userland/Services/WebDriver/Session.h
+++ b/Userland/Services/WebDriver/Session.h
@@ -42,6 +42,7 @@ public:
ErrorOr<JsonValue, HttpError> forward();
ErrorOr<JsonValue, HttpError> get_all_cookies();
ErrorOr<JsonValue, HttpError> get_named_cookie(String const& name);
+ ErrorOr<JsonValue, HttpError> delete_cookie(StringView const& name);
ErrorOr<JsonValue, HttpError> delete_all_cookies();
private: