OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Activation occurs after registration</title> | 2 <title>Service Worker: Current on load</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 var t = async_test('activation occurs after registration'); | 8 var t = async_test('current is set for a controlled document'); |
9 t.step(function() { | 9 t.step(function() { |
10 var scope = 'resources/blank.html'; | 10 var scope = 'resources/blank.html' |
11 navigator.serviceWorker.unregister(scope).then( | 11 navigator.serviceWorker.unregister(scope).then( |
12 doTest, | 12 doTest, |
13 unreached_rejection(t, 'Unregister should not fail') | 13 unreached_rejection(t, 'Unregister should not fail') |
14 ); | 14 ); |
15 | 15 |
16 function doTest() { | 16 function doTest() { |
17 navigator.serviceWorker.register( | 17 navigator.serviceWorker.register( |
18 'resources/worker-no-op.js', {scope: scope} | 18 'resources/worker-no-op.js', {scope: scope} |
19 ).then(t.step_func(onRegister), t.step_func(function(reason) { | 19 ).then( |
20 assert_unreached('Registration should succeed, but failed: ' + reaso
n.name); | 20 onRegister, |
| 21 unreached_rejection(t, 'Registration should succeed, but failed') |
| 22 ); |
| 23 } |
| 24 |
| 25 function onRegister(worker) { |
| 26 worker.addEventListener('statechange', t.step_func(function(event) { |
| 27 if (event.target.state == 'active') |
| 28 onActive(); |
21 })); | 29 })); |
22 } | 30 } |
23 | 31 |
24 function onRegister(worker) { | 32 function onActive() { |
25 assert_equals(worker.state, 'parsed', 'worker should be in the "parsed"
state upon registration'); | 33 with_iframe(scope, t.step_func(function(frame) { |
26 worker.addEventListener('statechange', t.step_func(function(event) { | 34 var w = frame.contentWindow; |
27 if (event.target.state == 'active') | 35 assert_true(w.navigator.serviceWorker.current instanceof w.ServiceWo
rker, |
28 t.done(); | 36 'current should be a ServiceWorker object'); |
| 37 t.done(); |
29 })); | 38 })); |
30 } | 39 } |
31 }); | 40 }); |
32 </script> | 41 </script> |
33 </body> | 42 </body> |
OLD | NEW |