OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>ServiceWorkerGlobalScope: scope property</title> | 2 <title>ServiceWorkerGlobalScope: scope property</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 <script> | 6 <script> |
7 | |
8 function scope_test(name, scope) { | 7 function scope_test(name, scope) { |
9 var t = async_test('Verify the scope property: ' + name); | 8 var t = async_test('Verify the scope property: ' + name); |
9 t.step(function() { | |
10 var expectedScope, options; | |
11 if (scope) { | |
12 expectedScope = new URL(scope, document.location).toString(); | |
13 } else { | |
14 expectedScope = new URL('/', document.location).toString(); | |
15 } | |
10 | 16 |
11 t.step(function() { | 17 service_worker_unregister_and_register( |
12 var expectedScope, options; | 18 t, 'resources/serviceworkerglobalscope-scope-worker.js', scope) |
13 if (scope) { | 19 .then(function(registration) { |
14 expectedScope = new URL(scope, document.location).toString(); | 20 assert_equals(registration.waiting, null, |
15 } else { | 21 'registration.waiting should be null'); |
16 expectedScope = new URL('/', document.location).toString(); | 22 assert_equals(registration.active, null, |
17 } | 23 'registration.active should be null'); |
18 | 24 assert_equals(registration.installing, null, |
19 service_worker_unregister_and_register( | 25 'registration.installing should be null'); |
20 t, 'resources/serviceworkerglobalscope-scope-worker.js', scope | 26 return new Promise(function(resolve, reject) { |
21 ).then( | 27 registration.addEventListener('updatefound', |
22 t.step_func(function(worker) { | 28 t.step_func(function() { |
23 var messageChannel = new MessageChannel(); | 29 assert_equals(registration.waiting, null, |
24 messageChannel.port1.onmessage = t.step_func(function(e) { | 30 'registration.waiting should be null'); |
25 message = e.data; | 31 assert_equals(registration.active, null, |
26 assert_equals(message.initialScope, expectedScope, 'Worker s hould see the scope on eval.'); | 32 'registration.active should be null'); |
27 assert_equals(message.currentScope, expectedScope, 'Worker s cope should not change.'); | 33 assert_true(registration.installing != null, |
falken
2014/08/14 10:16:36
assert_not_equals
nhiroki
2014/08/14 13:22:07
Comparing to the resolved worker would work. Fixed
| |
28 service_worker_unregister_and_done(t, scope); | 34 'registration.installing should not be null'); |
29 }); | 35 resolve(registration.installing); |
30 worker.postMessage('', [messageChannel.port2]); | 36 })); |
31 }) | 37 }); |
32 ); | 38 }) |
39 .then(function(worker) { | |
40 var messageChannel = new MessageChannel(); | |
41 messageChannel.port1.onmessage = t.step_func(function(e) { | |
42 var message = e.data; | |
43 assert_equals(message.initialScope, expectedScope, | |
44 'Worker should see the scope on eval.'); | |
45 assert_equals(message.currentScope, expectedScope, | |
46 'Worker scope should not change.'); | |
47 service_worker_unregister_and_done(t, scope); | |
48 }); | |
49 worker.postMessage('', [messageChannel.port2]); | |
50 }) | |
51 .catch(unreached_rejection(t)); | |
33 }); | 52 }); |
34 } | 53 } |
35 | 54 |
36 scope_test('default'); | 55 scope_test('default'); |
37 scope_test('relative path', '/a/b/c/'); | 56 scope_test('relative path', '/a/b/c/'); |
38 scope_test('absolute url', 'http://127.0.0.1:8000/'); | 57 |
58 // [BUG] Same scope test doesn't work. updatefound doesn't called. | |
nhiroki
2014/08/14 08:04:04
This would be intended behavior. unregister() coul
falken
2014/08/14 10:16:37
I'm a bit confused. What should this FIXME say?
nhiroki
2014/08/14 13:22:07
Hmmm... apparently this test is now working. Okay,
| |
59 // scope_test('absolute url', 'http://127.0.0.1:8000/'); | |
39 | 60 |
40 </script> | 61 </script> |
OLD | NEW |