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

Unified Diff: mojo/public/dart/third_party/test/test/util/one_off_handler_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
Index: mojo/public/dart/third_party/test/test/util/one_off_handler_test.dart
diff --git a/mojo/public/dart/third_party/test/test/util/one_off_handler_test.dart b/mojo/public/dart/third_party/test/test/util/one_off_handler_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..44c2e4cbbce96678092cfd8905c52eebab15eeda
--- /dev/null
+++ b/mojo/public/dart/third_party/test/test/util/one_off_handler_test.dart
@@ -0,0 +1,74 @@
+// 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/one_off_handler.dart';
+import 'package:test/test.dart';
+
+void main() {
+ var handler;
+ setUp(() => handler = new OneOffHandler());
+
+ _handle(request) => new Future.sync(() => handler.handler(request));
+
+ test("returns a 404 for a root URL", () async {
+ var request = new shelf.Request("GET", Uri.parse("http://localhost/"));
+ expect((await _handle(request)).statusCode, equals(404));
+ });
+
+ test("returns a 404 for an unhandled URL", () async {
+ var request = new shelf.Request("GET", Uri.parse("http://localhost/1"));
+ expect((await _handle(request)).statusCode, equals(404));
+ });
+
+ test("passes a request to a handler only once", () async {
+ var path = handler.create(expectAsync((request) {
+ expect(request.method, equals("GET"));
+ return new shelf.Response.ok("good job!");
+ }));
+
+ var request = new shelf.Request("GET", Uri.parse("http://localhost/$path"));
+ var response = await _handle(request);
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("good job!")));
+
+ request = new shelf.Request("GET", Uri.parse("http://localhost/$path"));
+ expect((await _handle(request)).statusCode, equals(404));
+ });
+
+ test("passes requests to the correct handlers", () async {
+ var path1 = handler.create(expectAsync((request) {
+ expect(request.method, equals("GET"));
+ return new shelf.Response.ok("one");
+ }));
+
+ var path2 = handler.create(expectAsync((request) {
+ expect(request.method, equals("GET"));
+ return new shelf.Response.ok("two");
+ }));
+
+ var path3 = handler.create(expectAsync((request) {
+ expect(request.method, equals("GET"));
+ return new shelf.Response.ok("three");
+ }));
+
+ var request = new shelf.Request(
+ "GET", Uri.parse("http://localhost/$path2"));
+ var response = await _handle(request);
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("two")));
+
+ request = new shelf.Request("GET", Uri.parse("http://localhost/$path1"));
+ response = await _handle(request);
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("one")));
+
+ request = new shelf.Request("GET", Uri.parse("http://localhost/$path3"));
+ response = await _handle(request);
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals("three")));
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698