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