Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Unified Diff: tests/html/fileapi_test.dart

Issue 12380046: Future-ify all the html methods and add named parameters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/html/fileapi_test.dart
diff --git a/tests/html/fileapi_test.dart b/tests/html/fileapi_test.dart
index 079197fc88204d4df20240bd87015c49d1017098..baae4b2b65cb4b941948a8b4b66d76e569053abf 100644
--- a/tests/html/fileapi_test.dart
+++ b/tests/html/fileapi_test.dart
@@ -21,12 +21,12 @@ main() {
});
getFileSystem() {
- window.requestFileSystem(Window.TEMPORARY, 100,
- expectAsync1((FileSystem fileSystem) {
+ return window.requestFileSystem(Window.TEMPORARY, 100).then(
+ (FileSystem fileSystem) {
fs = fileSystem;
- }),
+ }).catchError(
blois 2013/03/06 00:34:29 Should not need to do the catch error- it should p
Emily Fortuna 2013/03/06 21:29:18 Done.
(e) {
- fail('Got file error: ${e.code}');
+ fail('Got file error: ${e.error.code}');
});
}
@@ -34,7 +34,7 @@ main() {
test('requestFileSystem', () {
var expectation = FileSystem.supported ? returnsNormally : throws;
expect(() {
- window.requestFileSystem(Window.TEMPORARY, 100, (_) {}, (_) {});
+ window.requestFileSystem(Window.TEMPORARY, 100);
}, expectation);
});
});
@@ -44,27 +44,27 @@ main() {
test('getFileSystem', getFileSystem);
test('directoryDoesntExist', () {
- fs.root.getDirectory(
+ return fs.root.getDirectory(
'directory2',
- options: {},
- successCallback: (e) {
- fail('Should not be reached');
- },
- errorCallback: expectAsync1((FileError e) {
- expect(e.code, equals(FileError.NOT_FOUND_ERR));
- }));
+ options: {}).then(
+ (e) {
+ fail('Should not be reached');
+ }).catchError(
+ (AsyncError e) {
blois 2013/03/06 00:34:29 Should probably provide a test function as well an
+ expect(e.error.code, equals(FileError.NOT_FOUND_ERR));
+ });
});
test('directoryCreate', () {
- fs.root.getDirectory(
+ return fs.root.getDirectory(
'directory3',
- options: {'create': true},
- successCallback: expectAsync1((DirectoryEntry e) {
- expect(e.name, equals('directory3'));
- }),
- errorCallback: (e) {
- fail('Got file error: ${e.code}');
- });
+ options: {'create': true}).then(
+ (DirectoryEntry e) {
+ expect(e.name, equals('directory3'));
+ }).catchError(
+ (e) {
blois 2013/03/06 00:34:29 Can just ignore this error, test framework will ge
Emily Fortuna 2013/03/06 21:29:18 Done.
+ fail('Got file error: ${e.error.code}');
+ });
});
}
});
@@ -74,35 +74,154 @@ main() {
test('getFileSystem', getFileSystem);
test('fileDoesntExist', () {
- fs.root.getFile(
+ return fs.root.getFile(
'file2',
- options: {},
- successCallback: (e) {
- fail('Should not be reached');
- },
- errorCallback: expectAsync1((FileError e) {
- expect(e.code, equals(FileError.NOT_FOUND_ERR));
- }));
+ options: {}).then(
+ (e) {
+ fail('Should not be reached');
+ }).catchError(
+ (AsyncError e) {
+ expect(e.error.code, equals(FileError.NOT_FOUND_ERR));
blois 2013/03/06 00:34:29 Ditto for test function for catchError.
+ });
});
test('fileCreate', () {
- fs.root.getFile(
+ return fs.root.getFile(
'file4',
- options: {'create': true},
- successCallback: expectAsync1((FileEntry e) {
- expect(e.name, equals('file4'));
- expect(e.isFile, isTrue);
-
- e.getMetadata(expectAsync1((Metadata metadata) {
- var changeTime = metadata.modificationTime;
- expect(new DateTime.now().difference(changeTime).inSeconds,
- lessThan(60));
- }));
- }),
- errorCallback: (e) {
- fail('Got file error: ${e.code}');
- });
+ options: {'create': true}).then(
+ (FileEntry e) {
+ expect(e.name, equals('file4'));
+ expect(e.isFile, isTrue);
+
+ return e.getMetadata().then((Metadata metadata) {
blois 2013/03/06 00:34:29 sent mail with suggested style changes.
+ var changeTime = metadata.modificationTime;
+ expect(new DateTime.now().difference(changeTime).inSeconds,
+ lessThan(60));
+ expect(metadata.size, equals(0));
+ });
+ }).catchError(
+ (e) {
+ fail('Got file error: ${e.error.code}');
blois 2013/03/06 00:34:29 Don't need catchError.
Emily Fortuna 2013/03/06 21:29:18 Done.
+ });
+ });
+ }
+ });
+
+ // Do the boilerplate to get several files and directories created to then
+ // test the functions that use those items.
+ Future doDirSetup(successCallback) {
blois 2013/03/06 00:34:29 Seems like this should have a class which holds th
+ return fs.root.getFile(
+ 'file4',
+ options: {'create': true}).then(
blois 2013/03/06 00:34:29 ditto on style changes.
+ (FileEntry file) {
+ return fs.root.getDirectory(
+ 'directory3',
+ options: {'create': true}).then(
+ (DirectoryEntry dir) {
+ return successCallback(file, dir);
+ });
+ });
+ }
+
+ group('directoryReader', () {
+ if (FileSystem.supported) {
+ test('getFileSystem', getFileSystem);
+
+ test('readEntries', () {
+ return doDirSetup((file, dir) {
+ var reader = dir.createReader();
+ reader.readEntries().then(
+ (entries) { expect(entries is List, true);})
+ .catchError(
+ (e) {
blois 2013/03/06 00:34:29 don't need catchError
Emily Fortuna 2013/03/06 21:29:18 Done.
+ fail("Shouldn't be reached error: ${e.error.code}");
+ });
});
+ });
+ }
+ });
+
+ group('entry', () {
+ if (FileSystem.supported) {
+ test('getFileSystem', getFileSystem);
+
+ test('copyTo', () {
+ return doDirSetup((file, dir) {
+ return file.copyTo(dir, name: 'copiedFile').then(
+ (entry) {
+ expect(entry.isFile, true);
+ expect(entry.name, 'copiedFile');
+ }).catchError(
+ (error) { fail('CopyToFailure ${error.error.code}'); }); });
+ });
+
+ test('getParent', () {
+ return doDirSetup((file, dir) {
+ return file.getParent().then((entry) {
+ expect(entry.name, '');
+ expect(entry.isFile, false);
+ });
+ });
+ });
+
+ test('moveTo', () {
+ return doDirSetup((file, dir) {
+ return file.moveTo(dir, name: 'movedFile').then(
+ (entry) {
+ expect(entry.name, 'movedFile');
+ expect(entry.fullPath, '/directory3/movedFile');
+ return fs.root.getFile('file4', options: {'create': false})
+ .then(
+ (e) { fail("File should be moved."); })
+ .catchError(
+ (e) {
+ expect(e.error.code,
+ equals(FileError.NOT_FOUND_ERR));
+ });
+ })
+ .catchError((e) { fail("Failed move to ${e.error.code}"); });
+ });
+ });
+
+ test('remove', () {
+ return doDirSetup((file, dir) {
+ return file.remove().then((_) {})
+ .catchError((e) { fail("Failed move to ${e.error.code}"); });
+ });
+ });
+ }
+ });
+
+ group('fileEntry', () {
+ if (FileSystem.supported) {
+ test('getFileSystem', getFileSystem);
+
+ test('createWriter', () {
+ return doDirSetup((file, dir) {
+ return file.createWriter().then(
+ (writer) {
+ expect(writer.position, 0);
+ expect(writer.readyState, FileWriter.INIT);
+ expect(writer.length, 0);
+ }).catchError((e) {
+ fail("Create writer failed. ${e.error.code}");
+ });
+ });
+ });
+
+ test('file', () {
+ return doDirSetup((file, dir) {
+ return file.file().then(
+ (fileObj) {
+ expect(fileObj.name, file.name);
+ expect(fileObj.relativePath, '');
+ expect(new DateTime.now().difference(
+ fileObj.lastModifiedDate).inSeconds, lessThan(60));
+ }).catchError((e) {
+ fail("File failed. ${e.error.code}");
+ });
+ });
+ });
}
});
}

Powered by Google App Engine
This is Rietveld 408576698