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 function scope_test(name, scope) { |
| 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 } |
7 | 16 |
8 function scope_test(name, scope) { | 17 var registration; |
9 var t = async_test('Verify the scope property: ' + name); | 18 service_worker_unregister_and_register( |
10 | 19 t, 'resources/serviceworkerglobalscope-scope-worker.js', scope) |
11 t.step(function() { | 20 .then(function(r) { |
12 var expectedScope, options; | 21 registration = r; |
13 if (scope) { | 22 assert_equals(registration.waiting, null, |
14 expectedScope = new URL(scope, document.location).toString(); | 23 'registration.waiting should be null'); |
15 } else { | 24 assert_equals(registration.active, null, |
16 expectedScope = new URL('/', document.location).toString(); | 25 'registration.active should be null'); |
17 } | 26 assert_equals(registration.installing, null, |
18 | 27 'registration.installing should be null'); |
19 service_worker_unregister_and_register( | 28 return wait_for_update(t, registration); |
20 t, 'resources/serviceworkerglobalscope-scope-worker.js', scope | 29 }) |
21 ).then( | 30 .then(function(worker) { |
22 t.step_func(function(worker) { | 31 assert_equals(registration.waiting, null, |
| 32 'registration.waiting should be null'); |
| 33 assert_equals(registration.active, null, |
| 34 'registration.active should be null'); |
| 35 assert_equals(registration.installing, worker, |
| 36 'registration.installing should not be null'); |
| 37 return new Promise(function(resolve) { |
23 var messageChannel = new MessageChannel(); | 38 var messageChannel = new MessageChannel(); |
24 messageChannel.port1.onmessage = t.step_func(function(e) { | 39 messageChannel.port1.onmessage = resolve; |
25 message = e.data; | |
26 assert_equals(message.initialScope, expectedScope, 'Worker s
hould see the scope on eval.'); | |
27 assert_equals(message.currentScope, expectedScope, 'Worker s
cope should not change.'); | |
28 service_worker_unregister_and_done(t, scope); | |
29 }); | |
30 worker.postMessage('', [messageChannel.port2]); | 40 worker.postMessage('', [messageChannel.port2]); |
31 }) | 41 }); |
32 ); | 42 }) |
| 43 .then(function(e) { |
| 44 var message = e.data; |
| 45 assert_equals(message.initialScope, expectedScope, |
| 46 'Worker should see the scope on eval.'); |
| 47 assert_equals(message.currentScope, expectedScope, |
| 48 'Worker scope should not change.'); |
| 49 service_worker_unregister_and_done(t, scope); |
| 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 scope_test('absolute url', 'http://127.0.0.1:8000/'); |
39 | 58 |
40 </script> | 59 </script> |
OLD | NEW |