1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

WebDriver: Implement GET /session/{id}/cookie/{name} endpoint

This commit is contained in:
Tobias Christiansen 2022-10-15 19:22:20 +02:00 committed by Linus Groh
parent b6f101f1c0
commit a34f8c444b
7 changed files with 56 additions and 0 deletions

View file

@ -273,4 +273,28 @@ ErrorOr<JsonValue, HttpError> Session::get_all_cookies()
return JsonValue(cookies);
}
// GET /session/{session id}/cookie/{name} https://w3c.github.io/webdriver/#dfn-get-named-cookie
ErrorOr<JsonValue, HttpError> 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 = 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. If the url variable name is equal to a cookies cookie name amongst all associated cookies of the
// current browsing contexts active document, return success with the serialized cookie as data.
auto maybe_cookie = m_browser_connection->get_named_cookie(name);
if (maybe_cookie.has_value()) {
auto cookie = maybe_cookie.release_value();
auto serialized_cookie = serialize_cookie(cookie);
return JsonValue(serialized_cookie);
}
// 4. Otherwise, return error with error code no such cookie.
return HttpError { 404, "no such cookie", "Cookie not found" };
}
}