Chromium Code Reviews| 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 return new Promise(function(resolve, reject) { |
| 15 } else { | 21 assert_equals(registration.waiting, null, |
| 16 expectedScope = new URL('/', document.location).toString(); | 22 'registration.waiting shuold be null'); |
|
falken
2014/08/14 04:46:12
typo: "shuold" (and below)
horo
2014/08/14 07:11:46
Done.
| |
| 17 } | 23 assert_equals(registration.active, null, |
| 18 | 24 'registration.active shuold be null'); |
| 19 service_worker_unregister_and_register( | 25 assert_equals(registration.installing, null, |
| 20 t, 'resources/serviceworkerglobalscope-scope-worker.js', scope | 26 'registration.installing shuold be null'); |
| 21 ).then( | 27 registration.addEventListener('updatefound', t.step_func(function( ) { |
|
falken
2014/08/14 04:46:12
this should use wait_for_update()
horo
2014/08/14 07:11:47
We can't test (registration.waiting/active == null
falken
2014/08/14 10:16:36
You can save registration in a global:
var regist
nhiroki
2014/08/14 13:22:07
Done.
| |
| 22 t.step_func(function(worker) { | 28 assert_equals(registration.waiting , null, |
|
falken
2014/08/14 04:46:12
nit: extra space before , (and below)
horo
2014/08/14 07:11:46
Done.
| |
| 23 var messageChannel = new MessageChannel(); | 29 'registration.waiting shuld be null'); |
|
falken
2014/08/14 04:46:12
typo: "shuld"
horo
2014/08/14 07:11:47
Done.
| |
| 24 messageChannel.port1.onmessage = t.step_func(function(e) { | 30 assert_equals(registration.active , null, |
| 25 message = e.data; | 31 'registration.active should be null'); |
| 26 assert_equals(message.initialScope, expectedScope, 'Worker s hould see the scope on eval.'); | 32 assert_true(registration.installing != null, |
| 27 assert_equals(message.currentScope, expectedScope, 'Worker s cope should not change.'); | 33 'registration.installing should not be null'); |
| 28 service_worker_unregister_and_done(t, scope); | 34 resolve(registration.installing); |
| 29 }); | 35 })); |
| 30 worker.postMessage('', [messageChannel.port2]); | 36 }); |
| 31 }) | 37 }) |
| 32 ); | 38 .then(function(worker) { |
| 39 var messageChannel = new MessageChannel(); | |
| 40 messageChannel.port1.onmessage = t.step_func(function(e) { | |
| 41 message = e.data; | |
|
falken
2014/08/14 04:46:12
nit: var
horo
2014/08/14 07:11:47
Done.
| |
| 42 assert_equals(message.initialScope, expectedScope, | |
| 43 'Worker should see the scope on eval.'); | |
| 44 assert_equals(message.currentScope, expectedScope, | |
| 45 'Worker scope should not change.'); | |
| 46 service_worker_unregister_and_done(t, scope); | |
| 47 }); | |
| 48 worker.postMessage('', [messageChannel.port2]); | |
| 49 }) | |
| 50 .catch(unreached_rejection(t)); | |
| 33 }); | 51 }); |
| 34 } | 52 } |
| 35 | 53 |
| 36 scope_test('default'); | 54 scope_test('default'); |
| 37 scope_test('relative path', '/a/b/c/'); | 55 scope_test('relative path', '/a/b/c/'); |
| 38 scope_test('absolute url', 'http://127.0.0.1:8000/'); | 56 |
| 57 // [BUG] Same scope test doesn't work. updatefound doesn't called. | |
|
falken
2014/08/14 04:46:12
nit: FIXME, not [BUG] (but please link to a bug if
horo
2014/08/14 07:11:47
removed.
| |
| 58 // scope_test('absolute url', 'http://127.0.0.1:8000/'); | |
| 39 | 59 |
| 40 </script> | 60 </script> |
| OLD | NEW |