Update web-platform-tests to revision 4a5223502fa660ce03e470af6a61c8bc26c5a8ee

This commit is contained in:
WPT Sync Bot 2018-04-23 21:13:37 -04:00
parent c5f7c9ccf3
commit e891345f26
1328 changed files with 36632 additions and 20588 deletions

View file

@ -0,0 +1,59 @@
'use strict';
// Workaround because add_cleanup doesn't support async functions yet.
// See https://github.com/w3c/web-platform-tests/issues/6075
async function async_cleanup(cleanup_function) {
try {
await cleanup_function();
} catch (e) {
// Errors in cleanup functions shouldn't result in test failures.
}
}
promise_test(async testCase => {
const inTwentyFourHours = new Date(Date.now() + 24 * 60 * 60 * 1000);
assert_equals(
await cookieStore.set(
'cookie-name', 'cookie-value', { expires: inTwentyFourHours }),
undefined);
const cookie = await cookieStore.get('cookie-name');
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.set with expires option: Date object');
promise_test(async testCase => {
const inTwentyFourHours = Date.now() + 24 * 60 * 60 * 1000;
assert_equals(
await cookieStore.set(
'cookie-name', 'cookie-value', { expires: inTwentyFourHours }),
undefined);
const cookie = await cookieStore.get('cookie-name');
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.set with expires option: milliseconds since epoch object');
promise_test(async testCase => {
const year = (new Date()).getUTCFullYear() + 1;
const date = new Date('07 Jun ' + year + ' 07:07:07 UTC');
const day = ('Sun Mon Tue Wed Thu Fri Sat'.split(' '))[date.getUTCDay()];
const nextJune = `${day}, 07 Jun ${year} + ' 07:07:07 GMT`;
assert_equals(
await cookieStore.set(
'cookie-name', 'cookie-value', { expires: nextJune }),
undefined);
const cookie = await cookieStore.get('cookie-name');
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.set with expires option: HTTP date string');

View file

@ -1,6 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>Async Cookies: cookieStore handles special cookie names correctly</title>
<title>Cookie Store: cookieStore handles special cookie names correctly</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
<script src="/resources/testharness.js"></script>
@ -8,28 +8,64 @@
<script>
'use strict';
promise_test(async testCase => {
await promise_rejects(testCase, new TypeError(), cookieStore.set(
'__Secure-cookie-name', 'secure-cookie-value'));
['__Secure-', '__Host-'].forEach(prefix => {
promise_test(async testCase => {
await promise_rejects(
testCase, new TypeError(),
cookieStore.set(`${prefix}cookie-name`, `secure-cookie-value`),
`Setting ${prefix} cookies should fail in non-secure contexts`);
try { await cookieStore.delete('__Secure-cookie-name'); } catch (e) {}
}, 'cookieStore.set with __Secure- name on insecure origin');
try { await cookieStore.delete(`${prefix}cookie-name`); } catch (e) {}
}, `cookieStore.set with ${prefix} name on non-secure origin`);
promise_test(async testCase => {
await promise_rejects(testCase, new TypeError(), cookieStore.set(
'__Host-cookie-name', 'host-cookie-value'));
promise_test(async testCase => {
await promise_rejects(
testCase, new TypeError(),
cookieStore.set(
`${prefix}cookie-name`, `secure-cookie-value`, {
expires: Date.now() - (24 * 60 * 60 * 1000)
}),
`Setting expired ${prefix} cookies should fail in non-secure contexts`);
try { await cookieStore.delete('__Host-cookie-name'); } catch (e) {}
}, 'cookieStore.set with __Host- name on insecure origin');
try { await cookieStore.delete(`${prefix}cookie-name`); } catch (e) {}
}, `cookieStore.set of expired ${prefix} cookie on non-secure origin`);
promise_test(async testCase => {
await promise_rejects(testCase, new TypeError(), cookieStore.delete(
'__Secure-cookie-name', 'secure-cookie-value'));
}, 'cookieStore.delete with __Secure- name on insecure origin');
promise_test(async testCase => {
assert_equals(
await cookieStore.get(`${prefix}cookie-name`),
null,
'get with ${prefix} prefix should not reject');
assert_equals(
await cookieStore.get({name: `${prefix}cookie-name`}),
null,
'get with ${prefix} prefix name option should not reject');
assert_equals(
await cookieStore.get({name: prefix, matchType: 'startsWith'}),
null,
'get with ${prefix} name and startsWith options should not reject');
}, `cookieStore.get with ${prefix} name on non-secure origin`);
promise_test(async testCase => {
await promise_rejects(testCase, new TypeError(), cookieStore.delete(
'__Host-cookie-name', 'host-cookie-value'));
}, 'cookieStore.delete with __Host- name on insecure origin');
promise_test(async testCase => {
assert_array_equals(
await cookieStore.getAll(`${prefix}cookie-name`),
[],
'getAll with ${prefix} prefix should not reject');
assert_array_equals(
await cookieStore.getAll({name: `${prefix}cookie-name`}),
[],
'getAll with ${prefix} prefix name option should not reject');
assert_array_equals(
await cookieStore.getAll({name: prefix, matchType: 'startsWith'}),
[],
'getAll with ${prefix} name and startsWith options should not reject');
}, `cookieStore.getAll with ${prefix} name on non-secure origin`);
promise_test(async testCase => {
await promise_rejects(
testCase, new TypeError(),
cookieStore.delete(`${prefix}cookie-name`, `host-cookie-value`),
`Deleting ${prefix} cookies should fail in non-secure contexts`);
}, `cookieStore.delete with ${prefix} name on non-secure origin`);
});
</script>

View file

@ -0,0 +1,41 @@
<!doctype html>
<meta charset="utf-8">
<title>Cookie Store: cookieStore handles special cookie names correctly (secure context)</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
['__Secure-', '__Host-'].forEach(prefix => {
promise_test(async testCase => {
await cookieStore.set(`${prefix}cookie-name`, `secure-cookie-value`);
assert_equals(
(await cookieStore.get(`${prefix}cookie-name`)).value,
'secure-cookie-value',
`Setting ${prefix} cookies should not fail in secure context`);
try { await cookieStore.delete(`${prefix}cookie-name`); } catch (e) {}
}, `cookieStore.set with ${prefix} name on secure origin`);
promise_test(async testCase => {
// This test is for symmetry with the non-secure case. In non-secure
// contexts, the set() should fail even if the expiration date makes
// the operation a no-op.
await cookieStore.set(
`${prefix}cookie-name`, `secure-cookie-value`, {
expires: Date.now() - (24 * 60 * 60 * 1000)
});
assert_equals(await cookieStore.get(`${prefix}cookie-name`), null);
try { await cookieStore.delete(`${prefix}cookie-name`); } catch (e) {}
}, `cookieStore.set of expired ${prefix} cookie name on secure origin`);
promise_test(async testCase => {
assert_equals(
await cookieStore.delete(`${prefix}cookie-name`), undefined,
`Deleting ${prefix} cookies should not fail in secure context`);
}, `cookieStore.delete with ${prefix} name on secure origin`);
});
</script>

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Cookies: expiration</title>
<meta name="help" href="https://github.com/WICG/cookie-store/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/cookie-test-helpers.js"></script>
<script src="resources/expiration.js"></script>

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Cookies: expiration (HTTPS)</title>
<meta name="help" href="https://github.com/WICG/cookie-store/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/cookie-test-helpers.js"></script>
<script src="resources/expiration.js"></script>

View file

@ -10,21 +10,38 @@
'use strict';
promise_test(async t => {
const urls = ['/interfaces/html.idl', '/interfaces/cookie-store.idl'];
const [html, cookie_store] = await Promise.all(
urls.map(url => fetch(url).then(response => response.text())));
const urls = [
'/interfaces/uievents.idl',
'/interfaces/dom.idl',
'/interfaces/html.idl',
'/interfaces/cookie-store.idl'
];
const [uievents, dom, html, cookie_store] = await Promise.all(
urls.map(url => fetch(url).then(r => r.text())));
const idl_array = new IdlArray();
// Dependencies of HTML
idl_array.add_untested_idls(dom, { only: [
'Event',
'EventInit',
'EventTarget',
'HTMLCollection',
'NodeList',
] });
idl_array.add_untested_idls('interface Document {};');
idl_array.add_untested_idls('interface Element {};');
idl_array.add_untested_idls('interface LinkStyle {};');
idl_array.add_untested_idls('interface SVGElement {};');
idl_array.add_untested_idls(html);
idl_array.add_untested_idls(uievents, { only: [
'UIEvent',
'UIEventInit',
'MouseEvent',
'MouseEventInit',
'EventModifierInit',
] });
idl_array.add_untested_idls('interface Event {};');
idl_array.add_untested_idls('dictionary EventInit {};');
idl_array.add_untested_idls('interface EventTarget {};');
idl_array.add_untested_idls(
`[Global=ServiceWorker, Exposed=ServiceWorker]
interface ServiceWorkerGlobalScope {};`);

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Cookies: One simple origin cookie</title>
<meta name="help" href="https://github.com/WICG/cookie-store/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/cookie-test-helpers.js"></script>
<script src="resources/one_simple_origin_cookie.js"></script>

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Cookies: One simple origin cookie (HTTPS)</title>
<meta name="help" href="https://github.com/WICG/cookie-store/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/cookie-test-helpers.js"></script>
<script src="resources/one_simple_origin_cookie.js"></script>

View file

@ -1,89 +0,0 @@
'use strict';
// Set the secure example.org-domain cookie __Secure-COOKIENAME with
// value cookie-value on path /cgi-bin/ and 24 hour duration; domain
// and path will be rewritten below.
//
// This uses a Date object for expiration.
async function setOneDaySecureCookieWithDate() {
// one day ahead, ignoring a possible leap-second
let inTwentyFourHours = new Date(Date.now() + 24 * 60 * 60 * 1000);
await cookieStore.set('__Secure-COOKIENAME', 'cookie-value', {
path: kPath,
expires: inTwentyFourHours,
secure: true,
domain: location.hostname
});
}
// Set the secured example.org-domain cookie __Secure-COOKIENAME with
// value cookie-value on path /cgi-bin/ and expiration in June of next
// year; domain and path will be rewritten below.
//
// This uses an HTTP-style date string for expiration.
async function setSecureCookieWithHttpLikeExpirationString() {
const year = (new Date()).getUTCFullYear() + 1;
const date = new Date('07 Jun ' + year + ' 07:07:07 UTC');
const day = ('Sun Mon Tue Wed Thu Fri Sat'.split(' '))[date.getUTCDay()];
await cookieStore.set('__Secure-COOKIENAME', 'cookie-value', {
path: kPath,
expires: day + ', 07 Jun ' + year + ' 07:07:07 GMT',
secure: true,
domain: location.hostname
});
}
// Set the unsecured example.org-domain cookie LEGACYCOOKIENAME with
// value cookie-value on path /cgi-bin/ and 24 hour duration; domain
// and path will be rewritten below.
//
// This uses milliseconds since the start of the Unix epoch for
// expiration.
async function setOneDayUnsecuredCookieWithMillisecondsSinceEpoch() {
// one day ahead, ignoring a possible leap-second
let inTwentyFourHours = Date.now() + 24 * 60 * 60 * 1000;
await cookieStore.set('LEGACYCOOKIENAME', 'cookie-value', {
path: kPath,
expires: inTwentyFourHours,
secure: false,
domain: location.hostname
});
}
// Delete the cookie written by
// setOneDayUnsecuredCookieWithMillisecondsSinceEpoch.
async function deleteUnsecuredCookieWithDomainAndPath() {
await cookieStore.delete('LEGACYCOOKIENAME', {
path: kPath,
secure: false,
domain: location.hostname
});
}
cookie_test(async testCase => {
await promise_rejects_when_unsecured(
testCase,
new TypeError(),
setOneDaySecureCookieWithDate(),
'Secure cookies only writable from secure contexts');
const eventPromise = observeNextCookieChangeEvent();
await setOneDayUnsecuredCookieWithMillisecondsSinceEpoch();
assert_equals(
await getCookieString('LEGACYCOOKIENAME'),
'LEGACYCOOKIENAME=cookie-value',
'Ensure unsecured cookie we set is visible');
await verifyCookieChangeEvent(
eventPromise,
{changed: [{name: 'LEGACYCOOKIENAME', value: 'cookie-value'}]},
'Ensure unsecured cookie we set is visible to observer');
await deleteUnsecuredCookieWithDomainAndPath();
await promise_rejects_when_unsecured(
testCase,
new TypeError(),
setSecureCookieWithHttpLikeExpirationString(),
'Secure cookies only writable from secure contexts');
}, 'expiration');

View file

@ -3,10 +3,10 @@
cookie_test(async t => {
let eventPromise = observeNextCookieChangeEvent();
await cookieStore.set('', 'first-value');
const actual1 =
(await cookieStore.getAll('')).map(({ value }) => value).join(';');
const expected1 = 'first-value';
assert_equals(actual1, expected1);
assert_equals(
(await cookieStore.getAll('')).map(({ value }) => value).join(';'),
'first-value',
'Cookie with no name and normal value should have been set');
await verifyCookieChangeEvent(
eventPromise, {changed: [{name: '', value: 'first-value'}]},
'Observed no-name change');
@ -16,31 +16,26 @@ cookie_test(async t => {
new TypeError(),
cookieStore.set('', 'suspicious-value=resembles-name-and-value'),
'Expected promise rejection when setting a cookie with' +
' no name and "=" in value');
' no name and "=" in value (via arguments)');
await promise_rejects(
t,
new TypeError(),
cookieStore.set(
{name: '', value: 'suspicious-value=resembles-name-and-value'}),
'Expected promise rejection when setting a cookie with' +
' no name and "=" in value (via options)');
const actual2 =
(await cookieStore.getAll('')).map(({ value }) => value).join(';');
const expected2 = 'first-value';
assert_equals(actual2, expected2);
assert_equals(
await getCookieString(),
(await cookieStore.getAll('')).map(({ value }) => value).join(';'),
'first-value',
'Earlier cookie jar after rejected');
'Cookie with no name should still have previous value');
eventPromise = observeNextCookieChangeEvent();
await cookieStore.delete('');
await verifyCookieChangeEvent(
eventPromise, {deleted: [{name: '', value: ''}]},
eventPromise, {deleted: [{name: ''}]},
'Observed no-name deletion');
assert_equals(
await getCookieString(),
undefined,
'Empty cookie jar after cleanup');
assert_equals(
await getCookieStringHttp(),
undefined,
'Empty HTTP cookie jar after cleanup');
}, "Verify that attempting to set a cookie with no name and with '=' in" +
" the value does not work.");

View file

@ -1,57 +0,0 @@
'use strict';
// Helper to verify first-of-name get using async/await.
//
// Returns the first script-visible value of the __Host-COOKIENAME cookie or
// undefined if no matching cookies are script-visible.
async function getOneSimpleOriginCookie() {
let cookie = await cookieStore.get('__Host-COOKIENAME');
if (!cookie) return undefined;
return cookie.value;
}
// Returns the number of script-visible cookies whose names start with
// __Host-COOKIEN
async function countMatchingSimpleOriginCookies() {
let cookieList = await cookieStore.getAll({
name: '__Host-COOKIEN',
matchType: 'startsWith'
});
return cookieList.length;
}
// Set the secure implicit-domain cookie __Host-COOKIENAME with value
// cookie-value on path / and session duration.
async function setOneSimpleOriginSessionCookie() {
await cookieStore.set('__Host-COOKIENAME', 'cookie-value');
};
cookie_test(async testCase => {
await promise_rejects_when_unsecured(
testCase,
new TypeError(),
setOneSimpleOriginSessionCookie(),
'__Host- prefix only writable from secure contexts');
if (!kIsUnsecured) {
assert_equals(
await getOneSimpleOriginCookie(),
'cookie-value',
'__Host-COOKIENAME cookie should be found in a secure context');
} else {
assert_equals(
await getOneSimpleOriginCookie(),
undefined,
'__Host-COOKIENAME cookie should not be found in an unsecured context');
}
if (kIsUnsecured) {
assert_equals(
await countMatchingSimpleOriginCookies(),
0,
'No __Host-COOKIEN* cookies should be found in an unsecured context');
} else {
assert_equals(
await countMatchingSimpleOriginCookies(),
1,
'One __Host-COOKIEN* cookie should be found in a secure context');
}
}, 'One simple origin cookie');

View file

@ -1,46 +0,0 @@
cookie_test(async t => {
const theVeryRecentPast = Date.now();
const expiredCookieSentinelValue = 'EXPIRED';
await promise_rejects_when_unsecured(
t,
new TypeError(),
cookieStore.set('__Secure-COOKIENAME', expiredCookieSentinelValue, {
path: kPath,
expires: theVeryRecentPast,
secure: true,
domain: location.hostname
}),
'Secure cookies only writable from secure contexts');
}, 'Set an already-expired secure cookie');
['__Host-', '__Secure-'].forEach(prefix => {
cookie_test(async t => {
const name = prefix + 'COOKIENAME';
const value = 'cookie-value';
await promise_rejects_when_unsecured(
t,
new TypeError(),
cookieStore.set(name, value),
`Setting ${prefix} cookies should fail in non-secure contexts`);
// Getting does not produce an exception, even in non-secure contexts.
const pair = await cookieStore.get(name);
if (kIsUnsecured) {
assert_equals(pair, null);
} else {
assert_equals(pair.value, value);
}
await promise_rejects_when_unsecured(
t,
new TypeError(),
cookieStore.delete(name),
`Deleting ${prefix} cookies should fail in non-secure contexts`);
assert_equals(await cookieStore.get(name), null);
}, `${prefix} cookies only writable from secure context`);
});

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Cookies: __Secure- and __Host- cookies</title>
<meta name="help" href="https://github.com/WICG/cookie-store/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/cookie-test-helpers.js"></script>
<script src="resources/secure_cookies.js"></script>

View file

@ -1,8 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Cookies: __Secure- and __Host- cookies (HTTPS)</title>
<meta name="help" href="https://github.com/WICG/cookie-store/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/cookie-test-helpers.js"></script>
<script src="resources/secure_cookies.js"></script>