Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #library('fileapi'); | 1 #library('fileapi'); |
| 2 #import('../../pkg/unittest/unittest.dart'); | 2 #import('../../pkg/unittest/unittest.dart'); |
| 3 #import('../../pkg/unittest/html_config.dart'); | 3 #import('../../pkg/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 4 #import('dart:html'); |
| 5 | 5 |
| 6 void fail(message) { | |
| 7 guardAsync(() { | |
| 8 Expect.fail(message); | |
| 9 }); | |
| 10 } | |
| 11 | |
| 12 DOMFileSystem fs; | |
| 13 | |
| 6 main() { | 14 main() { |
| 7 useHtmlConfiguration(); | 15 useHtmlConfiguration(); |
| 8 window.webkitRequestFileSystem(Window.TEMPORARY, 100, (fs) { | 16 test('getFileSystem', () { |
| 9 // FIXME: add types to callback arguments after migration to wrapperless dar t:html. | 17 window.webkitRequestFileSystem(Window.TEMPORARY, 100, expectAsync1( |
| 18 (DOMFileSystem fileSystem) { | |
| 19 fs = fileSystem; | |
| 20 }), | |
| 21 (FileError e) { | |
| 22 fail('Got file error: ${e.code}'); | |
| 23 }); | |
| 24 }); | |
| 25 group('getDirectory', () { | |
| 10 | 26 |
| 11 test('getDirectory', () { | 27 test('directoryDoesntExist', () { |
| 12 expect(() => fs.root.getDirectory('directory1', {'x': true}, (e) {}), | |
| 13 throws); | |
| 14 | |
| 15 fs.root.getDirectory( | 28 fs.root.getDirectory( |
| 16 'directory2', | 29 'directory2', |
| 17 options: {}, | 30 options: {}, |
| 18 successCallback: expectAsync1((e) { | 31 successCallback: (DirectoryEntry e) { |
|
vsm
2012/08/28 22:24:09
Hmm, one problem with this pattern is that if the
| |
| 19 expect(false, 'Should not be reached'); | 32 fail('Should not be reached'); |
| 20 }, count:0), | 33 }, |
| 21 errorCallback: expectAsync1((e) { | 34 errorCallback: expectAsync1((FileError e) { |
| 22 expect(e.code, equals(FileError.NOT_FOUND_ERR)); | 35 guardAsync(() { |
| 36 expect(e.code, equals(FileError.NOT_FOUND_ERR)); | |
| 37 }); | |
| 23 })); | 38 })); |
| 39 }); | |
| 24 | 40 |
| 41 test('directoryCreate', () { | |
| 25 fs.root.getDirectory( | 42 fs.root.getDirectory( |
| 26 'directory3', | 43 'directory3', |
| 27 options: {'create': true}, | 44 options: {'create': true}, |
| 28 successCallback: expectAsync1((e) { | 45 successCallback: expectAsync1((DirectoryEntry e) { |
| 29 expect(e.name, equals('directory3')); | 46 guardAsync(() { |
| 47 expect(e.name, equals('directory3')); | |
| 48 }); | |
| 30 }), | 49 }), |
| 31 errorCallback: expectAsync1((e) { | 50 errorCallback: (FileError e) { |
| 32 expect(false, 'Got file error: ${e.code}'); | 51 fail('Got file error: ${e.code}'); |
| 33 }, count:0)); | 52 }); |
| 34 }); | 53 }); |
| 54 }); | |
| 35 | 55 |
| 36 test('getFile', () { | 56 group('getFile', () { |
| 37 expect(() => fs.root.getFile('file1', {'x': true}, (e) {}), throws); | |
| 38 | 57 |
| 58 test('fileDoesntExist', () { | |
| 39 fs.root.getDirectory( | 59 fs.root.getDirectory( |
| 40 'file2', | 60 'file2', |
| 41 options: {}, | 61 options: {}, |
| 42 successCallback: expectAsync1((e) { | 62 successCallback: (FileEntry e) { |
| 43 expect(false, 'Should not be reached'); | 63 fail('Should not be reached'); |
| 44 }, count:0), | 64 }, |
| 45 errorCallback: expectAsync1((e) { | 65 errorCallback: expectAsync1((FileError e) { |
| 46 expect(e.code, equals(FileError.NOT_FOUND_ERR)); | 66 guardAsync(() { |
| 67 expect(e.code, equals(FileError.NOT_FOUND_ERR)); | |
| 68 }); | |
| 47 })); | 69 })); |
| 70 }); | |
| 48 | 71 |
| 72 test('fileCreate', () { | |
| 49 fs.root.getDirectory( | 73 fs.root.getDirectory( |
| 50 'file3', | 74 'file3', |
| 51 options: {'create': true}, | 75 options: {'create': true}, |
| 52 successCallback: expectAsync1((e) { | 76 successCallback: expectAsync1((e) { |
| 53 expect(e.name, equals('file3')); | 77 guardAsync(() { |
| 78 expect(e.name, equals('file3')); | |
| 79 }); | |
| 54 }), | 80 }), |
| 55 errorCallback: expectAsync1((e) { | 81 errorCallback: (FileError e) { |
| 56 expect(false, 'Got file error: ${e.code}'); | 82 fail('Got file error: ${e.code}'); |
| 57 }, count:0)); | 83 }); |
| 58 }); | 84 }); |
| 59 }); | 85 }); |
| 60 } | 86 } |
| OLD | NEW |