mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 16:28:38 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
|
|
@ -0,0 +1,96 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Service Worker: registration end-to-end</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: end-to-end');
|
||||
t.step(function() {
|
||||
|
||||
var scope = 'resources/in-scope/';
|
||||
var serviceWorkerStates = [];
|
||||
var lastServiceWorkerState = '';
|
||||
var receivedMessageFromPort = '';
|
||||
var currentChangeCount = 0;
|
||||
|
||||
assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer);
|
||||
assert_equals(typeof navigator.serviceWorker.register, 'function');
|
||||
assert_equals(typeof navigator.serviceWorker.getRegistration, 'function');
|
||||
|
||||
navigator.serviceWorker.oncurrentchange = function() {
|
||||
++currentChangeCount;
|
||||
};
|
||||
|
||||
service_worker_unregister_and_register(
|
||||
t, 'resources/end-to-end-worker.js', scope)
|
||||
.then(onRegister)
|
||||
.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(registration) {
|
||||
var sw = registration.installing;
|
||||
serviceWorkerStates.push(sw.state);
|
||||
lastServiceWorkerState = sw.state;
|
||||
|
||||
var sawMessage = new Promise(t.step_func(function(resolve) {
|
||||
sendMessagePort(sw, 'registering doc').onmessage = t.step_func(function (e) {
|
||||
receivedMessageFromPort = e.data;
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
|
||||
var sawActive = new Promise(t.step_func(function(resolve) {
|
||||
sw.onstatechange = t.step_func(function() {
|
||||
serviceWorkerStates.push(sw.state);
|
||||
|
||||
switch (sw.state) {
|
||||
case 'installed':
|
||||
assert_equals(lastServiceWorkerState, 'installing');
|
||||
break;
|
||||
case 'activating':
|
||||
assert_equals(lastServiceWorkerState, 'installed');
|
||||
break;
|
||||
case 'activated':
|
||||
assert_equals(lastServiceWorkerState, 'activating');
|
||||
break;
|
||||
default:
|
||||
// We won't see 'redundant' because onstatechange is
|
||||
// overwritten before calling unregister.
|
||||
assert_unreached('Unexpected state: ' + sw.state);
|
||||
}
|
||||
|
||||
lastServiceWorkerState = sw.state;
|
||||
if (sw.state === 'activated')
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
|
||||
Promise.all([sawMessage, sawActive]).then(t.step_func(function() {
|
||||
assert_array_equals(serviceWorkerStates,
|
||||
['installing', 'installed', 'activating', 'activated'],
|
||||
'Service worker should pass through all states');
|
||||
|
||||
assert_equals(currentChangeCount, 0,
|
||||
'Should not see current changes since document is out of scope');
|
||||
|
||||
assert_equals(receivedMessageFromPort, 'Ack for: registering doc');
|
||||
|
||||
var sawRedundant = new Promise(t.step_func(function(resolve) {
|
||||
sw.onstatechange = t.step_func(function() {
|
||||
assert_equals(sw.state, 'redundant');
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
registration.unregister();
|
||||
sawRedundant.then(t.step_func(function() {
|
||||
t.done();
|
||||
}));
|
||||
}));
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue