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

Side by Side Diff: sdk/lib/_internal/pub/test/serve/utils.dart

Issue 137233021: Support index.html in pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 10 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 | « sdk/lib/_internal/pub/test/serve/serves_index_html_for_directories_test.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 d.file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 library pub_tests; 5 library pub_tests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:http/http.dart' as http; 11 import 'package:http/http.dart' as http;
12 import 'package:path/path.dart' as p;
12 import 'package:scheduled_test/scheduled_process.dart'; 13 import 'package:scheduled_test/scheduled_process.dart';
13 import 'package:scheduled_test/scheduled_test.dart'; 14 import 'package:scheduled_test/scheduled_test.dart';
14 15
15 import '../test_pub.dart'; 16 import '../test_pub.dart';
16 17
17 /// The pub process running "pub serve". 18 /// The pub process running "pub serve".
18 ScheduledProcess _pubServer; 19 ScheduledProcess _pubServer;
19 20
20 /// The ephemeral port assigned to the running server. 21 /// The ephemeral port assigned to the running server.
21 int _port; 22 int _port;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 /// Schedules an HTTP request to the running pub server with [urlPath] and 183 /// Schedules an HTTP request to the running pub server with [urlPath] and
183 /// verifies that it responds with a 404. 184 /// verifies that it responds with a 404.
184 void requestShould404(String urlPath) { 185 void requestShould404(String urlPath) {
185 schedule(() { 186 schedule(() {
186 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { 187 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) {
187 expect(response.statusCode, equals(404)); 188 expect(response.statusCode, equals(404));
188 }); 189 });
189 }, "request $urlPath"); 190 }, "request $urlPath");
190 } 191 }
191 192
193 /// Schedules an HTTP request to the running pub server with [urlPath] and
194 /// verifies that it responds with a redirect to the given [redirectTarget].
195 ///
196 /// [redirectTarget] may be either a [Matcher] or a string to match an exact
197 /// URL.
198 void requestShouldRedirect(String urlPath, redirectTarget) {
199 schedule(() {
200 var request = new http.Request("GET",
201 Uri.parse("http://127.0.0.1:$_port/$urlPath"));
202 request.followRedirects = false;
203 return request.send().then((response) {
204 expect(response.statusCode ~/ 100, equals(3));
205
206 expect(response.headers, containsPair('location', redirectTarget));
207 });
208 }, "request $urlPath");
209 }
210
192 /// Schedules an HTTP POST to the running pub server with [urlPath] and verifies 211 /// Schedules an HTTP POST to the running pub server with [urlPath] and verifies
193 /// that it responds with a 405. 212 /// that it responds with a 405.
194 void postShould405(String urlPath) { 213 void postShould405(String urlPath) {
195 schedule(() { 214 schedule(() {
196 return http.post("http://127.0.0.1:$_port/$urlPath").then((response) { 215 return http.post("http://127.0.0.1:$_port/$urlPath").then((response) {
197 expect(response.statusCode, equals(405)); 216 expect(response.statusCode, equals(405));
198 }); 217 });
199 }, "request $urlPath"); 218 }, "request $urlPath");
200 } 219 }
201 220
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 /// socket. It omitted, request is JSON encoded to a string first. 261 /// socket. It omitted, request is JSON encoded to a string first.
243 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { 262 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) {
244 schedule(() => _ensureWebSocket().then((_) { 263 schedule(() => _ensureWebSocket().then((_) {
245 if (encodeRequest) request = JSON.encode(request); 264 if (encodeRequest) request = JSON.encode(request);
246 _webSocket.add(request); 265 _webSocket.add(request);
247 return _webSocketBroadcastStream.first.then((value) { 266 return _webSocketBroadcastStream.first.then((value) {
248 expect(JSON.decode(value), expectation); 267 expect(JSON.decode(value), expectation);
249 }); 268 });
250 }), "send $request to web socket and expect reply that $expectation"); 269 }), "send $request to web socket and expect reply that $expectation");
251 } 270 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/serve/serves_index_html_for_directories_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698