mirror of
https://github.com/ManchildProductions/UXP-Fixed.git
synced 2026-06-20 21:28:57 +00:00
38 lines
1.3 KiB
HTML
38 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<title>Service Worker: registration events</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="resources/test-helpers.sub.js"></script>
|
|
<script>
|
|
var t = async_test('Registration: events');
|
|
t.step(function() {
|
|
var scope = 'resources/in-scope/';
|
|
service_worker_unregister_and_register(
|
|
t, 'resources/events-worker.js', scope)
|
|
.then(t.step_func(function(registration) {
|
|
onRegister(registration.installing);
|
|
}))
|
|
.catch(unreached_rejection(t));
|
|
|
|
function sendMessagePort(worker, from) {
|
|
var messageChannel = new MessageChannel();
|
|
worker.postMessage({from:from, port:messageChannel.port2}, [messageChannel.port2]);
|
|
return messageChannel.port1;
|
|
}
|
|
|
|
function onRegister(sw) {
|
|
sw.onstatechange = t.step_func(function() {
|
|
if (sw.state !== 'activated')
|
|
return;
|
|
|
|
sendMessagePort(sw, 'registering doc').onmessage = t.step_func(function (e) {
|
|
assert_array_equals(e.data.events,
|
|
['install', 'activate'],
|
|
'Worker should see install then activate events');
|
|
service_worker_unregister_and_done(t, scope);
|
|
});
|
|
});
|
|
}
|
|
});
|
|
</script>
|