mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
WebDriver: Implement DELETE /session/{id}/cookie
endpoint
This commit is contained in:
parent
c710780852
commit
0d6dc2492d
4 changed files with 51 additions and 0 deletions
|
@ -297,4 +297,39 @@ ErrorOr<JsonValue, HttpError> Session::get_named_cookie(String const& name)
|
|||
return HttpError { 404, "no such cookie", "Cookie not found" };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-delete-cookies
|
||||
void Session::delete_cookies(Optional<StringView> const& name)
|
||||
{
|
||||
// For each cookie among all associated cookies of the current browsing context’s active document,
|
||||
// run the substeps of the first matching condition:
|
||||
for (auto& cookie : m_browser_connection->get_all_cookies()) {
|
||||
// -> name is undefined
|
||||
// -> name is equal to cookie name
|
||||
if (!name.has_value() || name.value() == cookie.name) {
|
||||
// Set the cookie expiry time to a Unix timestamp in the past.
|
||||
cookie.expiry_time = Core::DateTime::from_timestamp(0);
|
||||
m_browser_connection->async_update_cookie(cookie);
|
||||
}
|
||||
// -> Otherwise
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /session/{session id}/cookie https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
ErrorOr<JsonValue, HttpError> 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 = 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, giving no filtering argument.
|
||||
delete_cookies();
|
||||
|
||||
// 4. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue