local_FileSystemDirectoryHandle-partitioned-manual.https.tentative.html (4439B)
1 <!doctype html> 2 <head> 3 <meta charset=utf-8> 4 <meta name="timeout" content="long"> 5 <script src="/common/dispatcher/dispatcher.js"></script> 6 <script src="/common/get-host-info.sub.js"></script> 7 <script src="/common/utils.js"></script> 8 <script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script> 9 <script src="/html/anonymous-iframe/resources/common.js"></script> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script src="/resources/testdriver.js"></script> 13 <script src="/resources/testdriver-vendor.js"></script> 14 <script src="resources/test-helpers.js"></script> 15 <script src="resources/local-fs-test-helpers.js"></script> 16 </head> 17 <body> 18 <script> 19 20 const setUpChildFrame = (done) => ` 21 const importScript = ${importScript}; 22 await importScript("/resources/testharness.js"); 23 await importScript("/resources/testdriver.js"); 24 await importScript("/resources/testdriver-vendor.js"); 25 await importScript("/file-system-access/resources/local-fs-test-helpers.js"); 26 await importScript("/file-system-access/resources/test-helpers.js"); 27 await window.test_driver.bless( 28 'show a file picker.<br />Please select an empty directory'); 29 await send("${done}", "done"); 30 `; 31 32 const createTestDir = (name) => (done) => ` 33 self.showDirectoryPicker().then(async (dir) => { 34 await dir.getDirectoryHandle("${name}", {create: true}); 35 return send("${done}", "done"); 36 }); 37 `; 38 39 const removeTestDir = (name) => (done) => ` 40 self.showDirectoryPicker().then(async (dir) => { 41 await dir.removeEntry("${name}", {recursive: true}); 42 return send("${done}", "done"); 43 }); 44 `; 45 46 const assertNumEntries = (numFiles) => (done) => ` 47 self.showDirectoryPicker().then(async (dir) => { 48 assert_equals(${numFiles}, await getDirectoryEntryCount(dir)); 49 return send("${done}", "done"); 50 }); 51 `; 52 53 const assertNoAccess = (done) => ` 54 try { 55 await self.showDirectoryPicker(); 56 await send("${done}", "unexpected"); 57 } catch (e) { 58 await send("${done}", "done"); 59 } 60 `; 61 62 // To be resilient against tests not cleaning up properly, cleanup before 63 // every test. 64 async function clearDirectories() { 65 const directory = await directory_promise; 66 for await (let entry of directory.values()) { 67 await directory.removeEntry( 68 entry.name, {recursive: entry.kind === 'directory'}); 69 } 70 } 71 72 // The following tests make use of helper framed_test to define promise tests 73 // that send assertion scripts to multiple executor subframes. 74 75 framed_test(async (t, sendTo) => { 76 await clearDirectories(); 77 // Ensure we have directory picker access in all child contexts. 78 await sendTo(childContexts, setUpChildFrame); 79 await sendTo(sameSiteContexts, assertNumEntries(0)); 80 81 // Create directory in anonymous same-site context. 82 await sendTo([FRAME_CONTEXT.anonymousFrameSameSite], createTestDir("test")); 83 84 // Assert we can see the directory from all same-site contexts. 85 await sendTo(sameSiteContexts, assertNumEntries(1)); 86 }, 'getDirectoryHandle can access handles across same-site contexts.'); 87 88 framed_test(async (t, sendTo) => { 89 await clearDirectories(); 90 // Ensure we have directory picker access in all child contexts. 91 await sendTo(childContexts, setUpChildFrame); 92 await sendTo(sameSiteContexts, assertNumEntries(0)); 93 94 // Create a test directory in a third-party same-site context. 95 await sendTo([FRAME_CONTEXT.thirdPartySameSite], createTestDir("file")); 96 await sendTo([FRAME_CONTEXT.thirdPartySameSite], assertNumEntries(1)); 97 98 // Remove directory from an anonymous same-site context. 99 await sendTo([FRAME_CONTEXT.anonymousFrameSameSite], removeTestDir("file")); 100 // Assert third-party same-site context can no longer access directory. 101 await sendTo([FRAME_CONTEXT.thirdPartySameSite], assertNumEntries(0)); 102 }, 'Directory handles can be removed from other same-site contexts.'); 103 104 framed_test(async (t, sendTo) => { 105 await clearDirectories(); 106 // Ensure we have directory picker access in all child contexts. 107 await sendTo(childContexts, setUpChildFrame); 108 // Assert that an error is raised when attempting to access 109 // getDirectoryHandle. 110 await sendTo(crossSiteContexts, assertNoAccess); 111 }, 'Cross-site sub-frames can not access getDirectoryHandle.'); 112 113 // TODO(crbug.com/1322897): Add tests for ancestor bit frames. 114 // TODO(crbug.com/1099413): Add tests for non-default buckets. 115 116 </script> 117 </body>