mirror of
https://github.com/servo/servo
synced 2026-05-09 00:22:16 +02:00
126 lines
4.3 KiB
HTML
126 lines
4.3 KiB
HTML
<!DOCTYPE html>
|
|
<title>ExtendableEvent: waitUntil</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="resources/test-helpers.sub.js"></script>
|
|
<script>
|
|
function runTest(test, scope, onRegister) {
|
|
var script = 'resources/extendable-event-waituntil.js?' + scope;
|
|
service_worker_unregister_and_register(test, script, scope)
|
|
.then(function(registration) {
|
|
onRegister(registration.installing);
|
|
});
|
|
}
|
|
|
|
// Sends a SYN to the worker and asynchronously listens for an ACK; sets
|
|
// |obj.synced| to true once ack'd.
|
|
function syncWorker(test, worker, obj) {
|
|
var channel = new MessageChannel();
|
|
channel.port1.onmessage = test.step_func(function(e) {
|
|
var message = e.data;
|
|
assert_equals(message, 'SYNC',
|
|
'Should receive sync message from worker.');
|
|
obj.synced = true;
|
|
channel.port1.postMessage('ACK');
|
|
});
|
|
worker.postMessage({port: channel.port2}, [channel.port2]);
|
|
}
|
|
|
|
async_test(function(t) {
|
|
// Passing scope as the test switch for worker script.
|
|
var scope = 'resources/install-fulfilled';
|
|
var onRegister = function(worker) {
|
|
var obj = {};
|
|
wait_for_state(t, worker, 'installed')
|
|
.then(function() {
|
|
assert_true(
|
|
obj.synced,
|
|
'state should be "installed" after the waitUntil promise ' +
|
|
'for "oninstall" is fulfilled.');
|
|
service_worker_unregister_and_done(t, scope);
|
|
})
|
|
.catch(unreached_rejection(t));
|
|
syncWorker(t, worker, obj);
|
|
};
|
|
runTest(t, scope, onRegister);
|
|
}, 'Test install event waitUntil fulfilled');
|
|
|
|
async_test(function(t) {
|
|
var scope = 'resources/install-multiple-fulfilled';
|
|
var onRegister = function(worker) {
|
|
var obj1 = {};
|
|
var obj2 = {};
|
|
wait_for_state(t, worker, 'installed')
|
|
.then(function() {
|
|
assert_true(
|
|
obj1.synced && obj2.synced,
|
|
'state should be "installed" after all waitUntil promises ' +
|
|
'for "oninstall" are fulfilled.');
|
|
service_worker_unregister_and_done(t, scope);
|
|
})
|
|
.catch(unreached_rejection(t));
|
|
syncWorker(t, worker, obj1);
|
|
syncWorker(t, worker, obj2);
|
|
};
|
|
runTest(t, scope, onRegister);
|
|
}, 'Test ExtendableEvent multiple waitUntil fulfilled.');
|
|
|
|
async_test(function(t) {
|
|
var scope = 'resources/install-reject-precedence';
|
|
var onRegister = function(worker) {
|
|
wait_for_state(t, worker, 'redundant')
|
|
.then(function() {
|
|
service_worker_unregister_and_done(t, scope);
|
|
})
|
|
.catch(unreached_rejection(t));
|
|
};
|
|
runTest(t, scope, onRegister);
|
|
}, 'Test ExtendableEvent waitUntil reject precedence.');
|
|
|
|
async_test(function(t) {
|
|
var scope = 'resources/activate-fulfilled';
|
|
var onRegister = function(worker) {
|
|
var obj = {};
|
|
wait_for_state(t, worker, 'activating')
|
|
.then(function() {
|
|
syncWorker(t, worker, obj);
|
|
return wait_for_state(t, worker, 'activated');
|
|
})
|
|
.then(function() {
|
|
assert_true(
|
|
obj.synced,
|
|
'state should be "activated" after the waitUntil promise ' +
|
|
'for "onactivate" is fulfilled.');
|
|
service_worker_unregister_and_done(t, scope);
|
|
})
|
|
.catch(unreached_rejection(t));
|
|
};
|
|
runTest(t, scope, onRegister);
|
|
}, 'Test activate event waitUntil fulfilled');
|
|
|
|
async_test(function(t) {
|
|
var scope = 'resources/install-rejected';
|
|
var onRegister = function(worker) {
|
|
wait_for_state(t, worker, 'redundant')
|
|
.then(function() {
|
|
service_worker_unregister_and_done(t, scope);
|
|
})
|
|
.catch(unreached_rejection(t));
|
|
};
|
|
runTest(t, scope, onRegister);
|
|
}, 'Test install event waitUntil rejected');
|
|
|
|
async_test(function(t) {
|
|
var scope = 'resources/activate-rejected';
|
|
var onRegister = function(worker) {
|
|
wait_for_state(t, worker, 'activated')
|
|
.then(function() {
|
|
service_worker_unregister_and_done(t, scope);
|
|
})
|
|
.catch(unreached_rejection(t));
|
|
};
|
|
runTest(t, scope, onRegister);
|
|
}, 'Test activate event waitUntil rejected.');
|
|
|
|
</script>
|