https://github.com/web-platform-tests/wpt
Raw File
Tip revision: bf0b0da813543d6f58646c2b65a399b417a4d4ba authored by Anne van Kesteren on 11 August 2016, 12:41:28 UTC
WIP
Tip revision: bf0b0da
registration-events.https.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>
back to top