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

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

Issue 219733002: Make a slightly better 404 page for pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 8 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
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
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (match == null) return false; 197 if (match == null) return false;
198 _ports[match[1]] = int.parse(match[2]); 198 _ports[match[1]] = int.parse(match[2]);
199 return true; 199 return true;
200 } 200 }
201 201
202 void endPubServe() { 202 void endPubServe() {
203 _pubServer.kill(); 203 _pubServer.kill();
204 } 204 }
205 205
206 /// Schedules an HTTP request to the running pub server with [urlPath] and 206 /// Schedules an HTTP request to the running pub server with [urlPath] and
207 /// invokes [callback] with the response.
208 ///
209 /// [root] indicates which server should be accessed, and defaults to "web".
210 void scheduleRequest(String urlPath, callback(http.Response response),
nweiz 2014/04/01 19:20:28 You don't need to manually pass a callback here. [
Bob Nystrom 2014/04/01 19:40:57 Yeah, I thought about that, but I figured the poin
211 {String root}) {
212 schedule(() {
213 return http.get(_getServerUrlSync(root, urlPath)).then(callback);
214 }, "request $urlPath");
215 }
216
217 /// Schedules an HTTP request to the running pub server with [urlPath] and
207 /// verifies that it responds with a body that matches [expectation]. 218 /// verifies that it responds with a body that matches [expectation].
208 /// 219 ///
209 /// [expectation] may either be a [Matcher] or a string to match an exact body. 220 /// [expectation] may either be a [Matcher] or a string to match an exact body.
210 /// [root] indicates which server should be accessed, and defaults to "web". 221 /// [root] indicates which server should be accessed, and defaults to "web".
211 /// [headers] may be either a [Matcher] or a map to match an exact headers map. 222 /// [headers] may be either a [Matcher] or a map to match an exact headers map.
212 void requestShouldSucceed(String urlPath, expectation, {String root, headers}) { 223 void requestShouldSucceed(String urlPath, expectation, {String root, headers}) {
213 schedule(() { 224 scheduleRequest(urlPath, (response) {
214 return http.get(_getServerUrlSync(root, urlPath)).then((response) { 225 if (expectation != null) expect(response.body, expectation);
215 if (expectation != null) expect(response.body, expectation); 226 if (headers != null) expect(response.headers, headers);
216 if (headers != null) expect(response.headers, headers); 227 }, root: root);
217 });
218 }, "request $urlPath");
219 } 228 }
220 229
221 /// Schedules an HTTP request to the running pub server with [urlPath] and 230 /// Schedules an HTTP request to the running pub server with [urlPath] and
222 /// verifies that it responds with a 404. 231 /// verifies that it responds with a 404.
223 /// 232 ///
224 /// [root] indicates which server should be accessed, and defaults to "web". 233 /// [root] indicates which server should be accessed, and defaults to "web".
225 void requestShould404(String urlPath, {String root}) { 234 void requestShould404(String urlPath, {String root}) {
226 schedule(() { 235 scheduleRequest(urlPath, (response) {
227 return http.get(_getServerUrlSync(root, urlPath)).then((response) { 236 expect(response.statusCode, equals(404));
228 expect(response.statusCode, equals(404)); 237 }, root: root);
229 });
230 }, "request $urlPath");
231 } 238 }
232 239
233 /// Schedules an HTTP request to the running pub server with [urlPath] and 240 /// Schedules an HTTP request to the running pub server with [urlPath] and
234 /// verifies that it responds with a redirect to the given [redirectTarget]. 241 /// verifies that it responds with a redirect to the given [redirectTarget].
235 /// 242 ///
236 /// [redirectTarget] may be either a [Matcher] or a string to match an exact 243 /// [redirectTarget] may be either a [Matcher] or a string to match an exact
237 /// URL. [root] indicates which server should be accessed, and defaults to 244 /// URL. [root] indicates which server should be accessed, and defaults to
238 /// "web". 245 /// "web".
239 void requestShouldRedirect(String urlPath, redirectTarget, {String root}) { 246 void requestShouldRedirect(String urlPath, redirectTarget, {String root}) {
240 schedule(() { 247 schedule(() {
241 var request = new http.Request("GET", 248 var request = new http.Request("GET",
242 Uri.parse(_getServerUrlSync(root, urlPath))); 249 Uri.parse(_getServerUrlSync(root, urlPath)));
243 request.followRedirects = false; 250 request.followRedirects = false;
244 return request.send().then((response) { 251 return request.send().then((response) {
245 expect(response.statusCode ~/ 100, equals(3)); 252 expect(response.statusCode ~/ 100, equals(3));
246
247 expect(response.headers, containsPair('location', redirectTarget)); 253 expect(response.headers, containsPair('location', redirectTarget));
248 }); 254 });
249 }, "request $urlPath"); 255 }, "request $urlPath");
250 } 256 }
251 257
252 /// Schedules an HTTP POST to the running pub server with [urlPath] and verifies 258 /// Schedules an HTTP POST to the running pub server with [urlPath] and verifies
253 /// that it responds with a 405. 259 /// that it responds with a 405.
254 /// 260 ///
255 /// [root] indicates which server should be accessed, and defaults to "web". 261 /// [root] indicates which server should be accessed, and defaults to "web".
256 void postShould405(String urlPath, {String root}) { 262 void postShould405(String urlPath, {String root}) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 /// included. Unlike [getServerUrl], this should only be called after the ports 420 /// included. Unlike [getServerUrl], this should only be called after the ports
415 /// are known. 421 /// are known.
416 String _getServerUrlSync([String root, String path]) { 422 String _getServerUrlSync([String root, String path]) {
417 if (root == null) root = 'web'; 423 if (root == null) root = 'web';
418 expect(_ports, contains(root)); 424 expect(_ports, contains(root));
419 var url = "http://127.0.0.1:${_ports[root]}"; 425 var url = "http://127.0.0.1:${_ports[root]}";
420 if (path != null) url = "$url/$path"; 426 if (path != null) url = "$url/$path";
421 return url; 427 return url;
422 } 428 }
423 429
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698