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

Unified Diff: tests/html/fileapi_test.dart

Issue 12463028: "Reverting 19586" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/xhr_cross_origin_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/fileapi_test.dart
diff --git a/tests/html/fileapi_test.dart b/tests/html/fileapi_test.dart
index a089a3233b56e74351fceb17bcc495a80617ddd6..079197fc88204d4df20240bd87015c49d1017098 100644
--- a/tests/html/fileapi_test.dart
+++ b/tests/html/fileapi_test.dart
@@ -2,12 +2,11 @@ library fileapi;
import '../../pkg/unittest/lib/unittest.dart';
import '../../pkg/unittest/lib/html_individual_config.dart';
import 'dart:html';
-import 'dart:async';
-class FileAndDir {
- FileEntry file;
- DirectoryEntry dir;
- FileAndDir(this.file, this.dir);
+void fail(message) {
+ guardAsync(() {
+ expect(false, isTrue, reason: message);
+ });
}
FileSystem fs;
@@ -22,17 +21,20 @@ main() {
});
getFileSystem() {
- return window.requestFileSystem(Window.TEMPORARY, 100)
- .then((FileSystem fileSystem) {
- fs = fileSystem;
- });
+ window.requestFileSystem(Window.TEMPORARY, 100,
+ expectAsync1((FileSystem fileSystem) {
+ fs = fileSystem;
+ }),
+ (e) {
+ fail('Got file error: ${e.code}');
+ });
}
group('unsupported_throws', () {
test('requestFileSystem', () {
var expectation = FileSystem.supported ? returnsNormally : throws;
expect(() {
- window.requestFileSystem(Window.TEMPORARY, 100);
+ window.requestFileSystem(Window.TEMPORARY, 100, (_) {}, (_) {});
}, expectation);
});
});
@@ -42,21 +44,27 @@ main() {
test('getFileSystem', getFileSystem);
test('directoryDoesntExist', () {
- return fs.root.getDirectory(
+ fs.root.getDirectory(
'directory2',
- options: {})
- .catchError((e) {
- expect(e.error.code, equals(FileError.NOT_FOUND_ERR));
- }, test: (e) => e is FileError);
+ options: {},
+ successCallback: (e) {
+ fail('Should not be reached');
+ },
+ errorCallback: expectAsync1((FileError e) {
+ expect(e.code, equals(FileError.NOT_FOUND_ERR));
+ }));
});
test('directoryCreate', () {
- return fs.root.getDirectory(
+ fs.root.getDirectory(
'directory3',
- options: {'create': true})
- .then((DirectoryEntry e) {
- expect(e.name, equals('directory3'));
- });
+ options: {'create': true},
+ successCallback: expectAsync1((DirectoryEntry e) {
+ expect(e.name, equals('directory3'));
+ }),
+ errorCallback: (e) {
+ fail('Got file error: ${e.code}');
+ });
});
}
});
@@ -66,137 +74,35 @@ main() {
test('getFileSystem', getFileSystem);
test('fileDoesntExist', () {
- return fs.root.getFile(
+ fs.root.getFile(
'file2',
- options: {})
- .catchError((e) {
- expect(e.error.code, equals(FileError.NOT_FOUND_ERR));
- }, test: (e) => e is FileError);
+ options: {},
+ successCallback: (e) {
+ fail('Should not be reached');
+ },
+ errorCallback: expectAsync1((FileError e) {
+ expect(e.code, equals(FileError.NOT_FOUND_ERR));
+ }));
});
test('fileCreate', () {
- return fs.root.getFile(
+ fs.root.getFile(
'file4',
- options: {'create': true})
- .then((FileEntry e) {
- expect(e.name, equals('file4'));
- expect(e.isFile, isTrue);
- return e.getMetadata();
- }).then((Metadata metadata) {
- var changeTime = metadata.modificationTime;
- expect(new DateTime.now().difference(changeTime).inSeconds,
- lessThan(60));
- expect(metadata.size, equals(0));
- });
- });
- }
- });
-
- // Do the boilerplate to get several files and directories created to then
- // test the functions that use those items.
- Future doDirSetup() {
- return fs.root.getFile(
- 'file4',
- options: {'create': true})
- .then((FileEntry file) {
- return fs.root.getDirectory(
- 'directory3',
- options: {'create': true})
- .then((DirectoryEntry dir) {
- return new Future.immediate(new FileAndDir(file, dir));
+ 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}');
});
});
- }
-
- group('directoryReader', () {
- if (FileSystem.supported) {
- test('getFileSystem', getFileSystem);
-
- test('readEntries', () {
- return doDirSetup()
- .then((fileAndDir) {
- var reader = fileAndDir.dir.createReader();
- return reader.readEntries();
- }).then((entries) {
- expect(entries is List, true);
- });
- });
- }
- });
-
- group('entry', () {
- if (FileSystem.supported) {
- test('getFileSystem', getFileSystem);
-
- test('copyTo', () {
- return doDirSetup()
- .then((fileAndDir) {
- return fileAndDir.file.copyTo(fileAndDir.dir, name: 'copiedFile');
- }).then((entry) {
- expect(entry.isFile, true);
- expect(entry.name, 'copiedFile');
- });
- });
-
- test('getParent', () {
- return doDirSetup()
- .then((fileAndDir) {
- return fileAndDir.file.getParent();
- }).then((entry) {
- expect(entry.name, '');
- expect(entry.isFile, false);
- });
- });
-
- test('moveTo', () {
- return doDirSetup()
- .then((fileAndDir) {
- return fileAndDir.file.moveTo(fileAndDir.dir, name: 'movedFile');
- }).then((entry) {
- expect(entry.name, 'movedFile');
- expect(entry.fullPath, '/directory3/movedFile');
- return fs.root.getFile('file4', options: {'create': false});
- }).catchError((e) {
- expect(e.error.code, equals(FileError.NOT_FOUND_ERR));
- }, test: (e) => e is FileError);
- });
-
- test('remove', () {
- return doDirSetup()
- .then((fileAndDir) {
- return fileAndDir.file.remove().then((_) {});
- });
- });
- }
- });
-
- group('fileEntry', () {
- if (FileSystem.supported) {
- test('getFileSystem', getFileSystem);
-
- test('createWriter', () {
- return doDirSetup()
- .then((fileAndDir) {
- return fileAndDir.file.createWriter();
- }).then((writer) {
- expect(writer.position, 0);
- expect(writer.readyState, FileWriter.INIT);
- expect(writer.length, 0);
- });
- });
-
- test('file', () {
- return doDirSetup()
- .then((fileAndDir) {
- return fileAndDir.file.file()
- .then((fileObj) {
- expect(fileObj.name, fileAndDir.file.name);
- expect(fileObj.relativePath, '');
- expect(new DateTime.now().difference(
- fileObj.lastModifiedDate).inSeconds, lessThan(60));
- });
- });
- });
}
});
}
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/xhr_cross_origin_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698