mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 19:10:05 +00:00
63a57a76ce
This reverts commit f8ff12008e
.
This CL is a revert of the initial revert and should be landed once
Flutter changes have been merged to handle the changes here.
Change-Id: I300a5efd776bf2a596743971f4e15ad62da77f5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153368
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
78 lines
2.4 KiB
Dart
78 lines
2.4 KiB
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library fileapi;
|
|
|
|
import 'dart:async';
|
|
import 'dart:html';
|
|
|
|
import 'package:async_helper/async_helper.dart';
|
|
import 'package:async_helper/async_minitest.dart';
|
|
|
|
class FileAndDir {
|
|
FileEntry file;
|
|
DirectoryEntry dir;
|
|
FileAndDir(this.file, this.dir);
|
|
}
|
|
|
|
late FileSystem fs;
|
|
|
|
main() async {
|
|
getFileSystem() async {
|
|
return await 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) async {
|
|
await getFileSystem();
|
|
|
|
var file = await fs.root!.createFile('file_$testName') as FileEntry;
|
|
var dir = await fs.root!.createDirectory('dir_$testName') as DirectoryEntry;
|
|
return new Future.value(new FileAndDir(file, dir));
|
|
}
|
|
|
|
if (FileSystem.supported) {
|
|
test('copy_move', () async {
|
|
var fileAndDir = await doDirSetup('copyTo');
|
|
var entry =
|
|
await fileAndDir.file.copyTo(fileAndDir.dir, name: 'copiedFile');
|
|
expect(entry.isFile, true, reason: "Expected File");
|
|
expect(entry.name, 'copiedFile');
|
|
|
|
// getParent
|
|
fileAndDir = await doDirSetup('getParent');
|
|
entry = await fileAndDir.file.getParent();
|
|
expect(entry.name, '');
|
|
expect(entry.isDirectory, true, reason: "Expected Directory");
|
|
|
|
// moveTo
|
|
fileAndDir = await doDirSetup('moveTo');
|
|
entry = await fileAndDir.file.moveTo(fileAndDir.dir, name: 'movedFile');
|
|
expect(entry.name, 'movedFile');
|
|
expect(entry.fullPath, '/dir_moveTo/movedFile');
|
|
|
|
try {
|
|
entry = await fs.root!.getFile('file4');
|
|
fail("File file4 should not exist.");
|
|
} on DomException catch (error) {
|
|
expect(DomException.NOT_FOUND, error.name);
|
|
}
|
|
|
|
// remove
|
|
fileAndDir = await doDirSetup('remove');
|
|
expect('file_remove', fileAndDir.file.name);
|
|
await fileAndDir.file.remove();
|
|
try {
|
|
var entry = await fileAndDir.dir.getFile(fileAndDir.file.name);
|
|
fail("file not removed");
|
|
} on DomException catch (error) {
|
|
expect(DomException.NOT_FOUND, error.name);
|
|
}
|
|
});
|
|
}
|
|
}
|