Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: LayoutTests/http/tests/serviceworker/minimal-end-to-end.html

Issue 238993003: ServiceWorker: "minimal" end-to-end sample as a W3C test (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Clarify registration promise chain Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Service Worker: minimal end-to-end</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/support.js"></script>
6 <script>
7 var t = async_test('Minimal end-to-end registration');
8 t.step(function() {
9
10 var stateChanges = recordStateChanges();
11 var serviceWorkerStates = [];
12 var lastServiceWorkerState = '';
13 var receivedMessageFromPort = '';
14 var receivedMessage = '';
15
16 assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer);
17 assert_equals(typeof navigator.serviceWorker.register, 'function');
18 assert_equals(typeof navigator.serviceWorker.unregister, 'function');
19
20 // This always tests fresh registration, so unregister it first.
21
22 // FIXME: This currently hits an ASSERT.
23 //navigator.serviceWorker.unregister('/scope/*').then(
24 Promise.resolve().then(
25 // FIXME: Use a variant of step_func here to catch test bugs.
26 function() {
27 return navigator.serviceWorker.register(
28 'resources/end-to-end-worker.js',
29 {scope: '/scope/*'});
30 }
31 ).then(
32 t.step_func(onRegister)
33 ).catch(
34 fail(t, 'Registration failed')
35 );
36
37 function onRegister(serviceWorker) {
38 serviceWorkerStates.push(serviceWorker.state);
39 lastServiceWorkerState = serviceWorker.state;
40
41 sendMessagePort(serviceWorker, 'registering doc').onmessage = t.step_fun c(function (e) {
42 if (e.data === 'ping')
43 serviceWorker.postMessage('pong');
44 else
45 receivedMessageFromPort = e.data;
46 });
47
48 serviceWorker.onstatechange = t.step_func(function() {
49 serviceWorkerStates.push(serviceWorker.state);
50
51 switch (serviceWorker.state) {
52 case 'installed':
53 assert_equals(lastServiceWorkerState, 'installing');
54 break;
55 case 'activating':
56 assert_equals(lastServiceWorkerState, 'installed');
57 break;
58 case 'active':
59 assert_equals(lastServiceWorkerState, 'activating');
60 break;
61 default:
62 fail(t, 'Unexpected state: ' + serviceWorker.state);
63 }
64
65 lastServiceWorkerState = serviceWorker.state;
66 if (serviceWorker.state === 'active')
67 finishTest();
68 });
69 }
70
71 window.onmessage = t.step_func(function(e) {
72 receivedMessage = e.message;
73 });
74
75 function finishTest() {
76 assert_equals(receivedMessageFromPort, 'Ack for: registering doc');
77 //assert_equals(receivedMessage, 'Ack for: registering doc');
78
79 assert_array_equals(serviceWorkerStates,
80 ['installing', 'installed', 'activating', 'active'],
81 'Service worker should pass through four states');
82 assert_equals(stateChanges.pendingStateChangeCount, 0,
83 'Out-of-scope document should not see pending state change s');
84 assert_equals(stateChanges.activeStateChangeCount, 0,
85 'Out-of-scope document should not see pending state change s');
kinuko 2014/04/16 03:28:38 I think we can remove the latter two asserts for n
jsbell 2014/04/16 17:04:19 Done.
86 t.done();
87 }
88 });
89 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698