Skip to content

Commit

Permalink
Implement the delete function in the Cookie Store API
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259220

Reviewed by Chris Dumez.

The delete function creates a cookie with the options given and
sets the expires field to a time in the past (we set it to the
epoch). Then it uses the Cookie Store API set function to set
this cookie so that the CFNetwork will update the existing cookies
with these options and delete them since they are expired.

* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieListItem_attributes.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_delete_arguments.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_delete_basic.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_event_delete.https.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_getAll_arguments.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_getAll_multiple.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_getAll_set_basic.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_get_arguments.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_get_delete_basic.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_get_set_across_frames.https-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_get_set_basic.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_set_arguments.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/cookie-store/cookieStore_special_names.https.any-expected.txt:
* Source/WebCore/Modules/cookie-store/CookieStore.cpp:
(WebCore::CookieStore::remove):
* Source/WebCore/Modules/cookie-store/CookieStore.h:

Canonical link: https://commits.webkit.org/266078@main
  • Loading branch information
RupinMittal committed Jul 15, 2023
1 parent bbbec87 commit 525b38f
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

FAIL CookieListItem - cookieStore.set defaults with positional name and value promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set defaults with name and value in options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with expires set to a timestamp 10 years in the future promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with expires set to a Date 10 years in the future promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with domain set to the current hostname promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with path set to the current directory promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set adds / to path if it does not end with / promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with sameSite set to strict promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with sameSite set to lax promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set with sameSite set to none promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL CookieListItem - cookieStore.set defaults with positional name and value assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set defaults with name and value in options assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with expires set to a timestamp 10 years in the future assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with expires set to a Date 10 years in the future assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with domain set to the current hostname assert_equals: expected (string) "localhost" but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with path set to the current directory assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set adds / to path if it does not end with / assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with sameSite set to strict assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with sameSite set to lax assert_equals: expected (object) null but got (undefined) undefined
FAIL CookieListItem - cookieStore.set with sameSite set to none assert_equals: expected (object) null but got (undefined) undefined

Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@

Harness Error (FAIL), message = Test named 'cookieStore.delete with name in options' specified 1 'cleanup' function, and 1 failed.

FAIL cookieStore.delete with positional name promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.delete with name in options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
NOTRUN cookieStore.delete domain starts with "."
NOTRUN cookieStore.delete with domain that is not equal current host
NOTRUN cookieStore.delete with domain set to the current hostname
NOTRUN cookieStore.delete with domain set to a subdomain of the current hostname
NOTRUN cookieStore.delete with domain set to a non-domain-matching suffix of the current hostname
NOTRUN cookieStore.delete with path set to the current directory
NOTRUN cookieStore.delete with path set to subdirectory of the current directory
NOTRUN cookieStore.delete with missing / at the end of path
NOTRUN cookieStore.delete with path that does not start with /
NOTRUN cookieStore.delete with get result
NOTRUN cookieStore.delete with positional empty name
NOTRUN cookieStore.delete with empty name in options
PASS cookieStore.delete with positional name
PASS cookieStore.delete with name in options
FAIL cookieStore.delete domain starts with "." assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.delete with domain that is not equal current host assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.delete with domain set to the current hostname assert_equals: expected null but got object "[object Object]"
FAIL cookieStore.delete with domain set to a subdomain of the current hostname assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.delete with domain set to a non-domain-matching suffix of the current hostname assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.delete with path set to the current directory assert_equals: expected null but got object "[object Object]"
PASS cookieStore.delete with path set to subdirectory of the current directory
FAIL cookieStore.delete with missing / at the end of path assert_equals: expected null but got object "[object Object]"
FAIL cookieStore.delete with path that does not start with / assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.delete with get result assert_equals: expected null but got object "[object Object]"
FAIL cookieStore.delete with positional empty name promise_test: Unhandled rejection with value: object "TypeError: Type error"
FAIL cookieStore.delete with empty name in options promise_test: Unhandled rejection with value: object "TypeError: Type error"

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL cookieStore.delete return type is Promise<void> promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.delete return type is Promise<void>

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Harness Error (FAIL), message = Test named 'cookieStore fires change event for cookie deleted by cookieStore.delete()' specified 1 'cleanup' function, and 1 failed.
Harness Error (TIMEOUT), message = null

FAIL cookieStore fires change event for cookie deleted by cookieStore.delete() promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
TIMEOUT cookieStore fires change event for cookie deleted by cookieStore.delete() Test timed out

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Harness Error (FAIL), message = Test named 'cookieStore.getAll with no arguments' specified 2 'cleanup' functions, and 2 failed.

