shared-storage-in-sandboxed-iframe.tentative.https.html (3418B)
1 <!doctype html> 2 <body> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script src=/browsing-topics/resources/header-util.sub.js></script> 6 <script> 7 function test_shared_storage_in_sandboxed_iframe(test, sandbox_flags, method, expect_success) { 8 let frame = document.createElement('iframe'); 9 frame.sandbox = sandbox_flags; 10 frame.src = '/shared-storage/resources/verify-shared-storage.https.html' + 11 `?method=${method}`; 12 13 window.addEventListener('message', test.step_func(function handler(evt) { 14 if (evt.source === frame.contentWindow) { 15 if (expect_success) { 16 assert_equals(evt.data.accessSharedStorageResult, 'success'); 17 } else { 18 assert_equals(evt.data.accessSharedStorageResult, 'failure'); 19 } 20 21 document.body.removeChild(frame); 22 window.removeEventListener('message', handler); 23 test.done(); 24 } 25 })); 26 27 document.body.appendChild(frame); 28 } 29 30 async_test(t => { 31 test_shared_storage_in_sandboxed_iframe(t, 32 /*sandbox_flags=*/'allow-scripts allow-same-origin', 33 /*method=*/'set', 34 /*expect_success=*/true); 35 }, 'test sharedStorage.set() in sandboxed iframe with "allow-same-origin"'); 36 37 async_test(t => { 38 test_shared_storage_in_sandboxed_iframe(t, 39 /*sandbox_flags=*/'allow-scripts', 40 /*method=*/'set', 41 /*expect_success=*/false); 42 }, 'test sharedStorage.set() in sandboxed iframe without "allow-same-origin"'); 43 44 async_test(t => { 45 test_shared_storage_in_sandboxed_iframe(t, 46 /*sandbox_flags=*/'allow-scripts allow-same-origin', 47 /*method=*/'createWorklet', 48 /*expect_success=*/true); 49 }, 'test sharedStorage.createWorklet() in sandboxed iframe with "allow-same-origin"'); 50 51 async_test(t => { 52 test_shared_storage_in_sandboxed_iframe(t, 53 /*sandbox_flags=*/'allow-scripts', 54 /*method=*/'createWorklet', 55 /*expect_success=*/false); 56 }, 'test sharedStorage.createWorklet() in sandboxed iframe without "allow-same-origin"'); 57 58 async_test(t => { 59 test_shared_storage_in_sandboxed_iframe(t, 60 /*sandbox_flags=*/'allow-scripts allow-same-origin', 61 /*method=*/'createWorkletScriptOrigin', 62 /*expect_success=*/true); 63 }, 'test sharedStorage.createWorklet() with dataOrigin "script-origin" in sandboxed iframe with "allow-same-origin"'); 64 65 async_test(t => { 66 test_shared_storage_in_sandboxed_iframe(t, 67 /*sandbox_flags=*/'allow-scripts', 68 /*method=*/'createWorkletScriptOrigin', 69 /*expect_success=*/true); 70 }, 'test sharedStorage.createWorklet() with dataOrigin "script-origin" in sandboxed iframe without "allow-same-origin"'); 71 72 async_test(t => { 73 test_shared_storage_in_sandboxed_iframe(t, 74 /*sandbox_flags=*/'allow-scripts allow-same-origin', 75 /*method=*/'addModule', 76 /*expect_success=*/true); 77 }, 'test sharedStorage.worklet.addModule() in sandboxed iframe with "allow-same-origin"'); 78 79 async_test(t => { 80 test_shared_storage_in_sandboxed_iframe(t, 81 /*sandbox_flags=*/'allow-scripts', 82 /*method=*/'addModule', 83 /*expect_success=*/false); 84 }, 'test sharedStorage.worklet.addModule() in sandboxed iframe without "allow-same-origin"'); 85 </script> 86 </body>