Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / registration-end-to-end.html
blob4845afb91f0827827df46d32dc9268a7f488c220
1 <!DOCTYPE html>
2 <title>Service Worker: registration end-to-end</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script>
6 <script>
7 var t = async_test('Registration: end-to-end');
8 t.step(function() {
10 var scope = 'resources/in-scope/';
11 var serviceWorkerStates = [];
12 var lastServiceWorkerState = '';
13 var receivedMessageFromPort = '';
14 var currentChangeCount = 0;
16 assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer);
17 assert_equals(typeof navigator.serviceWorker.register, 'function');
18 assert_equals(typeof navigator.serviceWorker.getRegistration, 'function');
20 navigator.serviceWorker.oncurrentchange = function() {
21 ++currentChangeCount;
24 service_worker_unregister_and_register(
25 t, 'resources/end-to-end-worker.js', scope)
26 .then(onRegister)
27 .catch(unreached_rejection(t));
29 function sendMessagePort(worker, from) {
30 var messageChannel = new MessageChannel();
31 worker.postMessage({from:from, port:messageChannel.port2}, [messageChannel.port2]);
32 return messageChannel.port1;
35 function onRegister(registration) {
36 var sw = registration.installing;
37 serviceWorkerStates.push(sw.state);
38 lastServiceWorkerState = sw.state;
40 var sawMessage = new Promise(t.step_func(function(resolve) {
41 sendMessagePort(sw, 'registering doc').onmessage = t.step_func(function (e) {
42 receivedMessageFromPort = e.data;
43 resolve();
44 });
45 }));
47 var sawActive = new Promise(t.step_func(function(resolve) {
48 sw.onstatechange = t.step_func(function() {
49 serviceWorkerStates.push(sw.state);
51 switch (sw.state) {
52 case 'installed':
53 assert_equals(lastServiceWorkerState, 'installing');
54 break;
55 case 'activating':
56 assert_equals(lastServiceWorkerState, 'installed');
57 break;
58 case 'activated':
59 assert_equals(lastServiceWorkerState, 'activating');
60 break;
61 default:
62 // We won't see 'redundant' because onstatechange is
63 // overwritten before calling unregister.
64 assert_unreached('Unexpected state: ' + sw.state);
67 lastServiceWorkerState = sw.state;
68 if (sw.state === 'activated')
69 resolve();
70 });
71 }));
73 Promise.all([sawMessage, sawActive]).then(t.step_func(function() {
74 assert_array_equals(serviceWorkerStates,
75 ['installing', 'installed', 'activating', 'activated'],
76 'Service worker should pass through all states');
78 assert_equals(currentChangeCount, 0,
79 'Should not see current changes since document is out of scope');
81 assert_equals(receivedMessageFromPort, 'Ack for: registering doc');
83 var sawRedundant = new Promise(t.step_func(function(resolve) {
84 sw.onstatechange = t.step_func(function() {
85 assert_equals(sw.state, 'redundant');
86 resolve();
87 });
88 }));
89 registration.unregister();
90 sawRedundant.then(t.step_func(function() {
91 t.done();
92 }));
93 }));
95 });
96 </script>