FAIL cookieStore.getAll with no arguments promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
NOTRUN cookieStore.getAll with empty options
NOTRUN cookieStore.getAll with positional name
NOTRUN cookieStore.getAll with name in options
NOTRUN cookieStore.getAll with name in both positional arguments and options
NOTRUN cookieStore.getAll with absolute url in options
NOTRUN cookieStore.getAll with relative url in options
NOTRUN cookieStore.getAll with invalid url path in options
NOTRUN cookieStore.getAll with invalid url host in options
FAIL cookieStore.getAll with empty options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.getAll with positional name promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.getAll with name in options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.getAll with name in both positional arguments and options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.getAll with absolute url in options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.getAll with relative url in options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.getAll with invalid url path in options promise_rejects_js: function "function() { throw e }" threw object "NotSupportedError: The operation is not supported." ("NotSupportedError") expected instance of function "function TypeError() {
[native code]
}" ("TypeError")
FAIL cookieStore.getAll with invalid url host in options promise_rejects_js: function "function() { throw e }" threw object "NotSupportedError: The operation is not supported." ("NotSupportedError") expected instance of function "function TypeError() {
[native code]
}" ("TypeError")

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

Harness Error (FAIL), message = Test named 'cookieStore.getAll returns multiple cookies written by cookieStore.set' specified 3 'cleanup' functions, and 3 failed.

FAIL cookieStore.getAll returns multiple cookies written by cookieStore.set promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

Harness Error (FAIL), message = Test named 'cookieStore.getAll returns the cookie written by cookieStore.set' specified 1 'cleanup' function, and 1 failed.

FAIL cookieStore.getAll returns the cookie written by cookieStore.set promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

Harness Error (FAIL), message = Test named 'cookieStore.get with no arguments returns TypeError' specified 1 'cleanup' function, and 1 failed.

FAIL cookieStore.get with no arguments returns TypeError assert_unreached: Should have rejected: undefined Reached unreachable code
NOTRUN cookieStore.get with empty options returns TypeError
NOTRUN cookieStore.get with positional name
NOTRUN cookieStore.get with name in options
NOTRUN cookieStore.get with name in both positional arguments and options
NOTRUN cookieStore.get with absolute url in options
NOTRUN cookieStore.get with relative url in options
NOTRUN cookieStore.get with invalid url path in options
NOTRUN cookieStore.get with invalid url host in options
FAIL cookieStore.get with empty options returns TypeError assert_unreached: Should have rejected: undefined Reached unreachable code
PASS cookieStore.get with positional name
PASS cookieStore.get with name in options
PASS cookieStore.get with name in both positional arguments and options
PASS cookieStore.get with absolute url in options
PASS cookieStore.get with relative url in options
FAIL cookieStore.get with invalid url path in options assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.get with invalid url host in options assert_unreached: Should have rejected: undefined Reached unreachable code

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

Harness Error (FAIL), message = Test named 'cookieStore.get returns null for a cookie deleted by cookieStore.delete' specified 1 'cleanup' function, and 1 failed.

FAIL cookieStore.get returns null for a cookie deleted by cookieStore.delete promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.get returns null for a cookie deleted by cookieStore.delete

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

Harness Error (FAIL), message = Test named 'cookieStore.get() sees cookieStore.set() in frame' specified 1 'cleanup' function, and 1 failed.

FAIL cookieStore.get() sees cookieStore.set() in frame promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'frameCookie.value')"
NOTRUN cookieStore.get() in frame sees cookieStore.set()
FAIL cookieStore.get() in frame sees cookieStore.set() promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'cookie.value')"

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

Harness Error (FAIL), message = Test named 'cookieStore.get returns the cookie written by cookieStore.set' specified 1 'cleanup' function, and 1 failed.

PASS cookieStore.get returns the cookie written by cookieStore.set

Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@

Harness Error (FAIL), message = Test named 'cookieStore.set with get result' specified 1 'cleanup' function, and 1 failed.

