filesystemdirectoryreader-manual.html (2442B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Entries API: FileSystemDirectoryReader manual test</title> 4 <link rel=help href="https://wicg.github.io/entries-api/#api-directoryreader"> 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 const reader = entry.createReader(); 12 13 assert_idl_attribute(reader, 'readEntries', 'FileSystemDirectoryReader has readEntries'); 14 assert_equals(typeof reader.readEntries, 'function', 'readEntries() is a method'); 15 16 t.done(); 17 }, 'FileSystemDirectoryReader - interface'); 18 19 20 entry_test((t, entry) => { 21 getChildEntry(entry, 'subdir', t.step_func(dir => { 22 const reader = dir.createReader(); 23 assert_equals(typeof reader.readEntries, 'function'); 24 25 const found_names = []; 26 const do_chunk = t.step_func(() => 27 reader.readEntries(t.step_func(entries => { 28 29 if (entries.length > 0) { 30 entries.forEach(t.step_func(entry => found_names.push(entry.name))); 31 do_chunk(); 32 return; 33 } 34 35 found_names.sort(); 36 assert_array_equals(found_names, ['1.txt', '2.txt', '3.txt'], 37 'directory contents should match'); 38 t.done(); 39 }))); 40 41 do_chunk(); 42 }), t.unreached_func('A child entry should be found')); 43 }, 'FileSystemDirectoryReader - basic enumeration'); 44 45 entry_test((t, entry) => { 46 const reader = entry.createReader(); 47 reader.readEntries(() => {}, t.unreached_func('readEntries should succeed')); 48 reader.readEntries( 49 t.unreached_func('readEntries() should fail if already reading'), 50 t.step_func(error => { 51 assert_equals(error.name, 'InvalidStateError', 'invalid state if already reading'); 52 t.done(); 53 })); 54 }, 'FileSystemDirectoryReader - reading flag'); 55 56 entry_test((t, entry) => { 57 const reader = entry.createReader(); 58 59 const do_chunk = t.step_func(() => 60 reader.readEntries(t.step_func(entries => { 61 if (entries.length > 0) { 62 do_chunk(); 63 return; 64 } 65 reader.readEntries(t.step_func(entries => { 66 assert_equals( 67 entries.length, 0, 68 'calling readEntries() when done should yield and empty sequence'); 69 t.done(); 70 })); 71 }))); 72 73 do_chunk(); 74 }, 'FileSystemDirectoryReader - done flag'); 75 76 // TODO: Manual tests where directory contents are changed during the test. 77 </script>