url-parsing.https.html (3208B)
1 <!DOCTYPE html> 2 <title>register()/getRegistration() URL parsing, with multiple globals in play</title> 3 <link rel="help" href="https://w3c.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-container-register-method"> 4 <link rel="help" href="https://w3c.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-container-getregistration-method"> 5 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> 6 <script src="/resources/testharness.js"></script> 7 <script src="../resources/testharness-helpers.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="../resources/test-helpers.sub.js"></script> 10 11 <!-- This is the entry global --> 12 13 <iframe src="incumbent/incumbent.https.html"></iframe> 14 15 <script> 16 'use strict'; 17 18 const loadPromise = new Promise(resolve => { 19 window.addEventListener('load', () => resolve()); 20 }); 21 22 promise_test(t => { 23 let registration; 24 25 return loadPromise.then(() => { 26 return frames[0].testRegister(); 27 }).then(r => { 28 registration = r; 29 return wait_for_state(t, registration.installing, 'activated'); 30 }).then(_ => { 31 assert_equals(registration.active.scriptURL, normalizeURL('relevant/test-sw.js'), 'the script URL should be parsed against the relevant global'); 32 assert_equals(registration.scope, normalizeURL('relevant/'), 'the default scope URL should be parsed against the parsed script URL'); 33 34 return registration.unregister(); 35 }); 36 }, 'register should use the relevant global of the object it was called on to resolve the script URL and the default scope URL'); 37 38 promise_test(t => { 39 let registration; 40 41 return loadPromise.then(() => { 42 return frames[0].testRegister({ scope: 'scope' }); 43 }).then(r => { 44 registration = r; 45 return wait_for_state(t, registration.installing, 'activated'); 46 }).then(_ => { 47 assert_equals(registration.active.scriptURL, normalizeURL('relevant/test-sw.js'), 'the script URL should be parsed against the relevant global'); 48 assert_equals(registration.scope, normalizeURL('relevant/scope'), 'the given scope URL should be parsed against the relevant global'); 49 50 return registration.unregister(); 51 }); 52 }, 'register should use the relevant global of the object it was called on to resolve the script URL and the given scope URL'); 53 54 promise_test(t => { 55 let registration; 56 57 return loadPromise.then(() => { 58 return navigator.serviceWorker.register(normalizeURL('relevant/test-sw.js')); 59 }).then(r => { 60 registration = r; 61 return frames[0].testGetRegistration(); 62 }) 63 .then(gottenRegistration => { 64 assert_not_equals(registration, null, 'the registration should not be null'); 65 assert_not_equals(gottenRegistration, null, 'the registration from the other frame should not be null'); 66 assert_equals(gottenRegistration.scope, registration.scope, 67 'the retrieved registration\'s scope should be equal to the original\'s scope'); 68 69 return registration.unregister(); 70 }); 71 }, 'getRegistration should use the relevant global of the object it was called on to resolve the script URL'); 72 73 </script>