shared-storage-writable-img-request-in-sandboxed-frame.tentative.https.html (2756B)
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_img_request_in_sandboxed_iframe( 11 test, key, value, sandbox_flags, expect_success) { 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-img-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 from 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.sharedStorageImageLoadStatus) { 28 document.body.removeChild(frame); 29 window.removeEventListener('message', handler); 30 if (evt.data.sharedStorageImageLoadStatus === "success") { 31 resolve(); 32 } else { 33 reject(evt.data.sharedStorageImageLoadStatus); 34 } 35 } 36 }); 37 window.addEventListener('error', () => { 38 reject(new Error('Load error')); 39 }); 40 }); 41 42 // Navigate and wait for notification. 43 document.body.appendChild(frame); 44 await promise; 45 46 if (expect_success) { 47 // Verify that the value has been set. 48 await verifyKeyValueForOrigin(key, value, location.origin); 49 } else { 50 // Verify that the value has not been set. 51 await verifyKeyNotFoundForOrigin(key, location.origin); 52 } 53 54 // Clean up and finish. 55 await sharedStorage.delete(key); 56 test.done(); 57 } 58 59 async_test(t => { 60 test_shared_storage_writable_img_request_in_sandboxed_iframe( 61 t, 62 /*key=*/'a', 63 /*value=*/'b', 64 /*sandbox_flags=*/'allow-scripts allow-same-origin', 65 /*expect_success=*/true); 66 }, 'test sharedStorageWritable img request in sandboxed iframe with ' 67 + '"allow-same-origin"'); 68 69 async_test(t => { 70 test_shared_storage_writable_img_request_in_sandboxed_iframe( 71 t, 72 /*key=*/'c', 73 /*value=*/'d', 74 /*sandbox_flags=*/'allow-scripts', 75 /*expect_success=*/true); 76 }, 'test sharedStorageWritable img request in sandboxed iframe without ' 77 + '"allow-same-origin"'); 78 </script> 79 </body>