sandboxed-iframe-no-storage-access.html (2013B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <script src="/resources/testdriver.js"></script> 4 <script src="/resources/testdriver-vendor.js"></script> 5 <script src="/resources/testharness.js"></script> 6 <!-- no testharnessreport.js --> 7 <script src="/storage-access-api/helpers.js"></script> 8 <script> 9 'use strict'; 10 (async function() { 11 test_driver.set_test_context(window.top); 12 13 const testPrefix = 'sandboxed-iframe'; 14 15 test(() => { 16 let iframe = document.createElement('iframe'); 17 assert_true( 18 iframe.sandbox.supports('allow-storage-access-by-user-activation'), 19 '`allow-storage-access-by-user-activation`' + 20 'sandbox attribute should be supported'); 21 }, '`allow-storage-access-by-user-activation` sandbox attribute is supported'); 22 promise_test( 23 async t => { 24 t.add_cleanup(async () => { 25 await test_driver.set_permission({name: 'storage-access'}, 'prompt'); 26 }); 27 await test_driver.set_permission({name: 'storage-access'}, 'granted'); 28 await MaybeSetStorageAccess('*', '*', 'blocked'); 29 return promise_rejects_dom( 30 t, 'NotAllowedError', document.requestStorageAccess(), 31 'document.requestStorageAccess() call without user gesture.'); 32 }, 33 '[' + testPrefix + 34 '] document.requestStorageAccess() should reject with a NotAllowedError with no user gesture.'); 35 36 promise_test(async t => { 37 t.add_cleanup(async () => { 38 await test_driver.set_permission({name: 'storage-access'}, 'prompt'); 39 }); 40 await test_driver.set_permission({name: 'storage-access'}, 'granted'); 41 await MaybeSetStorageAccess('*', '*', 'blocked'); 42 43 await RunCallbackWithGesture(async () => { 44 await promise_rejects_dom( 45 t, 'NotAllowedError', document.requestStorageAccess(), 46 'document.requestStorageAccess() call with user gesture.'); 47 }); 48 }, `[${testPrefix}] document.requestStorageAccess() should reject with a NotAllowedError, even with a user gesture`); 49 })(); 50 </script>