blob: f70cf40931db88350c5fb0f5ebb1fbd10f917dba [file] [log] [blame]
<!DOCTYPE html>
<title>Service Worker: Interfaces</title>
<meta name="timeout" content="long">
<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 src="resources/test-helpers.sub.js"></script>
<script>
'use strict';
promise_test(async (t) => {
const srcs = ['dom', 'html', 'service-workers', 'dedicated-workers'];
const [dom, html, serviceWorkerIdl, dedicated] = await Promise.all(
srcs.map(i => fetch(`/interfaces/${i}.idl`).then(r => r.text())));
var idlArray = new IdlArray();
idlArray.add_idls(serviceWorkerIdl, { only: [
'ServiceWorkerGlobalScope',
'Client',
'WindowClient',
'Clients',
'ServiceWorker',
'ServiceWorkerState',
'ServiceWorkerUpdateViaCache',
'ServiceWorkerRegistration',
'EventTarget',
'NavigationPreloadManager',
'Cache',
'CacheStorage',
]});
idlArray.add_dependency_idls(dedicated);
idlArray.add_dependency_idls(dom);
idlArray.add_dependency_idls(html);
idlArray.add_objects({
ServiceWorkerContainer: ['navigator.serviceWorker']
});
var scope = 'resources/scope/interfaces-and-attributes';
return service_worker_unregister_and_register(
t, 'resources/empty-worker.js', scope)
.then(function(registration) {
t.add_cleanup(function() {
return registration.unregister();
});
window.registrationInstance = registration;
idlArray.add_objects({
ServiceWorkerRegistration: ['window.registrationInstance'],
ServiceWorker: ['window.registrationInstance.installing']
});
idlArray.test();
});
}, 'test setup (worker registration)');
promise_test(t => {
const url = encodeURI(`data:text/html,<!DOCTYPE html>
<script>
parent.postMessage({ isDefined: 'serviceWorker' in navigator }, '*');
</` + `script>`);
var p = new Promise((resolve, reject) => {
window.addEventListener('message', event => {
resolve(event.data.isDefined);
});
});
with_iframe(url);
return p.then(isDefined => {
assert_false(isDefined, 'navigator.serviceWorker should not be defined in iframe');
});
}, 'navigator.serviceWorker is not available in a data: iframe');
</script>