зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1469261 [wpt PR 11546] - Async Cookies: Expose additional cookie attributes., a=testonly
Automatic update from web-platform-testsAsync Cookies: Expose additional cookie attributes. This CL exposes the following attributes in CookieListItem members returned by cookieStore.get() and cookieStore.getAll(), and contained in cookie change events. * expires: "expiry-time" attribute * domain: "domain" attribute, or null for host-only cookies * path: "path" attribute * secure: "secure-only-flag" attribute The "same-site-flag" attribute will be exposed in a future CL that will also add support for setting it. The following attributes are not exposed intentionally. * "creation-time", "last-access-time": no clear use case * "persistent-flag": exposed implicitly as a null expiration time * "host-only-flag": exposed implicitly as a null domain * "http-only-flag": would always be false This CL also fully implements setting a cookie's domain attribute, and updates the relevant WPT tests. CookieListItem is covered by the API explainer: https://wicg.github.io/cookie-store/explainer.html Cookie attributes are described in the cookie storage model: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-5.4 Bug: 729800 Change-Id: I8061f20d348b53ba8d0dabbd4b97564f6c3b4217 Reviewed-on: https://chromium-review.googlesource.com/1102339 Commit-Queue: Victor Costan <pwnall@chromium.org> Reviewed-by: Joshua Bell <jsbell@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#568972} -- wpt-commits: 9392f67e3db464b3f5de73b900e125306a758221 wpt-pr: 11546
This commit is contained in:
Родитель
7e0361f74a
Коммит
f872e7fe9a
|
@ -315395,6 +315395,12 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"cookie-store/cookieListItem_attributes.tentative.window.js": [
|
||||
[
|
||||
"/cookie-store/cookieListItem_attributes.tentative.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"cookie-store/cookieStore_delete_arguments.tentative.window.js": [
|
||||
[
|
||||
"/cookie-store/cookieStore_delete_arguments.tentative.window.html",
|
||||
|
@ -439556,8 +439562,12 @@
|
|||
"40595162d15dec7e315ef16f94646045596d7b1c",
|
||||
"support"
|
||||
],
|
||||
"cookie-store/cookieListItem_attributes.tentative.window.js": [
|
||||
"7d89e9ee77bad065c75bdb4f3467852dbf256b09",
|
||||
"testharness"
|
||||
],
|
||||
"cookie-store/cookieStore_delete_arguments.tentative.window.js": [
|
||||
"a2a3b036e62ed11e8013f7e255bbc418576dd451",
|
||||
"740fccd53713d8ffdd84aa388580630025fc016c",
|
||||
"testharness"
|
||||
],
|
||||
"cookie-store/cookieStore_delete_basic.tentative.window.js": [
|
||||
|
@ -439613,7 +439623,7 @@
|
|||
"testharness"
|
||||
],
|
||||
"cookie-store/cookieStore_set_arguments.tentative.window.js": [
|
||||
"33e7ed082d0e461147eb01dfabf305022952401f",
|
||||
"86cdff2d6d564eef090342adb3d41c0b1e1c4513",
|
||||
"testharness"
|
||||
],
|
||||
"cookie-store/cookieStore_set_expires_option.tentative.window.js": [
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
'use strict';
|
||||
|
||||
// Workaround because add_cleanup doesn't support async functions yet.
|
||||
// See https://github.com/web-platform-tests/wpt/issues/6075
|
||||
async function async_cleanup(cleanup_function) {
|
||||
try {
|
||||
await cleanup_function();
|
||||
} catch (e) {
|
||||
// Errors in cleanup functions shouldn't result in test failures.
|
||||
}
|
||||
}
|
||||
|
||||
const kCurrentHostname = (new URL(self.location.href)).hostname;
|
||||
const kIsSecureTransport = (new URL(self.location.href)).protocol === 'https:';
|
||||
|
||||
const kOneDay = 24 * 60 * 60 * 1000;
|
||||
const kTenYears = 10 * 365 * kOneDay;
|
||||
const kTenYearsFromNow = Date.now() + kTenYears;
|
||||
|
||||
promise_test(async testCase => {
|
||||
await cookieStore.delete('cookie-name');
|
||||
|
||||
await cookieStore.set('cookie-name', 'cookie-value');
|
||||
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
assert_equals(cookie.domain, null);
|
||||
assert_equals(cookie.path, '/');
|
||||
assert_equals(cookie.expires, null);
|
||||
assert_equals(cookie.secure, kIsSecureTransport);
|
||||
|
||||
await async_cleanup(() => cookieStore.delete('cookie-name'));
|
||||
}, 'cookieStore.set defaults with positional name and value');
|
||||
|
||||
promise_test(async testCase => {
|
||||
await cookieStore.delete('cookie-name');
|
||||
|
||||
await cookieStore.set({ name: 'cookie-name', value: 'cookie-value' });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
assert_equals(cookie.domain, null);
|
||||
assert_equals(cookie.path, '/');
|
||||
assert_equals(cookie.expires, null);
|
||||
assert_equals(cookie.secure, kIsSecureTransport);
|
||||
|
||||
await async_cleanup(() => cookieStore.delete('cookie-name'));
|
||||
}, 'cookieStore.set defaults with name and value in options');
|
||||
|
||||
promise_test(async testCase => {
|
||||
await cookieStore.delete('cookie-name');
|
||||
|
||||
await cookieStore.set('cookie-name', 'cookie-value',
|
||||
{ expires: kTenYearsFromNow });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
assert_equals(cookie.domain, null);
|
||||
assert_equals(cookie.path, '/');
|
||||
assert_approx_equals(cookie.expires, kTenYearsFromNow, kOneDay);
|
||||
assert_equals(cookie.secure, kIsSecureTransport);
|
||||
|
||||
await async_cleanup(() => cookieStore.delete('cookie-name'));
|
||||
}, 'cookieStore.set with expires set to 10 years in the future');
|
||||
|
||||
promise_test(async testCase => {
|
||||
await cookieStore.delete('cookie-name');
|
||||
|
||||
await cookieStore.set({ name: 'cookie-name', value: 'cookie-value',
|
||||
expires: kTenYearsFromNow });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
assert_equals(cookie.domain, null);
|
||||
assert_equals(cookie.path, '/');
|
||||
assert_approx_equals(cookie.expires, kTenYearsFromNow, kOneDay);
|
||||
assert_equals(cookie.secure, kIsSecureTransport);
|
||||
|
||||
await async_cleanup(() => cookieStore.delete('cookie-name'));
|
||||
}, 'cookieStore.set with name and value in options and expires in the future');
|
||||
|
||||
promise_test(async testCase => {
|
||||
await cookieStore.delete('cookie-name', { domain: kCurrentHostname });
|
||||
|
||||
await cookieStore.set('cookie-name', 'cookie-value',
|
||||
{ domain: kCurrentHostname });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
assert_equals(cookie.domain, kCurrentHostname);
|
||||
assert_equals(cookie.path, '/');
|
||||
assert_equals(cookie.expires, null);
|
||||
assert_equals(cookie.secure, kIsSecureTransport);
|
||||
|
||||
await async_cleanup(async () => {
|
||||
await cookieStore.delete('cookie-name', { domain: kCurrentHostname });
|
||||
});
|
||||
}, 'cookieStore.set with domain set to the current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
const currentPath = currentUrl.pathname;
|
||||
const currentDirectory =
|
||||
currentPath.substr(0, currentPath.lastIndexOf('/') + 1);
|
||||
await cookieStore.delete('cookie-name', { path: currentDirectory });
|
||||
|
||||
await cookieStore.set('cookie-name', 'cookie-value',
|
||||
{ path: currentDirectory });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
assert_equals(cookie.domain, null);
|
||||
assert_equals(cookie.path, currentDirectory);
|
||||
assert_equals(cookie.expires, null);
|
||||
assert_equals(cookie.secure, kIsSecureTransport);
|
||||
|
||||
await async_cleanup(async () => {
|
||||
await cookieStore.delete('cookie-name', { path: currentDirectory });
|
||||
});
|
||||
}, 'cookieStore.set with path set to the current directory');
|
|
@ -86,19 +86,23 @@ promise_test(async testCase => {
|
|||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
const subDomain = `sub.${currentDomain}`;
|
||||
await cookieStore.set(
|
||||
'cookie-name', 'cookie-value', { domain: currentDomain });
|
||||
|
||||
await cookieStore.delete('cookie-name', { domain: subDomain });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
|
||||
await async_cleanup(async () => {
|
||||
await cookieStore.delete('cookie-name', { domain: currentDomain })
|
||||
});
|
||||
await promise_rejects(testCase, new TypeError(), cookieStore.delete(
|
||||
'cookie-name', 'cookie-value', { domain: subDomain }));
|
||||
}, 'cookieStore.delete with domain set to a subdomain of the current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
assert_not_equals(currentDomain[0] === '.',
|
||||
'this test assumes that the current hostname does not start with .');
|
||||
const domainSuffix = currentDomain.substr(1);
|
||||
|
||||
await promise_rejects(testCase, new TypeError(), cookieStore.delete(
|
||||
'cookie-name', { domain: domainSuffix }));
|
||||
}, 'cookieStore.delete with domain set to a non-domain-matching suffix of ' +
|
||||
'the current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
|
@ -119,20 +123,23 @@ promise_test(async testCase => {
|
|||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
const subDomain = `sub.${currentDomain}`;
|
||||
await cookieStore.set(
|
||||
'cookie-name', 'cookie-value', { domain: currentDomain });
|
||||
|
||||
await cookieStore.delete({ name: 'cookie-name', domain: subDomain });
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie.name, 'cookie-name');
|
||||
assert_equals(cookie.value, 'cookie-value');
|
||||
|
||||
await async_cleanup(async () => {
|
||||
await cookieStore.delete('cookie-name', { domain: currentDomain })
|
||||
});
|
||||
await promise_rejects(testCase, new TypeError(), cookieStore.delete(
|
||||
{ name: 'cookie-name', domain: subDomain }));
|
||||
}, 'cookieStore.delete with name in options and domain set to a subdomain of ' +
|
||||
'the current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
assert_not_equals(currentDomain[0] === '.',
|
||||
'this test assumes that the current hostname does not start with .');
|
||||
const domainSuffix = currentDomain.substr(1);
|
||||
|
||||
await promise_rejects(testCase, new TypeError(), cookieStore.delete(
|
||||
{ name: 'cookie-name', domain: domainSuffix }));
|
||||
}, 'cookieStore.delete with name in options and domain set to a ' +
|
||||
'non-domain-matching suffix of the current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
|
|
|
@ -129,38 +129,51 @@ promise_test(async testCase => {
|
|||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
const subDomain = `sub.${currentDomain}`;
|
||||
await cookieStore.delete('cookie-name', { domain: currentDomain });
|
||||
await cookieStore.delete('cookie-name', { domain: subDomain });
|
||||
|
||||
await cookieStore.set(
|
||||
'cookie-name', 'cookie-value', { domain: subDomain });
|
||||
await promise_rejects(testCase, new TypeError(), cookieStore.set(
|
||||
'cookie-name', 'cookie-value', { domain: subDomain }));
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie, null);
|
||||
|
||||
await async_cleanup(async () => {
|
||||
await cookieStore.delete('cookie-name', { domain: subDomain });
|
||||
});
|
||||
}, 'cookieStore.set with domain set to a subdomain of the current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
assert_not_equals(currentDomain[0] === '.',
|
||||
'this test assumes that the current hostname does not start with .');
|
||||
const domainSuffix = currentDomain.substr(1);
|
||||
|
||||
await promise_rejects(testCase, new TypeError(), cookieStore.set(
|
||||
'cookie-name', 'cookie-value', { domain: domainSuffix }));
|
||||
const cookie = await cookieStore.get('cookie-name');
|
||||
assert_equals(cookie, null);
|
||||
}, 'cookieStore.set with domain set to a non-domain-matching suffix of the ' +
|
||||
'current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
const currentDomain = currentUrl.hostname;
|
||||
await cookieStore.delete('cookie-name');
|
||||
|
||||
await cookieStore.set('cookie-name', 'cookie-old-value');
|
||||
await cookieStore.set(
|
||||
'cookie-name', 'cookie-new-value', { domain: currentDomain });
|
||||
await cookieStore.set('cookie-name', 'cookie-value1');
|
||||
await cookieStore.set('cookie-name', 'cookie-value2',
|
||||
{ domain: currentDomain });
|
||||
|
||||
const cookies = await cookieStore.getAll('cookie-name');
|
||||
assert_equals(cookies.length, 1);
|
||||
assert_equals(cookies.length, 2);
|
||||
|
||||
assert_equals(cookies[0].name, 'cookie-name');
|
||||
assert_equals(cookies[0].value, 'cookie-new-value');
|
||||
assert_equals(cookies[1].name, 'cookie-name');
|
||||
|
||||
const values = cookies.map((cookie) => cookie.value);
|
||||
values.sort();
|
||||
assert_array_equals(values, ['cookie-value1', 'cookie-value2']);
|
||||
|
||||
await async_cleanup(async () => {
|
||||
await cookieStore.delete('cookie-name');
|
||||
await cookieStore.delete('cookie-name', { domain: currentDomain });
|
||||
});
|
||||
}, 'cookieStore.set default domain is current hostname');
|
||||
}, 'cookieStore.set default domain is null and differs from current hostname');
|
||||
|
||||
promise_test(async testCase => {
|
||||
const currentUrl = new URL(self.location.href);
|
||||
|
|
Загрузка…
Ссылка в новой задаче