FileSystemFileHandle-getFile.js (1836B)
1 'use strict'; 2 3 directory_test(async (t, root) => { 4 const fileContents = 'awesome content'; 5 let handle = 6 await createFileWithContents('foo.txt', fileContents, /*parent=*/ root); 7 let file = await handle.getFile(); 8 let slice = file.slice(1, file.size); 9 let actualContents = await slice.text(); 10 assert_equals(actualContents, fileContents.slice(1, fileContents.length)); 11 }, 'getFile() provides a file that can be sliced'); 12 13 directory_test(async (t, root) => { 14 const handle = await createEmptyFile('mtime.txt', root); 15 let file = await handle.getFile(); 16 const first_mtime = file.lastModified; 17 18 // We wait for 2s here to ensure that the files do not have the 19 // same modification time. Some filesystems have low resolutions 20 // for modification timestamps. 21 let timeout = new Promise(resolve => { 22 t.step_timeout(resolve, 2000); 23 }); 24 await timeout; 25 26 const writer = await cleanup_writable(t, await handle.createWritable({keepExistingData: false})); 27 await writer.write(new Blob(['foo'])); 28 await writer.close(); 29 30 file = await handle.getFile(); 31 const second_mtime = file.lastModified; 32 33 // We wait for 5 ms here to ensure that `lastModified` 34 // from the File objects is stable between getFile invocations. 35 timeout = new Promise(resolve => { 36 t.step_timeout(resolve, 5); 37 }); 38 await timeout; 39 let fileReplica = await handle.getFile(); 40 assert_equals(second_mtime, fileReplica.lastModified); 41 42 assert_less_than(first_mtime, second_mtime); 43 }, 'getFile() returns last modified time'); 44 45 directory_test(async (t, root) => { 46 const fileName = "fileAttributesTest.txt"; 47 48 const fileHandle = await createEmptyFile(fileName, root); 49 assert_equals(fileHandle.name, fileName); 50 51 const file = await fileHandle.getFile(); 52 assert_equals(file.name, fileName); 53 }, 'getFile() returns expected name');