shared-storage-writable-iframe-request-in-sandboxed-frame.tentative.https.html (2439B)
1 <!doctype html> 2 <body> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script src=/common/utils.js></script> 6 <script src=/fenced-frame/resources/utils.js></script> 7 <script src=/shared-storage/resources/util.js></script> 8 <script> 9 async function 10 test_shared_storage_writable_iframe_request_in_sandboxed_iframe( 11 test, key, value, sandbox_flags) { 12 // Create sandboxed iframe. 13 let frame = document.createElement('iframe'); 14 frame.sandbox = sandbox_flags; 15 let url = new URL( 16 '/shared-storage/resources/' 17 + 'shared-storage-writable-iframe-request-' 18 + 'in-sandboxed-iframe-inner.https.sub.html', 19 location.href); 20 url = appendExpectedKeyAndValue(url, key, value); 21 frame.src = url; 22 23 // We expect a message to bubble up via the sandboxed iframe. 24 const promise = new Promise((resolve, reject) => { 25 window.addEventListener('message', async function handler(evt) { 26 if (evt.source === frame.contentWindow && 27 evt.data.sharedStorageWritableHeader) { 28 assert_equals(evt.data.sharedStorageWritableHeader, '?1'); 29 document.body.removeChild(frame); 30 window.removeEventListener('message', handler); 31 resolve(); 32 } 33 }); 34 window.addEventListener('error', () => { 35 reject(new Error('Navigation error')); 36 }); 37 }); 38 39 // Navigate and wait for notification. 40 document.body.appendChild(frame); 41 await promise; 42 43 // Verify that the value has been set. 44 await verifyKeyValueForOrigin(key, value, location.origin); 45 46 // Clean up and finish. 47 await sharedStorage.delete(key); 48 test.done(); 49 } 50 51 async_test(t => { 52 test_shared_storage_writable_iframe_request_in_sandboxed_iframe( 53 t, 54 /*key=*/'a', 55 /*value=*/'b', 56 /*sandbox_flags=*/'allow-scripts allow-same-origin'); 57 }, 'test sharedStorageWritable iframe request in sandboxed iframe with ' 58 + '"allow-same-origin"'); 59 60 async_test(t => { 61 test_shared_storage_writable_iframe_request_in_sandboxed_iframe( 62 t, 63 /*key=*/'c', 64 /*value=*/'d', 65 /*sandbox_flags=*/'allow-scripts'); 66 }, 'test sharedStorageWritable iframe request in sandboxed iframe without ' 67 + '"allow-same-origin"'); 68 </script> 69 </body>