| <!DOCTYPE html> |
| <title>Service Worker: Controller on reload</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="resources/test-helpers.js"></script> |
| <body> |
| <script> |
| promise_test(function(t) { |
| var scope = 'resources/blank.html'; |
| var frame; |
| return service_worker_unregister(t, scope) |
| .then(function() { |
| return with_iframe(scope); |
| }) |
| .then(function(f) { |
| frame = f; |
| return frame.contentWindow.navigator.serviceWorker.register( |
| 'empty-worker.js', {scope: 'blank.html'}); |
| }) |
| .then(function(registration) { |
| return wait_for_state(t, registration.installing, 'activated'); |
| }) |
| .then(function() { |
| var w = frame.contentWindow; |
| assert_equals(w.navigator.serviceWorker.controller, null, |
| 'controller should be null until the document is ' + |
| 'reloaded'); |
| return new Promise(function(resolve) { |
| frame.onload = function() { resolve(); } |
| w.location.reload(); |
| }); |
| }) |
| .then(function() { |
| var w = frame.contentWindow; |
| assert_true( |
| w.navigator.serviceWorker.controller instanceof w.ServiceWorker, |
| 'controller should be a ServiceWorker object upon reload'); |
| frame.remove(); |
| service_worker_unregister_and_done(t, scope); |
| }); |
| }, 'controller is set upon reload after registration'); |
| </script> |
| </body> |