OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: claim client not 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 <body> |
| 8 <script> |
| 9 |
| 10 promise_test(function(t) { |
| 11 var init_scope = 'resources/blank.html?not-using-init'; |
| 12 var claim_scope = 'resources/blank.html?not-using'; |
| 13 var init_worker_url = 'resources/empty.js'; |
| 14 var claim_worker_url = 'resources/claim-worker.js'; |
| 15 var claim_worker, claim_registration, frame1, frame2; |
| 16 return service_worker_unregister_and_register( |
| 17 t, init_worker_url, init_scope) |
| 18 .then(function(registration) { |
| 19 return wait_for_state(t, registration.installing, 'activated'); |
| 20 }) |
| 21 .then(function() { |
| 22 return Promise.all( |
| 23 [with_iframe(init_scope), with_iframe(claim_scope)]); |
| 24 }) |
| 25 .then(function(frames) { |
| 26 frame1 = frames[0]; |
| 27 frame2 = frames[1]; |
| 28 assert_equals( |
| 29 frame1.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| 30 normalizeURL(init_worker_url), |
| 31 'Frame1 controller should not be null'); |
| 32 assert_equals( |
| 33 frame2.contentWindow.navigator.serviceWorker.controller, null, |
| 34 'Frame2 controller should be null'); |
| 35 return navigator.serviceWorker.register(claim_worker_url, |
| 36 {scope: claim_scope}); |
| 37 }) |
| 38 .then(function(registration) { |
| 39 claim_worker = registration.installing; |
| 40 claim_registration = registration; |
| 41 return wait_for_state(t, registration.installing, 'activated'); |
| 42 }) |
| 43 .then(function() { |
| 44 var saw_controllerchanged = new Promise(function(resolve) { |
| 45 frame2.contentWindow.navigator.serviceWorker.oncontrollerchange = |
| 46 function() { resolve(); } |
| 47 }); |
| 48 var channel = new MessageChannel(); |
| 49 var saw_message = new Promise(function(resolve) { |
| 50 channel.port1.onmessage = t.step_func(function(e) { |
| 51 assert_equals(e.data, 'PASS', |
| 52 'Worker call to claim() should fulfill.'); |
| 53 resolve(); |
| 54 }); |
| 55 }); |
| 56 claim_worker.postMessage({port: channel.port2}, [channel.port2]); |
| 57 return Promise.all([saw_controllerchanged, saw_message]); |
| 58 }) |
| 59 .then(function() { |
| 60 assert_equals( |
| 61 frame1.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| 62 normalizeURL(init_worker_url), |
| 63 'Frame1 should not be influenced'); |
| 64 assert_equals( |
| 65 frame2.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| 66 normalizeURL(claim_worker_url), |
| 67 'Frame2 should be controlled by the new registration'); |
| 68 frame1.remove(); |
| 69 frame2.remove(); |
| 70 return claim_registration.unregister(); |
| 71 }) |
| 72 .then(function() { |
| 73 return service_worker_unregister_and_done(t, init_scope); |
| 74 }); |
| 75 }, 'Test claim client which is not using registration'); |
| 76 |
| 77 promise_test(function(t) { |
| 78 var scope = 'resources/blank.html?longer-matched'; |
| 79 var claim_scope = 'resources/blank.html?longer'; |
| 80 var claim_worker_url = 'resources/claim-worker.js'; |
| 81 var installing_worker_url = 'resources/wait-forever-in-install-worker.js'; |
| 82 var frame, claim_worker; |
| 83 return with_iframe(scope) |
| 84 .then(function(f) { |
| 85 frame = f; |
| 86 return navigator.serviceWorker.register( |
| 87 claim_worker_url, {scope: claim_scope}); |
| 88 }) |
| 89 .then(function(registration) { |
| 90 claim_worker = registration.installing; |
| 91 return wait_for_state(t, registration.installing, 'activated'); |
| 92 }) |
| 93 .then(function() { |
| 94 return navigator.serviceWorker.register( |
| 95 installing_worker_url, {scope: scope}); |
| 96 }) |
| 97 .then(function() { |
| 98 var channel = new MessageChannel(); |
| 99 var saw_message = new Promise(function(resolve) { |
| 100 channel.port1.onmessage = t.step_func(function(e) { |
| 101 assert_equals(e.data, 'PASS', |
| 102 'Worker call to claim() should fulfill.'); |
| 103 resolve(); |
| 104 }); |
| 105 }); |
| 106 claim_worker.postMessage({port: channel.port2}, [channel.port2]); |
| 107 return saw_message; |
| 108 }) |
| 109 .then(function() { |
| 110 assert_equals( |
| 111 frame.contentWindow.navigator.serviceWorker.controller, null, |
| 112 'Frame should not be claimed when a longer-matched ' + |
| 113 'registration exists'); |
| 114 frame.remove(); |
| 115 return service_worker_unregister_and_done(t, claim_scope); |
| 116 }); |
| 117 }, 'Test claim client when there\'s a longer-matched registration not ' + |
| 118 'already used by the page'); |
| 119 |
| 120 </script> |
OLD | NEW |