detached-iframe.https.html (2459B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Storage Buckets API on detached iframe</title> 4 <link rel='help' href=''> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <body> 9 <script> 10 'use strict'; 11 12 promise_test(async testCase => { 13 const iframe = document.createElement('iframe'); 14 document.body.appendChild(iframe); 15 const bucketManager = iframe.contentWindow.navigator.storageBuckets; 16 await bucketManager.open('iframe-bucket'); 17 18 let bucketKeys = await bucketManager.keys(); 19 assert_equals(bucketKeys.length, 1); 20 21 // Note that these tests cannot make use of `prepareForBucketTest` because the 22 // iframe is detached before the test ends, so the test's cleanup step comes 23 // too late to delete buckets. 24 await bucketManager.delete('iframe-bucket'); 25 26 const IFrameTypeError = iframe.contentWindow.TypeError; 27 iframe.remove(); 28 29 // Calling open() from a detached iframe should fail but not crash. 30 await promise_rejects_js(testCase, IFrameTypeError, 31 bucketManager.open('iframe-bucket')); 32 }, 'Verify open() on detached iframe returns an error'); 33 34 promise_test(async testCase => { 35 const iframe = document.createElement('iframe'); 36 document.body.appendChild(iframe); 37 const bucketManager = iframe.contentWindow.navigator.storageBuckets; 38 await bucketManager.open('iframe-bucket'); 39 40 let bucketKeys = await bucketManager.keys(); 41 assert_equals(bucketKeys.length, 1); 42 await bucketManager.delete('iframe-bucket'); 43 44 const IFrameTypeError = iframe.contentWindow.TypeError; 45 iframe.remove(); 46 47 // Calling keys() from a detached iframe should fail but not crash. 48 await promise_rejects_js(testCase, IFrameTypeError, 49 bucketManager.keys()); 50 }, 'Verify keys() on detached iframe returns an error'); 51 52 promise_test(async testCase => { 53 const iframe = document.createElement('iframe'); 54 document.body.appendChild(iframe); 55 const bucketManager = iframe.contentWindow.navigator.storageBuckets; 56 await bucketManager.open('iframe-bucket'); 57 await bucketManager.delete('iframe-bucket'); 58 59 const IFrameTypeError = iframe.contentWindow.TypeError; 60 iframe.remove(); 61 62 // Calling delete() from a detached iframe should fail but not crash. 63 await promise_rejects_js(testCase, IFrameTypeError, 64 bucketManager.delete('foo-bucket')); 65 }, 'Verify delete() on detached iframe returns an error'); 66 67 </script> 68 </body>