srcdoc-iframe.https.html (2191B)
1 <!DOCTYPE html> 2 <title>Service Worker: srcdoc frame handling</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="resources/test-helpers.sub.js"></script> 6 <body> 7 <script> 8 9 // This test attempts to verify various service worker behaviors in 10 // srcdoc iframe. 11 12 function runTestInSrcDocFrame(testFunc, testFuncParam) { 13 return new Promise((resolve, reject) => { 14 window.addEventListener('message', function onMsg(evt) { 15 if (evt.data.type !== 'TEST_RESULT') { 16 return; 17 } 18 window.removeEventListener('message', onMsg); 19 resolve(evt.data.result); 20 }); 21 testFunc(testFuncParam); 22 }); 23 } 24 25 async function doAsyncTest(t, testFuncName, expectedResult) { 26 const worker = 'resources/srcdoc-iframe-worker.js'; 27 const scope = 'resources/srcdoc-iframe.html'; 28 29 let reg = await service_worker_unregister_and_register(t, worker, scope); 30 31 t.add_cleanup(() => service_worker_unregister(t, scope)); 32 33 await wait_for_state(t, reg.installing, 'activated'); 34 35 let frame = await with_iframe(scope); 36 let scopeFullUlr = frame.contentWindow.location.href; 37 38 let testFunc = frame.contentWindow.srcdocFrame()[testFuncName]; 39 let testResult = await runTestInSrcDocFrame(testFunc, scopeFullUlr); 40 assert_equals(testResult, expectedResult); 41 42 frame.remove(); 43 } 44 45 promise_test(async function(t) { 46 await doAsyncTest(t, 'addSandboxedSrcdocFrame', 'NoController'); 47 }, 'nested sandboxed srcdoc frame should not inherit controller'); 48 49 promise_test(async function(t) { 50 await doAsyncTest(t, 'addSameOriginSandboxedSrcdocFrame', 'HasController'); 51 }, 'nested same origin sandboxed srcdoc frame should inherit controller'); 52 53 promise_test(async function(t) { 54 await doAsyncTest(t, 'fetchResource', 'passed'); 55 }, 'should be able to serve resource from controller for srcdoc frame'); 56 57 promise_test(async function(t) { 58 await doAsyncTest(t, 'getServiceWorkerRegistration', 'passed'); 59 }, 'getRegistration should work in srcdoc iframe'); 60 61 promise_test(async function(t) { 62 await doAsyncTest(t, 'postMessageToController', 'passed'); 63 }, 'controller.postMessage should work in srcdoc iframe'); 64 65 </script> 66 </body>