Update web-platform-tests to revision 81962ac8802223d038b188b6f9cb88a0a9c5beee

This commit is contained in:
WPT Sync Bot 2018-05-18 22:02:29 -04:00
parent fe1a057bd1
commit 24183668c4
1960 changed files with 29853 additions and 10555 deletions

View file

@ -42,6 +42,11 @@ promise_test(async t => {
'EventModifierInit',
] });
idl_array.add_untested_idls(
`dictionary ExtendableEventInit {};`);
idl_array.add_untested_idls(
`[Global=ExtendableEvent, Exposed=ServiceWorker]
interface ExtendableEvent : Event {};`);
idl_array.add_untested_idls(
`[Global=ServiceWorker, Exposed=ServiceWorker]
interface ServiceWorkerGlobalScope {};`);

View file

@ -16,8 +16,12 @@ promise_test(async t => {
idl_array.add_untested_idls(
`[Global=Event, Exposed=ServiceWorker]
interface Event {};`);
idl_array.add_untested_idls(
`[Global=ExtendableEvent, Exposed=ServiceWorker]
interface ExtendableEvent : Event {};`);
idl_array.add_untested_idls('dictionary EventHandler {};');
idl_array.add_untested_idls('dictionary EventInit {};');
idl_array.add_untested_idls('dictionary ExtendableEventInit {};');
idl_array.add_untested_idls(
`[Global=EventTarget, Exposed=ServiceWorker]
interface EventTarget {};`);
@ -32,7 +36,8 @@ promise_test(async t => {
idl_array.add_objects({
CookieStore: [self.cookieStore],
CookieChangeEvent: [new CookieChangeEvent('change')],
ExtendableCookieChangeEvent: [
new ExtendableCookieChangeEvent('cookiechange')],
});
idl_array.test();
}, 'Interface test');

View file

@ -0,0 +1,113 @@
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
};
importScripts("/resources/testharness.js");
self.addEventListener('install', (event) => {
event.waitUntil((async () => {
// The subscribeToChanges calls are not done in parallel on purpose. Having
// multiple in-flight requests introduces failure modes aside from the
// cookie change logic that this test aims to cover.
await cookieStore.subscribeToChanges([
{ name: 'cookie-name1', matchType: 'equals', url: '/scope/path1' }]);
await cookieStore.subscribeToChanges([
{ }, // Test the default values for subscription properties.
{ name: 'cookie-prefix', matchType: 'startsWith' },
]);
})());
});
// 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.
}
}
// Resolves when the service worker receives the 'activate' event.
const kServiceWorkerActivatedPromise = new Promise(resolve => {
self.addEventListener('activate', event => { resolve(); });
});
// sort() comparator that uses the < operator.
//
// This is intended to be used for sorting strings. Using < is preferred to
// localeCompare() because the latter has some implementation-dependent
// behavior.
function CompareStrings(a, b) {
return a < b ? -1 : (b < a ? 1 : 0);
}
promise_test(async testCase => {
await kServiceWorkerActivatedPromise;
const subscriptions = await cookieStore.getChangeSubscriptions();
assert_equals(subscriptions.length, 3);
subscriptions.sort((a, b) => CompareStrings(`${a.name}`, `${b.name}`));
assert_equals(subscriptions[0].name, 'cookie-name1');
assert_equals('equals', subscriptions[0].matchType);
assert_equals(subscriptions[1].name, 'cookie-prefix');
assert_equals('startsWith', subscriptions[1].matchType);
assert_false('name' in subscriptions[2]);
assert_equals('startsWith', subscriptions[2].matchType);
}, 'getChangeSubscriptions returns subscriptions passed to subscribeToChanges');
promise_test(async testCase => {
promise_rejects(
testCase, new TypeError(),
cookieStore.subscribeToChanges([{ name: 'cookie-name2' }]));
}, 'subscribeToChanges rejects when called outside the install handler');
// Accumulates cookiechange events dispatched to the service worker.
let g_cookie_changes = [];
// Resolved when a cookiechange event is received. Rearmed by
// ResetCookieChangeReceivedPromise().
let g_cookie_change_received_promise = null;
let g_cookie_change_received_promise_resolver = null;
self.addEventListener('cookiechange', (event) => {
g_cookie_changes.push(event);
if (g_cookie_change_received_promise_resolver)
g_cookie_change_received_promise_resolver();
});
function RearmCookieChangeReceivedPromise() {
g_cookie_change_received_promise = new Promise((resolve) => {
g_cookie_change_received_promise_resolver = resolve;
});
}
RearmCookieChangeReceivedPromise();
promise_test(async testCase => {
await kServiceWorkerActivatedPromise;
await cookieStore.set('cookie-name', 'cookie-value');
await g_cookie_change_received_promise;
assert_equals(g_cookie_changes.length, 1);
const event = g_cookie_changes[0]
assert_equals(event.type, 'cookiechange');
assert_equals(event.changed.length, 1);
assert_equals(event.changed[0].name, 'cookie-name');
assert_equals(event.changed[0].value, 'cookie-value');
assert_equals(event.deleted.length, 0);
assert_true(event instanceof ExtendableCookieChangeEvent);
assert_true(event instanceof ExtendableEvent);
await async_cleanup(() => {
cookieStore.delete('cookie-name');
g_cookie_changes = [];
RearmCookieChangeReceivedPromise();
});
}, 'cookiechange dispatched with cookie change that matches subscription');
done();

