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

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

Issue 120343005: pkg/http_server more virtual dir test cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: CR nits Created 6 years, 11 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 | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/test/utils.dart
diff --git a/pkg/http_server/test/utils.dart b/pkg/http_server/test/utils.dart
index f1159c50acaba11cbdc3ee0b6702720637b4c8d0..6414b48117ff7d76332259e474d513a9596ff1f1 100644
--- a/pkg/http_server/test/utils.dart
+++ b/pkg/http_server/test/utils.dart
@@ -7,6 +7,34 @@ library utils;
import 'dart:async';
import 'dart:convert';
import 'dart:io';
+import "package:unittest/unittest.dart";
+
+import 'package:http_server/http_server.dart';
+
+void testVirtualDir(String name, Future func(Directory dir)) {
+ test(name, () {
+ var dir = Directory.systemTemp.createTempSync('http_server_virtual_');
+
+ return func(dir)
+ .whenComplete(() {
+ return dir.delete(recursive: true);
+ });
+ });
+}
+
+Future<int> getStatusCodeForVirtDir(VirtualDirectory virtualDir,
+ String path,
+ {String host,
+ bool secure: false,
+ DateTime ifModifiedSince,
+ bool rawPath: false}) {
+ return _withServer((server) {
+
+ virtualDir.serve(server);
+ return getStatusCode(server.port, path, host: host, secure: secure,
+ ifModifiedSince: ifModifiedSince, rawPath: rawPath);
+ });
+}
Future<int> getStatusCode(int port,
String path,
@@ -38,21 +66,37 @@ Future<int> getStatusCode(int port,
(_) => response.statusCode));
}
+Future<HttpHeaders> getHeaders(VirtualDirectory virDir, String path) {
+ return _withServer((server) {
+ virDir.serve(server);
-Future<HttpHeaders> getHeaders(int port, String path) =>
- new HttpClient()
- .get('localhost', port, path)
- .then((request) => request.close())
- .then((response) => response.drain().then(
- (_) => response.headers));
+ return new HttpClient()
+ .get('localhost', server.port, path)
+ .then((request) => request.close())
+ .then((response) => response.drain().then((_) => response.headers));
+ });
+}
+Future<String> getAsString(VirtualDirectory virtualDir, String path) {
+ return _withServer((server) {
+ virtualDir.serve(server);
+ return new HttpClient()
+ .get('localhost', server.port, path)
+ .then((request) => request.close())
+ .then((response) => UTF8.decodeStream(response));
+ });
+}
-Future<String> getAsString(int port, String path) =>
- new HttpClient()
- .get('localhost', port, path)
- .then((request) => request.close())
- .then((response) => UTF8.decodeStream(response));
+Future _withServer(Future func(HttpServer server)) {
+ HttpServer server;
+ return HttpServer.bind('localhost', 0)
+ .then((value) {
+ server = value;
+ return func(server);
+ })
+ .whenComplete(server.close);
+}
const CERTIFICATE = "localhost_cert";
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698