OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: claim client using registration</title> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharness-helpers.js"></script> |
| 5 <script src="../resources/testharnessreport.js"></script> |
| 6 <script src="resources/test-helpers.js"></script> |
| 7 <script> |
| 8 |
| 9 promise_test(function(t) { |
| 10 var scope = 'resources/'; |
| 11 var frame_url = 'resources/blank.html?using-different-registration'; |
| 12 var url1 = 'resources/empty.js'; |
| 13 var url2 = 'resources/claim-worker.js'; |
| 14 var worker, sw_registration, frame; |
| 15 return service_worker_unregister_and_register(t, url1, scope) |
| 16 .then(function(registration) { |
| 17 return wait_for_state(t, registration.installing, 'activated'); |
| 18 }) |
| 19 .then(function() { |
| 20 return with_iframe(frame_url); |
| 21 }) |
| 22 .then(function(f) { |
| 23 frame = f; |
| 24 return navigator.serviceWorker.register(url2, {scope: frame_url}); |
| 25 }) |
| 26 .then(function(registration) { |
| 27 worker = registration.installing; |
| 28 sw_registration = registration; |
| 29 return wait_for_state(t, registration.installing, 'activated'); |
| 30 }) |
| 31 .then(function() { |
| 32 var saw_controllerchanged = new Promise(function(resolve) { |
| 33 frame.contentWindow.navigator.serviceWorker.oncontrollerchange = |
| 34 function() { resolve(); } |
| 35 }); |
| 36 var channel = new MessageChannel(); |
| 37 var saw_message = new Promise(function(resolve) { |
| 38 channel.port1.onmessage = t.step_func(function(e) { |
| 39 assert_equals(e.data, 'PASS', |
| 40 'Worker call to claim() should fulfill.'); |
| 41 resolve(); |
| 42 }); |
| 43 }); |
| 44 worker.postMessage({port: channel.port2}, [channel.port2]); |
| 45 return Promise.all([saw_controllerchanged, saw_message]); |
| 46 }) |
| 47 .then(function() { |
| 48 assert_equals( |
| 49 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| 50 normalizeURL(url2), |
| 51 'Frame1 controller scriptURL should be changed to url2'); |
| 52 frame.remove(); |
| 53 return sw_registration.unregister(); |
| 54 }) |
| 55 .then(function() { |
| 56 return service_worker_unregister_and_done(t, scope); |
| 57 }); |
| 58 }, 'Test worker claims client which is using another registration'); |
| 59 |
| 60 promise_test(function(t) { |
| 61 var scope = 'resources/blank.html?using-same-registration'; |
| 62 var url1 = 'resources/empty.js'; |
| 63 var url2 = 'resources/claim-worker.js'; |
| 64 var frame, worker; |
| 65 return service_worker_unregister_and_register(t, url1, scope) |
| 66 .then(function(registration) { |
| 67 return wait_for_state(t, registration.installing, 'activated'); |
| 68 }) |
| 69 .then(function() { |
| 70 return with_iframe(scope); |
| 71 }) |
| 72 .then(function(f) { |
| 73 frame = f; |
| 74 return navigator.serviceWorker.register(url2, {scope: scope}); |
| 75 }) |
| 76 .then(function(registration) { |
| 77 worker = registration.installing; |
| 78 return wait_for_state(t, registration.installing, 'installed'); |
| 79 }) |
| 80 .then(function() { |
| 81 var channel = new MessageChannel(); |
| 82 var saw_message = new Promise(function(resolve) { |
| 83 channel.port1.onmessage = t.step_func(function(e) { |
| 84 assert_equals(e.data, 'FAIL: exception: InvalidStateError', |
| 85 'Worker call to claim() should reject with ' + |
| 86 'InvalidStateError'); |
| 87 resolve(); |
| 88 }); |
| 89 }); |
| 90 worker.postMessage({port: channel.port2}, [channel.port2]); |
| 91 return saw_message; |
| 92 }) |
| 93 .then(function() { |
| 94 frame.remove(); |
| 95 return service_worker_unregister_and_done(t, scope); |
| 96 }); |
| 97 }, 'Test for the waiting worker claims a client which is using the the ' + |
| 98 'same registration'); |
| 99 |
| 100 </script> |
OLD | NEW |