mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:47:45 +00:00
Browser+WebContent+WebDriver: Move Delete Cookie to WebContent
This commit is contained in:
parent
d202999853
commit
b7f21bb92e
7 changed files with 43 additions and 18 deletions
|
@ -27,6 +27,7 @@ endpoint WebDriverClient {
|
|||
get_all_cookies() => (Web::WebDriver::Response response)
|
||||
get_named_cookie(String name) => (Web::WebDriver::Response response)
|
||||
add_cookie(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
delete_cookie(String name) => (Web::WebDriver::Response response)
|
||||
take_screenshot() => (Web::WebDriver::Response response)
|
||||
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -975,6 +975,21 @@ Messages::WebDriverClient::AddCookieResponse WebDriverConnection::add_cookie(Jso
|
|||
return make_success_response({});
|
||||
}
|
||||
|
||||
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
|
||||
Messages::WebDriverClient::DeleteCookieResponse WebDriverConnection::delete_cookie(String const& name)
|
||||
{
|
||||
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
||||
TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// 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 make_success_response({});
|
||||
}
|
||||
|
||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
|
||||
{
|
||||
|
@ -1138,4 +1153,23 @@ ErrorOr<WebDriverConnection::ScriptArguments, Web::WebDriver::Error> WebDriverCo
|
|||
return ScriptArguments { move(script), move(arguments) };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-delete-cookies
|
||||
void WebDriverConnection::delete_cookies(Optional<StringView> const& name)
|
||||
{
|
||||
// For each cookie among all associated cookies of the current browsing context’s active document, un the substeps of the first matching condition:
|
||||
auto* document = m_page_host.page().top_level_browsing_context().active_document();
|
||||
|
||||
for (auto& cookie : m_web_content_client.did_request_all_cookies(document->url())) {
|
||||
// -> 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_web_content_client.async_did_update_cookie(document->url(), cookie);
|
||||
}
|
||||
// -> Otherwise
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ private:
|
|||
virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override;
|
||||
virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
||||
virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override;
|
||||
virtual Messages::WebDriverClient::DeleteCookieResponse delete_cookie(String const& name) override;
|
||||
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
||||
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
||||
|
||||
|
@ -73,6 +74,7 @@ private:
|
|||
JS::MarkedVector<JS::Value> arguments;
|
||||
};
|
||||
ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JsonValue const& payload);
|
||||
void delete_cookies(Optional<StringView> const& name = {});
|
||||
|
||||
ConnectionFromClient& m_web_content_client;
|
||||
PageHost& m_page_host;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue