| OLD | NEW |
| 1 library fileapi; | 1 library fileapi; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 import '../../pkg/unittest/lib/html_individual_config.dart'; | 3 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 class FileAndDir { | 7 class FileAndDir { |
| 8 FileEntry file; | 8 FileEntry file; |
| 9 DirectoryEntry dir; | 9 DirectoryEntry dir; |
| 10 FileAndDir(this.file, this.dir); | 10 FileAndDir(this.file, this.dir); |
| 11 } | 11 } |
| 12 | 12 |
| 13 FileSystem fs; | 13 FileSystem fs; |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 useHtmlIndividualConfiguration(); | 16 useHtmlIndividualConfiguration(); |
| 17 | 17 |
| 18 group('supported', () { | 18 group('supported', () { |
| 19 test('supported', () { | 19 test('supported', () { |
| 20 expect(FileSystem.supported, true); | 20 expect(FileSystem.supported, true); |
| 21 }); | 21 }); |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 getFileSystem() { | 24 getFileSystem() { |
| 25 return window.requestFileSystem(Window.TEMPORARY, 100) | 25 return window.requestFileSystem(100) |
| 26 .then((FileSystem fileSystem) { | 26 .then((FileSystem fileSystem) { |
| 27 fs = fileSystem; | 27 fs = fileSystem; |
| 28 }); | 28 }); |
| 29 } | 29 } |
| 30 | 30 |
| 31 group('unsupported_throws', () { | 31 group('unsupported_throws', () { |
| 32 test('requestFileSystem', () { | 32 test('requestFileSystem', () { |
| 33 var expectation = FileSystem.supported ? returnsNormally : throws; | 33 var expectation = FileSystem.supported ? returnsNormally : throws; |
| 34 expect(() { | 34 expect(() { |
| 35 window.requestFileSystem(Window.TEMPORARY, 100); | 35 window.requestFileSystem(100); |
| 36 }, expectation); | 36 }, expectation); |
| 37 }); | 37 }); |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 group('getDirectory', () { | 40 group('getDirectory', () { |
| 41 if (FileSystem.supported) { | 41 if (FileSystem.supported) { |
| 42 test('getFileSystem', getFileSystem); | 42 test('getFileSystem', getFileSystem); |
| 43 | 43 |
| 44 test('directoryDoesntExist', () { | 44 test('directoryDoesntExist', () { |
| 45 return fs.root.getDirectory( | 45 return fs.root.getDirectory( |
| 46 'directory2', | 46 'directory2') |
| 47 options: {}) | |
| 48 .catchError((e) { | 47 .catchError((e) { |
| 49 expect(e.error.code, equals(FileError.NOT_FOUND_ERR)); | 48 expect(e.error.code, equals(FileError.NOT_FOUND_ERR)); |
| 50 }, test: (e) => e is FileError); | 49 }, test: (e) => e is FileError); |
| 51 }); | 50 }); |
| 52 | 51 |
| 53 test('directoryCreate', () { | 52 test('directoryCreate', () { |
| 54 return fs.root.getDirectory( | 53 return fs.root.createDirectory( |
| 55 'directory3', | 54 'directory3') |
| 56 options: {'create': true}) | |
| 57 .then((DirectoryEntry e) { | 55 .then((DirectoryEntry e) { |
| 58 expect(e.name, equals('directory3')); | 56 expect(e.name, equals('directory3')); |
| 59 }); | 57 }); |
| 60 }); | 58 }); |
| 61 } | 59 } |
| 62 }); | 60 }); |
| 63 | 61 |
| 64 group('getFile', () { | 62 group('getFile', () { |
| 65 if (FileSystem.supported) { | 63 if (FileSystem.supported) { |
| 66 test('getFileSystem', getFileSystem); | 64 test('getFileSystem', getFileSystem); |
| 67 | 65 |
| 68 test('fileDoesntExist', () { | 66 test('fileDoesntExist', () { |
| 69 return fs.root.getFile( | 67 return fs.root.getFile( |
| 70 'file2', | 68 'file2') |
| 71 options: {}) | |
| 72 .catchError((e) { | 69 .catchError((e) { |
| 73 expect(e.error.code, equals(FileError.NOT_FOUND_ERR)); | 70 expect(e.error.code, equals(FileError.NOT_FOUND_ERR)); |
| 74 }, test: (e) => e is FileError); | 71 }, test: (e) => e is FileError); |
| 75 }); | 72 }); |
| 76 | 73 |
| 77 test('fileCreate', () { | 74 test('fileCreate', () { |
| 78 return fs.root.getFile( | 75 return fs.root.createFile( |
| 79 'file4', | 76 'file4') |
| 80 options: {'create': true}) | |
| 81 .then((FileEntry e) { | 77 .then((FileEntry e) { |
| 82 expect(e.name, equals('file4')); | 78 expect(e.name, equals('file4')); |
| 83 expect(e.isFile, isTrue); | 79 expect(e.isFile, isTrue); |
| 84 return e.getMetadata(); | 80 return e.getMetadata(); |
| 85 }).then((Metadata metadata) { | 81 }).then((Metadata metadata) { |
| 86 var changeTime = metadata.modificationTime; | 82 var changeTime = metadata.modificationTime; |
| 87 // Upped because our Windows buildbots can sometimes be particularly | 83 // Upped because our Windows buildbots can sometimes be particularly |
| 88 // slow. | 84 // slow. |
| 89 expect(new DateTime.now().difference(changeTime).inMinutes, | 85 expect(new DateTime.now().difference(changeTime).inMinutes, |
| 90 lessThan(4)); | 86 lessThan(4)); |
| 91 expect(metadata.size, equals(0)); | 87 expect(metadata.size, equals(0)); |
| 92 }); | 88 }); |
| 93 }); | 89 }); |
| 94 } | 90 } |
| 95 }); | 91 }); |
| 96 | 92 |
| 97 // Do the boilerplate to get several files and directories created to then | 93 // Do the boilerplate to get several files and directories created to then |
| 98 // test the functions that use those items. | 94 // test the functions that use those items. |
| 99 Future doDirSetup() { | 95 Future doDirSetup() { |
| 100 return fs.root.getFile( | 96 return fs.root.createFile( |
| 101 'file4', | 97 'file4') |
| 102 options: {'create': true}) | |
| 103 .then((FileEntry file) { | 98 .then((FileEntry file) { |
| 104 return fs.root.getDirectory( | 99 return fs.root.createDirectory( |
| 105 'directory3', | 100 'directory3') |
| 106 options: {'create': true}) | |
| 107 .then((DirectoryEntry dir) { | 101 .then((DirectoryEntry dir) { |
| 108 return new Future.immediate(new FileAndDir(file, dir)); | 102 return new Future.immediate(new FileAndDir(file, dir)); |
| 109 }); | 103 }); |
| 110 }); | 104 }); |
| 111 } | 105 } |
| 112 | 106 |
| 113 group('directoryReader', () { | 107 group('directoryReader', () { |
| 114 if (FileSystem.supported) { | 108 if (FileSystem.supported) { |
| 115 test('getFileSystem', getFileSystem); | 109 test('getFileSystem', getFileSystem); |
| 116 | 110 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 }); | 144 }); |
| 151 }); | 145 }); |
| 152 | 146 |
| 153 test('moveTo', () { | 147 test('moveTo', () { |
| 154 return doDirSetup() | 148 return doDirSetup() |
| 155 .then((fileAndDir) { | 149 .then((fileAndDir) { |
| 156 return fileAndDir.file.moveTo(fileAndDir.dir, name: 'movedFile'); | 150 return fileAndDir.file.moveTo(fileAndDir.dir, name: 'movedFile'); |
| 157 }).then((entry) { | 151 }).then((entry) { |
| 158 expect(entry.name, 'movedFile'); | 152 expect(entry.name, 'movedFile'); |
| 159 expect(entry.fullPath, '/directory3/movedFile'); | 153 expect(entry.fullPath, '/directory3/movedFile'); |
| 160 return fs.root.getFile('file4', options: {'create': false}); | 154 return fs.root.getFile('file4'); |
| 161 }).catchError((e) { | 155 }).catchError((e) { |
| 162 expect(e.error.code, equals(FileError.NOT_FOUND_ERR)); | 156 expect(e.error.code, equals(FileError.NOT_FOUND_ERR)); |
| 163 }, test: (e) => e is FileError); | 157 }, test: (e) => e is FileError); |
| 164 }); | 158 }); |
| 165 | 159 |
| 166 test('remove', () { | 160 test('remove', () { |
| 167 return doDirSetup() | 161 return doDirSetup() |
| 168 .then((fileAndDir) { | 162 .then((fileAndDir) { |
| 169 return fileAndDir.file.remove().then((_) {}); | 163 return fileAndDir.file.remove().then((_) {}); |
| 170 }); | 164 }); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 195 expect(fileObj.name, fileAndDir.file.name); | 189 expect(fileObj.name, fileAndDir.file.name); |
| 196 expect(fileObj.relativePath, ''); | 190 expect(fileObj.relativePath, ''); |
| 197 expect(new DateTime.now().difference( | 191 expect(new DateTime.now().difference( |
| 198 fileObj.lastModifiedDate).inSeconds, lessThan(60)); | 192 fileObj.lastModifiedDate).inSeconds, lessThan(60)); |
| 199 }); | 193 }); |
| 200 }); | 194 }); |
| 201 }); | 195 }); |
| 202 } | 196 } |
| 203 }); | 197 }); |
| 204 } | 198 } |
| OLD | NEW |