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

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

Issue 11420025: Add a package for authenticating via OAuth2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Refresh token fixes and code review changes Created 8 years, 1 month 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 | « pkg/oauth2/test/handle_access_token_response_test.dart ('k') | utils/apidoc/apidoc.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/oauth2/test/utils.dart
diff --git a/pkg/oauth2/test/utils.dart b/pkg/oauth2/test/utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..631ea954751f24ce9aec4b072ad72276084c01aa
--- /dev/null
+++ b/pkg/oauth2/test/utils.dart
@@ -0,0 +1,82 @@
+// Copyright (c) 2012, 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.
+
+library utils;
+
+import '../../unittest/lib/unittest.dart';
+import '../../http/lib/http.dart' as http;
+import '../../http/lib/testing.dart';
+import '../lib/oauth2.dart' as oauth2;
+
+class ExpectClient extends MockClient {
+ final Queue<MockClientHandler> _handlers;
+
+ ExpectClient._(MockClientHandler fn)
+ : _handlers = new Queue<MockClientHandler>(),
+ super(fn);
+
+ factory ExpectClient() {
+ var client;
+ client = new ExpectClient._((request) =>
+ client._handleRequest(request));
+ return client;
+ }
+
+ void expectRequest(MockClientHandler fn) {
+ var completer = new Completer();
+ expect(completer.future, completes);
+
+ _handlers.add((request) {
+ completer.complete(null);
+ return fn(request);
+ });
+ }
+
+ Future<http.Response> _handleRequest(http.Request request) {
+ if (_handlers.isEmpty) {
+ return new Future.immediate(new http.Response('not found', 404));
+ } else {
+ return _handlers.removeFirst()(request);
+ }
+ }
+}
+
+// TODO(nweiz): remove this once it's built in to unittest
+/// A matcher for StateErrors.
+const isStateError = const _StateError();
+
+/// A matcher for functions that throw StateError.
+const Matcher throwsStateError =
+ const Throws(isStateError);
+
+class _StateError extends TypeMatcher {
+ const _StateError() : super("StateError");
+ bool matches(item, MatchState matchState) => item is StateError;
+}
+
+/// A matcher for AuthorizationExceptions.
+const isAuthorizationException = const _AuthorizationException();
+
+/// A matcher for functions that throw AuthorizationException.
+const Matcher throwsAuthorizationException =
+ const Throws(isAuthorizationException);
+
+class _AuthorizationException extends TypeMatcher {
+ const _AuthorizationException() : super("AuthorizationException");
+ bool matches(item, MatchState matchState) =>
+ item is oauth2.AuthorizationException;
+}
+
+/// A matcher for ExpirationExceptions.
+const isExpirationException = const _ExpirationException();
+
+/// A matcher for functions that throw ExpirationException.
+const Matcher throwsExpirationException =
+ const Throws(isExpirationException);
+
+class _ExpirationException extends TypeMatcher {
+ const _ExpirationException() : super("ExpirationException");
+ bool matches(item, MatchState matchState) =>
+ item is oauth2.ExpirationException;
+}
« no previous file with comments | « pkg/oauth2/test/handle_access_token_response_test.dart ('k') | utils/apidoc/apidoc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698