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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http_server/lib/src/virtual_directory.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:unittest/unittest.dart"; 8 import "package:unittest/unittest.dart";
9 import "package:http_server/http_server.dart"; 9 import "package:http_server/http_server.dart";
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 return getStatusCode(server.port, '/dir/file') 108 return getStatusCode(server.port, '/dir/file')
109 .whenComplete(() { 109 .whenComplete(() {
110 server.close(); 110 server.close();
111 dir.deleteSync(recursive: true); 111 dir.deleteSync(recursive: true);
112 }); 112 });
113 }), completion(equals(HttpStatus.NOT_FOUND))); 113 }), completion(equals(HttpStatus.NOT_FOUND)));
114 }); 114 });
115 }); 115 });
116 }); 116 });
117 117
118 group('serve-dir', () {
119 group('top-level', () {
120 test('simple', () {
121 expect(HttpServer.bind('localhost', 0).then((server) {
122 var dir = new Directory('').createTempSync();
123 var virDir = new VirtualDirectory(dir.path);
124 virDir.allowDirectoryListing = true;
125
126 virDir.serve(server);
127
128 return getAsString(server.port, '/')
129 .whenComplete(() {
130 server.close();
131 dir.deleteSync();
132 });
133 }), completion(contains('Index of /')));
134 });
135
136 test('files', () {
137 expect(HttpServer.bind('localhost', 0).then((server) {
138 var dir = new Directory('').createTempSync();
139 var virDir = new VirtualDirectory(dir.path);
140 for (int i = 0; i < 10; i++) {
141 new File('${dir.path}/$i').createSync();
142 }
143 virDir.allowDirectoryListing = true;
144
145 virDir.serve(server);
146
147 return getAsString(server.port, '/')
148 .whenComplete(() {
149 server.close();
150 dir.deleteSync(recursive: true);
151 });
152 }), completion(contains('Index of /')));
153 });
154
155 test('dirs', () {
156 expect(HttpServer.bind('localhost', 0).then((server) {
157 var dir = new Directory('').createTempSync();
158 var virDir = new VirtualDirectory(dir.path);
159 for (int i = 0; i < 10; i++) {
160 new Directory('${dir.path}/$i').createSync();
161 }
162 virDir.allowDirectoryListing = true;
163
164 virDir.serve(server);
165
166 return getAsString(server.port, '/')
167 .whenComplete(() {
168 server.close();
169 dir.deleteSync(recursive: true);
170 });
171 }), completion(contains('Index of /')));
172 });
173
174 test('recursive-link', () {
175 expect(HttpServer.bind('localhost', 0).then((server) {
176 var dir = new Directory('').createTempSync();
177 var link = new Link('${dir.path}/recursive')..createSync('.');
178 var virDir = new VirtualDirectory(dir.path);
179 virDir.allowDirectoryListing = true;
180
181 virDir.serve(server);
182
183 return Future.wait([
184 getAsString(server.port, '/').then(
185 (s) => s.contains('recursive/')),
186 getAsString(server.port, '/').then(
187 (s) => !s.contains('../')),
188 getAsString(server.port, '/').then(
189 (s) => s.contains('Index of /')),
190 getAsString(server.port, '/recursive').then(
191 (s) => s.contains('recursive/')),
192 getAsString(server.port, '/recursive').then(
193 (s) => s.contains('../')),
194 getAsString(server.port, '/recursive').then(
195 (s) => s.contains('Index of /recursive'))])
196 .whenComplete(() {
197 server.close();
198 dir.deleteSync(recursive: true);
199 });
200 }), completion(equals([true, true, true, true, true, true])));
201 });
202 });
203
204 group('custom', () {
205 test('simple', () {
206 expect(HttpServer.bind('localhost', 0).then((server) {
207 var dir = new Directory('').createTempSync();
208 var virDir = new VirtualDirectory(dir.path);
209 virDir.allowDirectoryListing = true;
210 virDir.setDirectoryHandler((dir2, request) {
211 expect(dir2, isNotNull);
212 expect(FileSystemEntity.identicalSync(dir.path, dir2.path), isTrue);
213 request.response.write('My handler ${request.uri.path}');
214 request.response.close();
215 });
216
217 virDir.serve(server);
218
219 return getAsString(server.port, '/')
220 .whenComplete(() {
221 server.close();
222 dir.deleteSync();
223 });
224 }), completion(contains('My handler /')));
225 });
226 });
227 });
228
118 group('links', () { 229 group('links', () {
119 if (!Platform.isWindows) { 230 if (!Platform.isWindows) {
120 group('follow-links', () { 231 group('follow-links', () {
121 test('dir-link', () { 232 test('dir-link', () {
122 expect(HttpServer.bind('localhost', 0).then((server) { 233 expect(HttpServer.bind('localhost', 0).then((server) {
123 var dir = new Directory('').createTempSync(); 234 var dir = new Directory('').createTempSync();
124 var dir2 = new Directory('${dir.path}/dir2')..createSync(); 235 var dir2 = new Directory('${dir.path}/dir2')..createSync();
125 var link = new Link('${dir.path}/dir3')..createSync('dir2'); 236 var link = new Link('${dir.path}/dir3')..createSync('dir2');
126 var file = new File('${dir2.path}/file')..createSync(); 237 var file = new File('${dir2.path}/file')..createSync();
127 var virDir = new VirtualDirectory(dir.path); 238 var virDir = new VirtualDirectory(dir.path);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 469
359 return getAsString(server.port, '/') 470 return getAsString(server.port, '/')
360 .whenComplete(() { 471 .whenComplete(() {
361 server.close(); 472 server.close();
362 }); 473 });
363 }), completion(equals('my-page 404'))); 474 }), completion(equals('my-page 404')));
364 }); 475 });
365 }); 476 });
366 } 477 }
367 478
OLDNEW
« 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