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

Unified Diff: test/util/path_handler_test.dart

Issue 1076803003: Change the URL-space exposed by the browser server. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Changelog + pubspec Created 5 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 side-by-side diff with in-line comments
Download patch
« test/runner/loader_test.dart ('K') | « test/runner/pub_serve_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/util/path_handler_test.dart
diff --git a/test/util/path_handler_test.dart b/test/util/path_handler_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d6ea38f12f84b92140906c57b2de9bf36063e259
--- /dev/null
+++ b/test/util/path_handler_test.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+
+import 'package:shelf/shelf.dart' as shelf;
+import 'package:test/src/util/path_handler.dart';
+import 'package:test/test.dart';
+
+void main() {
+ var handler;
+ setUp(() => handler = new PathHandler());
+
+ _handle(request) => new Future.sync(() => handler.handler(request));
+
+ test("returns a 404 for a root URL", () {
+ var request = new shelf.Request("GET", Uri.parse("http://localhost/"));
+ return _handle(request).then((response) {
+ expect(response.statusCode, equals(404));
+ });
+ });
+
+ test("returns a 404 for an unregistered URL", () {
+ var request = new shelf.Request("GET", Uri.parse("http://localhost/foo"));
+ return _handle(request).then((response) {
+ expect(response.statusCode, equals(404));
+ });
+ });
+
+ test("runs a handler for an exact URL", () {
+ var request = new shelf.Request("GET", Uri.parse("http://localhost/foo"));
+ handler.add("foo", expectAsync((request) {
+ expect(request.handlerPath, equals('/foo'));
+ expect(request.url.path, isEmpty);
+ return new shelf.Response.ok("good job!");
+ }));
+
+ return _handle(request).then((response) {
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("good job!")));
+ });
+ });
+
+ test("runs a handler for a suffix", () {
+ var request = new shelf.Request(
+ "GET", Uri.parse("http://localhost/foo/bar"));
+ handler.add("foo", expectAsync((request) {
+ expect(request.handlerPath, equals('/foo/'));
+ expect(request.url.path, 'bar');
+ return new shelf.Response.ok("good job!");
+ }));
+
+ return _handle(request).then((response) {
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("good job!")));
+ });
+ });
+
+ test("runs the longest matching handler", () {
+ var request = new shelf.Request(
+ "GET", Uri.parse("http://localhost/foo/bar/baz"));
+
+ handler.add("foo", expectAsync((_) {}, count: 0));
+ handler.add("foo/bar", expectAsync((request) {
+ expect(request.handlerPath, equals('/foo/bar/'));
+ expect(request.url.path, 'baz');
+ return new shelf.Response.ok("good job!");
+ }));
+ handler.add("foo/bar/baz/bang", expectAsync((_) {}, count: 0));
+
+ return _handle(request).then((response) {
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("good job!")));
+ });
+ });
+}
« test/runner/loader_test.dart ('K') | « test/runner/pub_serve_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698