| OLD | NEW |
| 1 function scope_test(t, worker_url, scope) { | 1 function scope_test(t, worker_url, scope) { |
| 2 var expectedScope, options; | 2 var expectedScope, options; |
| 3 if (scope) { | 3 if (scope) { |
| 4 expectedScope = new URL(scope, document.location).toString(); | 4 expectedScope = new URL(scope, document.location).toString(); |
| 5 } else { | 5 } else { |
| 6 expectedScope = new URL('/', document.location).toString(); | 6 expectedScope = new URL('/', document.location).toString(); |
| 7 } | 7 } |
| 8 | 8 |
| 9 var registration; | 9 var registration; |
| 10 var options = scope ? {scope: scope} : {}; | 10 var options = scope ? {scope: scope} : {}; |
| 11 service_worker_unregister(t, scope) | 11 service_worker_unregister(t, scope) |
| 12 .then(function() { | 12 .then(function() { |
| 13 return navigator.serviceWorker.register(worker_url, options); | 13 return navigator.serviceWorker.register(worker_url, options); |
| 14 }) | 14 }) |
| 15 .then(function(r) { | 15 .then(function(r) { |
| 16 registration = r; | 16 registration = r; |
| 17 return wait_for_update(t, registration); | 17 var worker = r.installing; |
| 18 }) | |
| 19 .then(function(worker) { | |
| 20 return new Promise(function(resolve) { | 18 return new Promise(function(resolve) { |
| 21 var messageChannel = new MessageChannel(); | 19 var messageChannel = new MessageChannel(); |
| 22 messageChannel.port1.onmessage = resolve; | 20 messageChannel.port1.onmessage = resolve; |
| 23 worker.postMessage('', [messageChannel.port2]); | 21 worker.postMessage('', [messageChannel.port2]); |
| 24 }); | 22 }); |
| 25 }) | 23 }) |
| 26 .then(function(e) { | 24 .then(function(e) { |
| 27 var message = e.data; | 25 var message = e.data; |
| 28 assert_equals(message.initialScope, expectedScope, | 26 assert_equals(message.initialScope, expectedScope, |
| 29 'Worker should see the scope on eval.'); | 27 'Worker should see the scope on eval.'); |
| 30 assert_equals(message.currentScope, expectedScope, | 28 assert_equals(message.currentScope, expectedScope, |
| 31 'Worker scope should not change.'); | 29 'Worker scope should not change.'); |
| 32 return registration.unregister(); | 30 return registration.unregister(); |
| 33 }) | 31 }) |
| 34 .then(function() { | 32 .then(function() { |
| 35 t.done(); | 33 t.done(); |
| 36 }) | 34 }) |
| 37 .catch(unreached_rejection(t)); | 35 .catch(unreached_rejection(t)); |
| 38 } | 36 } |
| OLD | NEW |