Commit 47ccc9c4 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

Cookie Store: Improve plumbing for idlharness tests.

Bug: 729800
Change-Id: Iff06269a032bf22de79b84508c923fe3215c07ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852326
Commit-Queue: Victor Costan <pwnall@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704915}
parent 6bc241b3
// META: global=!default,serviceworker,window
// META: timeout=long
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
'use strict';
// https://wicg.github.io/cookie-store/
idl_test(
['cookie-store'],
['service-workers', 'html', 'dom'],
async (idl_array, t) => {
const isServiceWorker = 'ServiceWorkerGlobalScope' in self
&& self instanceof ServiceWorkerGlobalScope;
if (isServiceWorker) {
idl_array.add_objects({
ExtendableCookieChangeEvent: [
'new ExtendableCookieChangeEvent("cookiechange")'],
ServiceWorkerGlobalScope: ['self'],
});
} else {
const registration = await service_worker_unregister_and_register(
t, 'resources/empty_sw.js', 'resources/does/not/exist');
t.add_cleanup(() => registration.unregister());
// Global property referenced by idl_array.add_objects().
self.registration = registration;
idl_array.add_objects({
CookieChangeEvent: ['new CookieChangeEvent("change")'],
Window: ['self'],
});
}
idl_array.add_objects({
CookieStore: ['self.cookieStore'],
CookieStoreManager: ['self.registration.cookies'],
ServiceWorkerRegistration: ['self.registration'],
});
}
);
<!doctype html>
<meta charset="utf-8">
<title>Async Cookies: IDL tests</title>
<link rel="help" href="https://github.com/WICG/cookie-store"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<script>
'use strict';
idl_test(
['cookie-store'],
['SVG', 'service-workers', 'uievents', 'html', 'dom'],
idl_array => {
idl_array.add_objects({
CookieStore: ['cookieStore'],
CookieChangeEvent: ['new CookieChangeEvent("change")'],
});
}
);
</script>
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
};
importScripts('/resources/testharness.js',
'/resources/WebIDLParser.js',
'/resources/idlharness.js');
promise_test(async t => {
const urls = ['/interfaces/cookie-store.idl'];
const [cookie_store] = await Promise.all(
urls.map(url => fetch(url).then(response => response.text())));
const idl_array = new IdlArray();
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 {};`);
idl_array.add_untested_idls(
`[Global=ServiceWorker, Exposed=ServiceWorker]
interface ServiceWorkerGlobalScope {};`);
idl_array.add_untested_idls(
`[Global=Window, Exposed=Window]
interface Window {};`);
idl_array.add_idls(cookie_store);
idl_array.add_objects({
CookieStore: ["self.cookieStore"],
ExtendableCookieChangeEvent: [
"new ExtendableCookieChangeEvent('cookiechange')"],
});
idl_array.test();
}, 'Interface test');
done();
<!doctype html>
<meta charset="utf-8">
<title>Async Cookies: ServiceWorker IDL tests</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
(async () => {
const scope = 'does/not/exist';
let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
'idlharness_serviceworker.js', {scope});
fetch_tests_from_worker(registration.installing);
})();
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment