Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: pkg/http_server/test/virtual_directory_test.dart

Issue 17833003: Add directory-listing to VirtualDirectory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http_server/lib/src/virtual_directory.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/test/virtual_directory_test.dart
diff --git a/pkg/http_server/test/virtual_directory_test.dart b/pkg/http_server/test/virtual_directory_test.dart
index 1c579dac071426420ef1e2a7a21ca61db06edec7..c020c3f2c831dc78eb2fd3f30c581cd784e0cf84 100644
--- a/pkg/http_server/test/virtual_directory_test.dart
+++ b/pkg/http_server/test/virtual_directory_test.dart
@@ -115,6 +115,117 @@ void main() {
});
});
+ group('serve-dir', () {
+ group('top-level', () {
+ test('simple', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var virDir = new VirtualDirectory(dir.path);
+ virDir.allowDirectoryListing = true;
+
+ virDir.serve(server);
+
+ return getAsString(server.port, '/')
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync();
+ });
+ }), completion(contains('Index of /')));
+ });
+
+ test('files', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var virDir = new VirtualDirectory(dir.path);
+ for (int i = 0; i < 10; i++) {
+ new File('${dir.path}/$i').createSync();
+ }
+ virDir.allowDirectoryListing = true;
+
+ virDir.serve(server);
+
+ return getAsString(server.port, '/')
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync(recursive: true);
+ });
+ }), completion(contains('Index of /')));
+ });
+
+ test('dirs', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var virDir = new VirtualDirectory(dir.path);
+ for (int i = 0; i < 10; i++) {
+ new Directory('${dir.path}/$i').createSync();
+ }
+ virDir.allowDirectoryListing = true;
+
+ virDir.serve(server);
+
+ return getAsString(server.port, '/')
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync(recursive: true);
+ });
+ }), completion(contains('Index of /')));
+ });
+
+ test('recursive-link', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var link = new Link('${dir.path}/recursive')..createSync('.');
+ var virDir = new VirtualDirectory(dir.path);
+ virDir.allowDirectoryListing = true;
+
+ virDir.serve(server);
+
+ return Future.wait([
+ getAsString(server.port, '/').then(
+ (s) => s.contains('recursive/')),
+ getAsString(server.port, '/').then(
+ (s) => !s.contains('../')),
+ getAsString(server.port, '/').then(
+ (s) => s.contains('Index of /')),
+ getAsString(server.port, '/recursive').then(
+ (s) => s.contains('recursive/')),
+ getAsString(server.port, '/recursive').then(
+ (s) => s.contains('../')),
+ getAsString(server.port, '/recursive').then(
+ (s) => s.contains('Index of /recursive'))])
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync(recursive: true);
+ });
+ }), completion(equals([true, true, true, true, true, true])));
+ });
+ });
+
+ group('custom', () {
+ test('simple', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var virDir = new VirtualDirectory(dir.path);
+ virDir.allowDirectoryListing = true;
+ virDir.setDirectoryHandler((dir2, request) {
+ expect(dir2, isNotNull);
+ expect(FileSystemEntity.identicalSync(dir.path, dir2.path), isTrue);
+ request.response.write('My handler ${request.uri.path}');
+ request.response.close();
+ });
+
+ virDir.serve(server);
+
+ return getAsString(server.port, '/')
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync();
+ });
+ }), completion(contains('My handler /')));
+ });
+ });
+ });
+
group('links', () {
if (!Platform.isWindows) {
group('follow-links', () {
« no previous file with comments | « pkg/http_server/lib/src/virtual_directory.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698