FAIL cookieStore.set with positional name and value promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with name and value in options promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.set with positional name and value
PASS cookieStore.set with name and value in options
PASS cookieStore.set with empty name and an '=' in value
FAIL cookieStore.set with normal name and an '=' in value promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with expires set to a future Date promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with expires set to a past Date promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with expires set to a future timestamp promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with expires set to a past timestamp promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.set with normal name and an '=' in value
PASS cookieStore.set with expires set to a future Date
PASS cookieStore.set with expires set to a past Date
PASS cookieStore.set with expires set to a future timestamp
PASS cookieStore.set with expires set to a past timestamp
FAIL cookieStore.set domain starts with "." assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.set with domain that is not equal current host assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.set with domain set to the current hostname promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.set with domain set to the current hostname
FAIL cookieStore.set with domain set to a subdomain of the current hostname assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.set with domain set to a non-domain-matching suffix of the current hostname assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.set default domain is null and differs from current hostname promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with path set to the current directory promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set with path set to a subdirectory of the current directory promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.set with path set to the current directory
FAIL cookieStore.set with path set to a subdirectory of the current directory assert_equals: expected null but got object "[object Object]"
FAIL cookieStore.set default path is / promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set adds / to path that does not end with / promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
FAIL cookieStore.set adds / to path that does not end with / assert_equals: expected (string) "/cookie-store/" but got (undefined) undefined
FAIL cookieStore.set with path that does not start with / assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.set with get result assert_equals: expected "old-cookie-value" but got "cookie-value"

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

FAIL cookieStore.set with __Secure- name on secure origin promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating '(await cookieStore.get(`${prefix}cookie-name`)).value')"
PASS cookieStore.set of expired __Secure- cookie name on secure origin
FAIL cookieStore.delete with __Secure- name on secure origin promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.delete with __Secure- name on secure origin
FAIL cookieStore.set with __Host- name on secure origin promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating '(await cookieStore.get(`${prefix}cookie-name`)).value')"
PASS cookieStore.set of expired __Host- cookie name on secure origin
FAIL cookieStore.delete with __Host- name on secure origin promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
PASS cookieStore.delete with __Host- name on secure origin
FAIL cookieStore.set with __Host- prefix and a domain option assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL cookieStore.set with __Host- prefix a path option promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating '(await cookieStore.get(`__Host-cookie-name`)).value')"
PASS cookieStore.set with malformed name.
Expand Down
33 changes: 29 additions & 4 deletions Source/WebCore/Modules/cookie-store/CookieStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <wtf/CompletionHandler.h>
#include <wtf/IsoMallocInlines.h>
#include <wtf/Ref.h>
#include <wtf/Seconds.h>
#include <wtf/URL.h>
#include <wtf/Vector.h>
#include <wtf/WallTime.h>
Expand Down Expand Up @@ -192,14 +193,38 @@ void CookieStore::set(CookieInit&& options, Ref<DeferredPromise>&& promise)
cookieJar.setCookieAsync(document, url, cookie, WTFMove(completionHandler));
}

void CookieStore::remove(const String&, Ref<DeferredPromise>&& promise)
void CookieStore::remove(String&& name, Ref<DeferredPromise>&& promise)
{
promise->reject(NotSupportedError);
remove(CookieStoreDeleteOptions { WTFMove(name), { } }, WTFMove(promise));
}

void CookieStore::remove(CookieStoreDeleteOptions&&, Ref<DeferredPromise>&& promise)
void CookieStore::remove(CookieStoreDeleteOptions&& options, Ref<DeferredPromise>&& promise)
{
promise->reject(NotSupportedError);
auto* context = scriptExecutionContext();
if (!context) {
promise->reject(SecurityError);
return;
}

auto* origin = context->securityOrigin();
if (!origin) {
promise->reject(SecurityError);
return;
}

if (origin->isOpaque()) {
promise->reject(Exception { SecurityError, "The origin is opaque"_s });
return;
}

CookieInit initOptions;
initOptions.name = WTFMove(options.name);
initOptions.value = emptyString();
initOptions.domain = WTFMove(options.domain);
initOptions.path = WTFMove(options.path);
initOptions.expires = (WallTime::now() - 24_h).secondsSinceEpoch().milliseconds();

set(WTFMove(initOptions), WTFMove(promise));
}

const char* CookieStore::activeDOMObjectName() const
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/cookie-store/CookieStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CookieStore final : public RefCounted<CookieStore>, public EventTarget, pu
void set(String&& name, String&& value, Ref<DeferredPromise>&&);
void set(CookieInit&&, Ref<DeferredPromise>&&);

void remove(const String& name, Ref<DeferredPromise>&&);
void remove(String&& name, Ref<DeferredPromise>&&);
void remove(CookieStoreDeleteOptions&&, Ref<DeferredPromise>&&);

using RefCounted::ref;
Expand Down

0 comments on commit 525b38f

Please sign in to comment.