View file

@ -0,0 +1,22 @@
<!doctype html>
<meta charset="utf-8">
<title>Async Cookies: cookie change events in ServiceWorker</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';
(async () => {
const scope = 'scope';
let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_subscriptions.js', {scope});
fetch_tests_from_worker(registration.installing);
})();
</script>

View file

@ -0,0 +1,63 @@
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
};
importScripts("/resources/testharness.js");
self.addEventListener('install', (event) => {
event.waitUntil((async () => {
cookieStore.subscribeToChanges([
{ name: 'cookie-name', matchType: 'equals', url: '/scope/path' }]);
})());
});
// 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.
}
}
// Resolves when the service worker receives the 'activate' event.
const kServiceWorkerActivatedPromise = new Promise(resolve => {
self.addEventListener('activate', event => { resolve(); });
});
promise_test(async testCase => {
await kServiceWorkerActivatedPromise;
const subscriptions = await cookieStore.getChangeSubscriptions();
assert_equals(subscriptions.length, 1);
assert_equals(subscriptions[0].name, 'cookie-name');
assert_equals('equals', subscriptions[0].matchType);
}, 'getChangeSubscriptions returns a subscription passed to subscribeToChanges');
promise_test(async testCase => {
await kServiceWorkerActivatedPromise;
cookie_change_received_promise = new Promise((resolve) => {
self.addEventListener('cookiechange', (event) => {
resolve(event);
});
});
await cookieStore.set('cookie-name', 'cookie-value');
const event = await cookie_change_received_promise;
assert_equals(event.type, 'cookiechange');
assert_equals(event.changed.length, 1);
assert_equals(event.changed[0].name, 'cookie-name');
assert_equals(event.changed[0].value, 'cookie-value');
assert_equals(event.deleted.length, 0);
assert_true(event instanceof ExtendableCookieChangeEvent);
assert_true(event instanceof ExtendableEvent);
await async_cleanup(() => { cookieStore.delete('cookie-name'); });
}, 'cookiechange dispatched with cookie change that matches subscription');
done();

View file

@ -0,0 +1,22 @@
<!doctype html>
<meta charset="utf-8">
<title>Async Cookies: cookie change events in ServiceWorker</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';
(async () => {
const scope = 'scope';
let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_subscriptions_basic.js', {scope});
fetch_tests_from_worker(registration.installing);
})();
</script>