Skip to content

Commit

Permalink
Improve WPT test coverage for CookieStore API
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D222963

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1920104
gecko-commit: df1fc10f7b4d25524907e6682d39b1e0a7b7c8d5
gecko-reviewers: edgul, smaug
  • Loading branch information
bakulf authored and moz-wptsync-bot committed Sep 24, 2024
1 parent acec99e commit 266b949
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
31 changes: 21 additions & 10 deletions cookie-store/cookieStore_getAll_arguments.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,28 @@ promise_test(async testCase => {
assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with relative url in options');

promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
if (!self.GLOBAL.isWorker()) {
promise_test(async testCase => {
const invalid_url =
`${self.location.protocol}//${self.location.host}/different/path`;
await promise_rejects_js(testCase, TypeError, cookieStore.getAll(
{ url: invalid_url }));
}, 'cookieStore.getAll with invalid url path in options');
} else {
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});

const invalid_url =
`${self.location.protocol}//${self.location.host}/different/path`;
await promise_rejects_js(testCase, TypeError, cookieStore.getAll(
{ url: invalid_url }));
}, 'cookieStore.getAll with invalid url path in options');
const sameorigin_url =
`${self.location.protocol}//${self.location.host}/different/path`;
const cookies = await cookieStore.getAll({ url: sameorigin_url });
assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, 'cookie-name');
assert_equals(cookies[0].value, 'cookie-value');
}, 'cookieStore.getAll with same-origin url path in options');
}

promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
Expand Down
20 changes: 14 additions & 6 deletions cookie-store/cookieStore_get_arguments.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,20 @@ promise_test(async testCase => {
assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with relative url in options');

promise_test(async testCase => {
const invalid_url =
`${self.location.protocol}//${self.location.host}/different/path`;
await promise_rejects_js(testCase, TypeError, cookieStore.get(
{ url: invalid_url }));
}, 'cookieStore.get with invalid url path in options');
if (!self.GLOBAL.isWorker()) {
promise_test(async testCase => {
const invalid_url =
`${self.location.protocol}//${self.location.host}/different/path`;
await promise_rejects_js(testCase, TypeError, cookieStore.get(
{ url: invalid_url }));
}, 'cookieStore.get with invalid url path in options');
} else {
promise_test(async testCase => {
const sameorigin_url =
`${self.location.protocol}//${self.location.host}/different/path`;
assert_true(await cookieStore.get({ url: sameorigin_url }) === null);
}, 'cookieStore.get with same-origin url path in options');
}

promise_test(async testCase => {
const invalid_url =
Expand Down
6 changes: 4 additions & 2 deletions cookie-store/cookieStore_in_detached_frame.https.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>cookieStore on DOMWindow of detached iframe (crbug.com/774626)</title>
<title>cookieStore on DOMWindow of detached iframe</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<link rel="author" href="[email protected]" title="Victor Costan">
<script src="/resources/testharness.js"></script>
Expand All @@ -14,6 +14,8 @@
const frameWindow = iframe.contentWindow;

iframe.parentNode.removeChild(iframe);
assert_equals(null, frameWindow.cookieStore);

// By spec, window.cookieStore isn't nullable.
assert_true(frameWindow.cookieStore != null);
});
</script>

0 comments on commit 266b949

Please sign in to comment.