Chromium Code Reviews| Index: tests/html/fileapi_test.dart |
| diff --git a/tests/html/fileapi_test.dart b/tests/html/fileapi_test.dart |
| index 6b85308493fee4975d8bf7d0a5fc5b176d3d12ed..c623fd335c506cfea4404717a50d236a01049d61 100644 |
| --- a/tests/html/fileapi_test.dart |
| +++ b/tests/html/fileapi_test.dart |
| @@ -3,58 +3,84 @@ |
| #import('../../pkg/unittest/html_config.dart'); |
| #import('dart:html'); |
| +void fail(message) { |
| + guardAsync(() { |
| + Expect.fail(message); |
| + }); |
| +} |
| + |
| +DOMFileSystem fs; |
| + |
| main() { |
| useHtmlConfiguration(); |
| - window.webkitRequestFileSystem(Window.TEMPORARY, 100, (fs) { |
| - // FIXME: add types to callback arguments after migration to wrapperless dart:html. |
| - |
| - test('getDirectory', () { |
| - expect(() => fs.root.getDirectory('directory1', {'x': true}, (e) {}), |
| - throws); |
| + test('getFileSystem', () { |
| + window.webkitRequestFileSystem(Window.TEMPORARY, 100, expectAsync1( |
| + (DOMFileSystem fileSystem) { |
| + fs = fileSystem; |
| + }), |
| + (FileError e) { |
| + fail('Got file error: ${e.code}'); |
| + }); |
| + }); |
| + group('getDirectory', () { |
| + test('directoryDoesntExist', () { |
| fs.root.getDirectory( |
| 'directory2', |
| options: {}, |
| - successCallback: expectAsync1((e) { |
| - expect(false, 'Should not be reached'); |
| - }, count:0), |
| - errorCallback: expectAsync1((e) { |
| - expect(e.code, equals(FileError.NOT_FOUND_ERR)); |
| + successCallback: (DirectoryEntry e) { |
|
vsm
2012/08/28 22:24:09
Hmm, one problem with this pattern is that if the
|
| + fail('Should not be reached'); |
| + }, |
| + errorCallback: expectAsync1((FileError e) { |
| + guardAsync(() { |
| + expect(e.code, equals(FileError.NOT_FOUND_ERR)); |
| + }); |
| })); |
| + }); |
| + test('directoryCreate', () { |
| fs.root.getDirectory( |
| 'directory3', |
| options: {'create': true}, |
| - successCallback: expectAsync1((e) { |
| - expect(e.name, equals('directory3')); |
| + successCallback: expectAsync1((DirectoryEntry e) { |
| + guardAsync(() { |
| + expect(e.name, equals('directory3')); |
| + }); |
| }), |
| - errorCallback: expectAsync1((e) { |
| - expect(false, 'Got file error: ${e.code}'); |
| - }, count:0)); |
| + errorCallback: (FileError e) { |
| + fail('Got file error: ${e.code}'); |
| + }); |
| }); |
| + }); |
| - test('getFile', () { |
| - expect(() => fs.root.getFile('file1', {'x': true}, (e) {}), throws); |
| + group('getFile', () { |
| + test('fileDoesntExist', () { |
| fs.root.getDirectory( |
| 'file2', |
| options: {}, |
| - successCallback: expectAsync1((e) { |
| - expect(false, 'Should not be reached'); |
| - }, count:0), |
| - errorCallback: expectAsync1((e) { |
| - expect(e.code, equals(FileError.NOT_FOUND_ERR)); |
| + successCallback: (FileEntry e) { |
| + fail('Should not be reached'); |
| + }, |
| + errorCallback: expectAsync1((FileError e) { |
| + guardAsync(() { |
| + expect(e.code, equals(FileError.NOT_FOUND_ERR)); |
| + }); |
| })); |
| + }); |
| + test('fileCreate', () { |
| fs.root.getDirectory( |
| 'file3', |
| options: {'create': true}, |
| successCallback: expectAsync1((e) { |
| - expect(e.name, equals('file3')); |
| + guardAsync(() { |
| + expect(e.name, equals('file3')); |
| + }); |
| }), |
| - errorCallback: expectAsync1((e) { |
| - expect(false, 'Got file error: ${e.code}'); |
| - }, count:0)); |
| - }); |
| + errorCallback: (FileError e) { |
| + fail('Got file error: ${e.code}'); |
| + }); |
| + }); |
| }); |
| } |