filesystemdirectoryentry-getDirectory-manual.html (3944B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Entries API: FileSystemDirectoryEntry.getDirectory() manual test</title> 4 <link rel=help href="https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getdirectory"> 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, 'getDirectory', 'FileSystemDirectoryEntry has getDirectory'); 12 assert_equals(typeof entry.getDirectory, 'function', 'getDirectory() is a method'); 13 14 t.done(); 15 }, 'FileSystemDirectoryEntry - getDirectory()'); 16 17 INVALID_PATHS.forEach(path => { 18 entry_test((t, entry) => { 19 entry.getDirectory( 20 path, 21 {}, 22 t.unreached_func('getDirectory should fail'), 23 t.step_func(error => { 24 assert_equals(error.name, 'TypeMismatchError', 25 'getDirectory() should fail if given invalid path'); 26 t.done(); 27 })); 28 }, 'FileSystemDirectoryEntry.getDirectory() - invalid path: ' + JSON.stringify(path)); 29 }); 30 31 EMPTY_PATHS.forEach(path => { 32 entry_test((t, entry) => { 33 entry.getDirectory( 34 path, 35 {}, 36 t.step_func(dir => { 37 assert_true(dir.isDirectory, 38 'empty path should yield FileSystemDirectoryEntry'); 39 assert_equals(dir.name, entry.name, 40 'empty path should yield same directory'); 41 assert_equals(dir.fullPath, entry.fullPath, 42 'empty path should yield same directory'); 43 t.done(); 44 }), 45 t.unreached_func('getDirectory should not fail') 46 ); 47 }, 'FileSystemDirectoryEntry.getDirectory() - empty path: ' 48 + JSON.stringify(path) || 'undefined'); 49 }); 50 51 DIR_PATHS.forEach(path => { 52 entry_test((t, entry) => { 53 entry.getDirectory( 54 path, 55 {create: true}, 56 t.unreached_func('getDirectory should fail'), 57 t.step_func(error => { 58 assert_equals(error.name, 'SecurityError', 59 'getDirectory() should fail with security error if ' + 60 'create option is set'); 61 t.done(); 62 })); 63 }, 'FileSystemDirectoryEntry.getDirectory() - {create:true}: ' + path); 64 }); 65 66 NOT_FOUND_PATHS.forEach(path => { 67 entry_test((t, entry) => { 68 entry.getDirectory( 69 path, 70 {}, 71 t.unreached_func('getDirectory should fail'), 72 t.step_func(error => { 73 assert_equals(error.name, 'NotFoundError', 74 'getDirectory() should fail with not found'); 75 t.done(); 76 })); 77 }, 'FileSystemDirectoryEntry.getDirectory() - not found: ' + path); 78 }); 79 80 FILE_PATHS.forEach(path => { 81 entry_test((t, entry) => { 82 entry.getDirectory( 83 path, 84 {}, 85 t.unreached_func('getDirectory should fail'), 86 t.step_func(error => { 87 assert_equals(error.name, 'TypeMismatchError', 88 'getDirectory() should fail if type is file'); 89 t.done(); 90 })); 91 }, 'FileSystemDirectoryEntry.getDirectory() - directory: ' + path); 92 }); 93 94 DIR_PATHS.forEach(path => { 95 entry_test((t, entry) => { 96 entry.getDirectory( 97 path, 98 {}, 99 t.step_func(e => { 100 assert_false(e.isFile); 101 assert_true(e.isDirectory); 102 assert_equals(e.name, 'subdir'); 103 t.done(); 104 }), 105 t.unreached_func('getDirectory should not fail') 106 ); 107 }, 'FileSystemDirectoryEntry.getDirectory() - directory: ' + path); 108 }); 109 110 [ 111 {path: '.', name: 'upload'}, 112 {path: '/', name: ''} 113 ].forEach(test_case => { 114 entry_test((t, entry) => { 115 entry.getDirectory( 116 test_case.path, 117 {}, 118 t.step_func(e => { 119 assert_false(e.isFile); 120 assert_true(e.isDirectory); 121 assert_equals(e.name, test_case.name); 122 t.done(); 123 }), 124 t.unreached_func('getDirectory should not fail') 125 ); 126 }, 'FileSystemDirectoryEntry.getDirectory() - directory: ' + test_case.path); 127 }); 128 </script>