| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import "package:http_server/http_server.dart"; | 8 import "package:http_server/http_server.dart"; |
| 9 import 'package:path/path.dart' as pathos; | 9 import 'package:path/path.dart' as pathos; |
| 10 import "package:unittest/unittest.dart"; | 10 import "package:unittest/unittest.dart"; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return virDir.serveFile(new File(indexUri.toFilePath()), request); | 182 return virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 return getAsString(virDir, '/') | 185 return getAsString(virDir, '/') |
| 186 .then((result) { | 186 .then((result) { |
| 187 expect(result, 'index file'); | 187 expect(result, 'index file'); |
| 188 }); | 188 }); |
| 189 }); | 189 }); |
| 190 | 190 |
| 191 testVirtualDir('index-2', (dir) { | 191 testVirtualDir('index-2', (dir) { |
| 192 new Directory('${dir.path}/dir').createSync(); |
| 193 var virDir = new VirtualDirectory(dir.path); |
| 194 virDir.allowDirectoryListing = true; |
| 195 virDir.directoryHandler = (dir2, request) { |
| 196 fail('not expected'); |
| 197 }; |
| 198 return getStatusCodeForVirtDir(virDir, '/dir', followRedirects: false) |
| 199 .then((result) { |
| 200 expect(result, 301); |
| 201 }); |
| 202 }); |
| 203 |
| 204 testVirtualDir('index-3', (dir) { |
| 192 new File('${dir.path}/dir/index.html') | 205 new File('${dir.path}/dir/index.html') |
| 193 ..createSync(recursive: true) | 206 ..createSync(recursive: true) |
| 194 ..writeAsStringSync('index file'); | 207 ..writeAsStringSync('index file'); |
| 195 var virDir = new VirtualDirectory(dir.path); | 208 var virDir = new VirtualDirectory(dir.path); |
| 196 virDir.allowDirectoryListing = true; | 209 virDir.allowDirectoryListing = true; |
| 197 virDir.directoryHandler = (dir2, request) { | 210 virDir.directoryHandler = (dir2, request) { |
| 198 // Redirect directory-requests to index.html files. | 211 // Redirect directory-requests to index.html files. |
| 199 var indexUri = new Uri.file(dir2.path).resolve('index.html'); | 212 var indexUri = new Uri.file(dir2.path).resolve('index.html'); |
| 200 return virDir.serveFile(new File(indexUri.toFilePath()), request); | 213 return virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 201 }; | 214 }; |
| 215 return getAsString(virDir, '/dir') |
| 216 .then((result) { |
| 217 expect(result, 'index file'); |
| 218 }); |
| 219 }); |
| 202 | 220 |
| 203 return getAsString(virDir, '/dir') | 221 testVirtualDir('index-4', (dir) { |
| 222 new File('${dir.path}/dir/index.html') |
| 223 ..createSync(recursive: true) |
| 224 ..writeAsStringSync('index file'); |
| 225 var virDir = new VirtualDirectory(dir.path); |
| 226 virDir.allowDirectoryListing = true; |
| 227 virDir.directoryHandler = (dir2, request) { |
| 228 // Redirect directory-requests to index.html files. |
| 229 var indexUri = new Uri.file(dir2.path).resolve('index.html'); |
| 230 virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 231 }; |
| 232 return getAsString(virDir, '/dir/') |
| 204 .then((result) { | 233 .then((result) { |
| 205 expect(result, 'index file'); | 234 expect(result, 'index file'); |
| 206 }); | 235 }); |
| 207 }); | 236 }); |
| 208 }); | 237 }); |
| 209 }); | 238 }); |
| 210 | 239 |
| 211 group('links', () { | 240 group('links', () { |
| 212 if (!Platform.isWindows) { | 241 if (!Platform.isWindows) { |
| 213 group('follow-links', () { | 242 group('follow-links', () { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 return virDir.serveFile(new File('${d.path}/file'), request); | 528 return virDir.serveFile(new File('${d.path}/file'), request); |
| 500 }; | 529 }; |
| 501 | 530 |
| 502 return getAsString(virDir, '/') | 531 return getAsString(virDir, '/') |
| 503 .then((result) { | 532 .then((result) { |
| 504 expect(result, 'file contents'); | 533 expect(result, 'file contents'); |
| 505 }); | 534 }); |
| 506 }); | 535 }); |
| 507 }); | 536 }); |
| 508 } | 537 } |
| OLD | NEW |