| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 library file_apptests; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:convert'; | |
| 9 import 'dart:io'; | |
| 10 | |
| 11 import 'package:mojo_apptest/apptest.dart'; | |
| 12 import 'package:mojo/application.dart'; | |
| 13 import 'package:mojo/bindings.dart'; | |
| 14 import 'package:mojo/core.dart'; | |
| 15 | |
| 16 tests(Application application, String url) { | |
| 17 group('File Apptests', () { | |
| 18 test('Absolute path', () async { | |
| 19 String current = Directory.current.path; | |
| 20 for (String relative in ['abd', '..', '.', 'efg/hij', 'abc/']) { | |
| 21 if (current.endsWith('/')) { | |
| 22 expect(new File(relative).absolute.path, '$current$relative'); | |
| 23 } else { | |
| 24 expect(new File(relative).absolute.path, '$current/$relative'); | |
| 25 } | |
| 26 expect(new File(relative).absolute.isAbsolute, isTrue); | |
| 27 expect(new Directory(relative).absolute.path, | |
| 28 new Link(relative).absolute.path); | |
| 29 expect(new File(relative).absolute is File, isTrue); | |
| 30 expect(new Directory(relative).absolute is Directory, isTrue); | |
| 31 expect(new Link(relative).absolute is Link, isTrue); | |
| 32 } | |
| 33 for (String absolute in ['/abd', '/', '/./..\\', '/efg/hij', '/abc/']) { | |
| 34 expect(new File(absolute).absolute.path, absolute); | |
| 35 expect(new File(absolute).absolute.isAbsolute, isTrue); | |
| 36 } | |
| 37 }); | |
| 38 test('File Constructor', () async { | |
| 39 expect(new File('blåbærgrød'), isNotNull); | |
| 40 expect(new File('foo.txt'), isNotNull); | |
| 41 }); | |
| 42 test('Directory systemTemp', () async { | |
| 43 expect(Directory.systemTemp, isNotNull); | |
| 44 }); | |
| 45 test('Directory create', () async { | |
| 46 Directory directory = | |
| 47 await Directory.systemTemp.createTemp('dart_directory_test'); | |
| 48 Directory subDirectory = new Directory("${directory.path}/subdir"); | |
| 49 expect('$directory'.contains(directory.path), isTrue); | |
| 50 expect(await subDirectory.exists(), isFalse); | |
| 51 await subDirectory.create(); | |
| 52 expect(await subDirectory.exists(), isTrue); | |
| 53 File f = new File('${subDirectory.path}/file.txt'); | |
| 54 File fLong = new File('${directory.path}/subdir/../subdir/file.txt'); | |
| 55 expect(await f.exists(), isFalse); | |
| 56 await fLong.create(); | |
| 57 expect(await f.exists(), isTrue); | |
| 58 }); | |
| 59 test('Directory sync operation', () async { | |
| 60 Directory directory = new Directory('/foo'); | |
| 61 bool exceptionCaught = false; | |
| 62 try { | |
| 63 directory.statSync(); | |
| 64 // We shouldn't hit here. | |
| 65 fail("Directory.statSync is expected to throw."); | |
| 66 } on UnsupportedError catch (e) { | |
| 67 exceptionCaught = true; | |
| 68 } | |
| 69 expect(exceptionCaught, isTrue); | |
| 70 }); | |
| 71 test('Directory stat', () async { | |
| 72 Directory directory = | |
| 73 await Directory.systemTemp.createTemp('stat_test'); | |
| 74 FileStat fs = await directory.stat(); | |
| 75 expect(fs, isNotNull); | |
| 76 expect(fs.modeString(), "rwx------"); | |
| 77 expect(fs.type, equals(FileSystemEntityType.DIRECTORY)); | |
| 78 }); | |
| 79 test('Directory list', () async { | |
| 80 // Setup state. | |
| 81 Directory directory = | |
| 82 await Directory.systemTemp.createTemp('list_test'); | |
| 83 File f = new File('${directory.path}/child_file.txt'); | |
| 84 await f.create(); | |
| 85 Directory d = new Directory('${directory.path}/child_dir'); | |
| 86 await d.create(); | |
| 87 Directory d2 = new Directory('${d.path}/deeper_child_dir'); | |
| 88 await d2.create(); | |
| 89 | |
| 90 | |
| 91 // Non-recursive listing. | |
| 92 List<String> paths = new List<String>(); | |
| 93 await for (FileSystemEntity entity in directory.list()) { | |
| 94 paths.add(entity.path); | |
| 95 } | |
| 96 paths.sort(); | |
| 97 expect(paths.length, 4); | |
| 98 expect(paths[0].endsWith('/.'), isTrue); | |
| 99 expect(paths[1].endsWith('/..'), isTrue); | |
| 100 expect(paths[2].endsWith('/child_dir'), isTrue); | |
| 101 expect(paths[3].endsWith('/child_file.txt'), isTrue); | |
| 102 | |
| 103 // Recursive listing. | |
| 104 paths.clear(); | |
| 105 await for (FileSystemEntity entity in directory.list(recursive: true)) { | |
| 106 paths.add(entity.path); | |
| 107 } | |
| 108 paths.sort(); | |
| 109 expect(paths.length, 9); | |
| 110 expect(paths[0].endsWith('/.'), isTrue); | |
| 111 expect(paths[1].endsWith('/..'), isTrue); | |
| 112 expect(paths[2].endsWith('/child_dir'), isTrue); | |
| 113 expect(paths[3].endsWith('/child_dir/.'), isTrue); | |
| 114 expect(paths[4].endsWith('/child_dir/..'), isTrue); | |
| 115 expect(paths[5].endsWith('/child_dir/deeper_child_dir'), isTrue); | |
| 116 expect(paths[6].endsWith('/child_dir/deeper_child_dir/.'), isTrue); | |
| 117 expect(paths[7].endsWith('/child_dir/deeper_child_dir/..'), isTrue); | |
| 118 expect(paths[8].endsWith('/child_file.txt'), isTrue); | |
| 119 }); | |
| 120 test('Directory rename', () async { | |
| 121 // Setup state. | |
| 122 Directory directory = await Directory.systemTemp.createTemp('rename_dir'); | |
| 123 Directory childDirectory = new Directory('${directory.path}/child'); | |
| 124 await childDirectory.create(); | |
| 125 expect(await childDirectory.exists(), isTrue); | |
| 126 Directory newChildDirectory = | |
| 127 await childDirectory.rename('${directory.path}/new_child'); | |
| 128 expect(await newChildDirectory.exists(), isTrue); | |
| 129 expect(await childDirectory.exists(), isFalse); | |
| 130 }); | |
| 131 test('File rename', () async { | |
| 132 // Setup state. | |
| 133 Directory directory = await Directory.systemTemp.createTemp('rename'); | |
| 134 File childFile = new File('${directory.path}/child.txt'); | |
| 135 await childFile.create(); | |
| 136 expect(await childFile.exists(), isTrue); | |
| 137 File newChildFile = | |
| 138 await childFile.rename('${directory.path}/new_child.txt'); | |
| 139 expect(await newChildFile.exists(), isTrue); | |
| 140 expect(await childFile.exists(), isFalse); | |
| 141 }); | |
| 142 test('File delete', () async { | |
| 143 // Setup state. | |
| 144 Directory directory = await Directory.systemTemp.createTemp('fdel'); | |
| 145 File childFile = new File('${directory.path}/child.txt'); | |
| 146 expect(await childFile.exists(), isFalse); | |
| 147 await childFile.create(); | |
| 148 expect(await childFile.exists(), isTrue); | |
| 149 await childFile.delete(); | |
| 150 expect(await childFile.exists(), isFalse); | |
| 151 }); | |
| 152 test('Directory delete', () async { | |
| 153 // Setup state. | |
| 154 Directory directory = await Directory.systemTemp.createTemp('ddel'); | |
| 155 Directory child = new Directory('${directory.path}/child'); | |
| 156 expect(await child.exists(), isFalse); | |
| 157 await child.create(); | |
| 158 expect(await child.exists(), isTrue); | |
| 159 await child.delete(); | |
| 160 expect(await child.exists(), isFalse); | |
| 161 }); | |
| 162 test('Directory recursive delete', () async { | |
| 163 // NOTE: Recursive deletion is not yet implemented by mojo:files. | |
| 164 Directory directory = | |
| 165 await Directory.systemTemp.createTemp('recursive_del'); | |
| 166 expect(await directory.exists(), isTrue); | |
| 167 Directory childDirectory = new Directory('${directory.path}/child'); | |
| 168 await childDirectory.create(); | |
| 169 expect(await childDirectory.exists(), isTrue); | |
| 170 File newChildFile = new File('${childDirectory.path}/child.txt'); | |
| 171 await newChildFile.create(); | |
| 172 expect(await newChildFile.exists(), isTrue); | |
| 173 // Delete the directory recursively. | |
| 174 bool exceptionCaught = false; | |
| 175 try { | |
| 176 await directory.delete(recursive: true); | |
| 177 fail("Recursive deletion has now been implemented by mojo:files."); | |
| 178 } catch (e) { | |
| 179 exceptionCaught = true; | |
| 180 } | |
| 181 expect(exceptionCaught, isTrue); | |
| 182 // Verify that everything has been deleted. | |
| 183 // TODO(johnmccutchan): Uncomment once recursive deletion is implemented. | |
| 184 // expect(await directory.exists(), isFalse); | |
| 185 // expect(await newChildFile.exists(), isFalse); | |
| 186 // expect(await childDirectory.exists(), isFalse); | |
| 187 }); | |
| 188 }); | |
| 189 } | |
| OLD | NEW |