8611852b81
R=bkonyi@google.com Change-Id: Ic52e7afb489b15b2f2e45f5ad9191cf5e441c047 Reviewed-on: https://dart-review.googlesource.com/11342 Commit-Queue: Terry Lucas <terry@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
67 lines
1.6 KiB
Dart
67 lines
1.6 KiB
Dart
library fileapi;
|
|
|
|
import 'dart:html';
|
|
import 'dart:async';
|
|
|
|
import 'package:unittest/unittest.dart';
|
|
import 'package:unittest/html_individual_config.dart';
|
|
|
|
class FileAndDir {
|
|
FileEntry file;
|
|
DirectoryEntry dir;
|
|
FileAndDir(this.file, this.dir);
|
|
}
|
|
|
|
FileSystem fs;
|
|
|
|
main() {
|
|
useHtmlIndividualConfiguration();
|
|
|
|
getFileSystem() {
|
|
return window.requestFileSystem(100).then((FileSystem fileSystem) {
|
|
fs = fileSystem;
|
|
});
|
|
}
|
|
|
|
// Do the boilerplate to get several files and directories created to then
|
|
// test the functions that use those items.
|
|
Future doDirSetup(String testName) {
|
|
return fs.root.createFile('file_$testName').then((Entry file) {
|
|
return fs.root
|
|
.createDirectory('dir_$testName')
|
|
.then((Entry dir) {
|
|
return new Future.value(new FileAndDir(file, dir));
|
|
});
|
|
});
|
|
}
|
|
|
|
if (FileSystem.supported) {
|
|
test('getFileSystem', getFileSystem);
|
|
|
|
test('createWriter', () {
|
|
return doDirSetup('createWriter').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('file').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));
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|