| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>ServiceWorkerGlobalScope: registration</title> | 2 <title>ServiceWorkerGlobalScope: registration</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 | 7 |
| 8 promise_test(function(t) { | 8 promise_test(function(t) { |
| 9 var script = 'resources/registration-attribute-worker.js'; | 9 var script = 'resources/registration-attribute-worker.js'; |
| 10 var scope = 'resources/scope/registration-attribute'; | 10 var scope = 'resources/scope/registration-attribute'; |
| 11 | 11 |
| 12 return service_worker_unregister_and_register(t, script, scope) | 12 return service_worker_unregister_and_register(t, script, scope) |
| 13 .then(function(registration) { | 13 .then(function(registration) { |
| 14 add_completion_callback(function() { registration.unregister(); }); |
| 14 return wait_for_state(t, registration.installing, 'activated'); | 15 return wait_for_state(t, registration.installing, 'activated'); |
| 15 }) | 16 }) |
| 16 .then(function() { return with_iframe(scope); }) | 17 .then(function() { return with_iframe(scope); }) |
| 17 .then(function(frame) { | 18 .then(function(frame) { |
| 18 var expected_events_seen = [ | 19 var expected_events_seen = [ |
| 19 'updatefound', | 20 'updatefound', |
| 20 'install', | 21 'install', |
| 21 'statechange(installed)', | 22 'statechange(installed)', |
| 22 'statechange(activating)', | 23 'statechange(activating)', |
| 23 'activate', | 24 'activate', |
| 24 'statechange(activated)', | 25 'statechange(activated)', |
| 25 'fetch', | 26 'fetch', |
| 26 ]; | 27 ]; |
| 27 | 28 |
| 28 assert_equals( | 29 assert_equals( |
| 29 frame.contentDocument.body.textContent, | 30 frame.contentDocument.body.textContent, |
| 30 expected_events_seen.toString(), | 31 expected_events_seen.toString(), |
| 31 'Service Worker should respond to fetch'); | 32 'Service Worker should respond to fetch'); |
| 32 frame.remove(); | 33 frame.remove(); |
| 33 return service_worker_unregister_and_done(t, scope); | |
| 34 }); | 34 }); |
| 35 }, 'Verify registration attribute on ServiceWorkerGlobalScope'); | 35 }, 'Verify registration attributes on ServiceWorkerGlobalScope'); |
| 36 |
| 37 promise_test(function(t) { |
| 38 var script = 'resources/registration-attribute-worker.js'; |
| 39 var newer_script = 'resources/registration-attribute-newer-worker.js'; |
| 40 var scope = 'resources/scope/registration-attribute'; |
| 41 var newer_worker; |
| 42 |
| 43 return service_worker_unregister_and_register(t, script, scope) |
| 44 .then(function(registration) { |
| 45 add_completion_callback(function() { registration.unregister(); }); |
| 46 return wait_for_state(t, registration.installing, 'activated'); |
| 47 }) |
| 48 .then(function() { |
| 49 return navigator.serviceWorker.register(newer_script, {scope: scope}); |
| 50 }) |
| 51 .then(function(registration) { |
| 52 newer_worker = registration.installing; |
| 53 return wait_for_state(t, registration.installing, 'activated'); |
| 54 }) |
| 55 .then(function() { |
| 56 var channel = new MessageChannel; |
| 57 var saw_message = new Promise(function(resolve) { |
| 58 channel.port1.onmessage = function(e) { resolve(e.data); }; |
| 59 }); |
| 60 newer_worker.postMessage({port: channel.port2}, [channel.port2]); |
| 61 return saw_message; |
| 62 }) |
| 63 .then(function(results) { |
| 64 var script_url = normalizeURL(script); |
| 65 var newer_script_url = normalizeURL(newer_script); |
| 66 var expectations = [ |
| 67 'evaluate', |
| 68 ' installing: empty', |
| 69 ' waiting: empty', |
| 70 ' active: ' + script_url, |
| 71 'updatefound', |
| 72 ' installing: ' + newer_script_url, |
| 73 ' waiting: empty', |
| 74 ' active: ' + script_url, |
| 75 'install', |
| 76 ' installing: ' + newer_script_url, |
| 77 ' waiting: empty', |
| 78 ' active: ' + script_url, |
| 79 'statechange(installed)', |
| 80 ' installing: empty', |
| 81 ' waiting: ' + newer_script_url, |
| 82 ' active: ' + script_url, |
| 83 'statechange(activating)', |
| 84 ' installing: empty', |
| 85 ' waiting: empty', |
| 86 ' active: ' + newer_script_url, |
| 87 'activate', |
| 88 ' installing: empty', |
| 89 ' waiting: empty', |
| 90 ' active: ' + newer_script_url, |
| 91 'statechange(activated)', |
| 92 ' installing: empty', |
| 93 ' waiting: empty', |
| 94 ' active: ' + newer_script_url, |
| 95 ]; |
| 96 assert_array_equals(results, expectations); |
| 97 }); |
| 98 }, 'Verify registration attributes on ServiceWorkerGlobalScope of the ' + |
| 99 'newer worker'); |
| 36 | 100 |
| 37 </script> | 101 </script> |
| OLD | NEW |