filesystemdirectoryentry-getFile-manual.html (3702B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Entries API: FileSystemDirectoryEntry.getFile() manual test</title> 4 <link rel=help href="https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getfile"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="support.js"></script> 8 9 <script> 10 entry_test((t, entry) => { 11 assert_idl_attribute(entry, 'getFile', 'FileSystemDirectoryEntry has getFile'); 12 assert_equals(typeof entry.getFile, 'function', 'getFile() is a method'); 13 14 t.done(); 15 }, 'FileSystemDirectoryEntry - getFile()'); 16 17 INVALID_PATHS.forEach(path => { 18 entry_test((t, entry) => { 19 entry.getFile( 20 path, 21 {}, 22 t.unreached_func('getFile should fail'), 23 t.step_func(error => { 24 assert_equals(error.name, 'TypeMismatchError', 25 'getFile() should fail if given invalid path'); 26 t.done(); 27 })); 28 }, 'FileSystemDirectoryEntry.getFile() - invalid path: ' + JSON.stringify(path)); 29 }); 30 31 EMPTY_PATHS.forEach(path => { 32 entry_test((t, entry) => { 33 entry.getFile( 34 path, 35 {}, 36 t.unreached_func('getFile should fail'), 37 t.step_func(error => { 38 assert_equals(error.name, 'TypeMismatchError', 39 'getFile() on empty path should fail because the ' + 40 'path resolves to the directory itself'); 41 t.done(); 42 })); 43 }, 'FileSystemDirectoryEntry.getFile() - empty path: ' + JSON.stringify(path) || 'undefined'); 44 }); 45 46 FILE_PATHS.forEach(path => { 47 entry_test((t, entry) => { 48 entry.getFile( 49 path, 50 {create: true}, 51 t.unreached_func('getFile should fail'), 52 t.step_func(error => { 53 assert_equals(error.name, 'SecurityError', 54 'getFile() should fail with security error if ' + 55 'create option is set'); 56 t.done(); 57 })); 58 }, 'FileSystemDirectoryEntry.getFile() - {create:true}: ' + path); 59 }); 60 61 NOT_FOUND_PATHS.forEach(path => { 62 entry_test((t, entry) => { 63 entry.getFile( 64 path, 65 {}, 66 t.unreached_func('getFile should fail'), 67 t.step_func(error => { 68 assert_equals(error.name, 'NotFoundError', 69 'getFile() should fail with not found'); 70 t.done(); 71 })); 72 }, 'FileSystemDirectoryEntry.getFile() - not found: ' + path); 73 }); 74 75 DIR_PATHS.concat(['/', '.']).forEach(path => { 76 entry_test((t, entry) => { 77 entry.getFile( 78 path, 79 {}, 80 t.unreached_func('getFile should fail'), 81 t.step_func(error => { 82 assert_equals(error.name, 'TypeMismatchError', 83 'getFile() should fail if type is directory'); 84 t.done(); 85 })); 86 }, 'FileSystemDirectoryEntry.getFile() - directory: ' + path); 87 }); 88 89 FILE_PATHS.forEach(path => { 90 entry_test((t, entry) => { 91 entry.getFile( 92 path, 93 {}, 94 t.step_func(e => { 95 assert_true(e.isFile); 96 assert_false(e.isDirectory); 97 assert_equals(e.name, 'file.txt'); 98 t.done(); 99 }), 100 t.unreached_func('getFile should not fail') 101 ); 102 }, 'FileSystemDirectoryEntry.getFile() - file: ' + path); 103 }); 104 105 entry_test((t, entry) => { 106 entry.getFile(FILE_PATHS[0], {}, t.step_func(e1 => { 107 entry.getFile(FILE_PATHS[0], {}, t.step_func(e2 => { 108 assert_equals(e1.name, e2.name, 'names should match'); 109 assert_equals(e1.fullPath, e2.fullPath, 'names should match'); 110 assert_not_equals(e1, e2, 'objects should be distinct'); 111 t.done(); 112 }), t.unreached_func('getFile should not fail')); 113 }), t.unreached_func('getFile should not fail')); 114 }, 'FileSystemDirectoryEntry.getFile() - object identity'); 115 </script>