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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
« no previous file with comments | « pkg/oauth2/lib/src/utils.dart ('k') | pkg/oauth2/test/client_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/oauth2/test/authorization_code_grant_test.dart
diff --git a/pkg/oauth2/test/authorization_code_grant_test.dart b/pkg/oauth2/test/authorization_code_grant_test.dart
index 2b80cf4544fe52442db2417c3c23817ddb1fb08e..e896dca25a2be039cdfdf74cd3c28240a0e64f01 100644
--- a/pkg/oauth2/test/authorization_code_grant_test.dart
+++ b/pkg/oauth2/test/authorization_code_grant_test.dart
@@ -30,6 +30,12 @@ void createGrant() {
httpClient: client);
}
+void expectFutureThrows(future, predicate) {
+ future.catchError(expectAsync1((AsyncError e) {
+ expect(predicate(e.error), isTrue);
+ }));
+}
+
void main() {
group('.getAuthorizationUrl', () {
setUp(createGrant);
@@ -83,7 +89,8 @@ void main() {
test("can't be called twice", () {
grant.getAuthorizationUrl(redirectUrl);
- expect(() => grant.getAuthorizationUrl(redirectUrl), throwsStateError);
+ expectFutureThrows(grant.getAuthorizationUrl(redirectUrl),
+ (e) => e is StateError);
});
});
@@ -91,39 +98,44 @@ void main() {
setUp(createGrant);
test("can't be called before .getAuthorizationUrl", () {
- expect(grant.handleAuthorizationResponse({}), throwsStateError);
+ expectFutureThrows(grant.handleAuthorizationResponse({}),
+ (e) => e is StateError);
});
test("can't be called twice", () {
grant.getAuthorizationUrl(redirectUrl);
grant.handleAuthorizationResponse({'code': 'auth code'});
- expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
- throwsStateError);
+ expectFutureThrows(
+ grant.handleAuthorizationResponse({'code': 'auth code'}),
+ (e) => e is StateError);
});
test('must have a state parameter if the authorization URL did', () {
grant.getAuthorizationUrl(redirectUrl, state: 'state');
- expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
- throwsFormatException);
+ expectFutureThrows(
+ grant.handleAuthorizationResponse({'code': 'auth code'}),
+ (e) => e is FormatException);
});
test('must have the same state parameter the authorization URL did', () {
grant.getAuthorizationUrl(redirectUrl, state: 'state');
- expect(grant.handleAuthorizationResponse({
+ expectFutureThrows(grant.handleAuthorizationResponse({
'code': 'auth code',
'state': 'other state'
- }), throwsFormatException);
+ }), (e) => e is FormatException);
});
test('must have a code parameter', () {
grant.getAuthorizationUrl(redirectUrl);
- expect(grant.handleAuthorizationResponse({}), throwsFormatException);
+ expectFutureThrows(grant.handleAuthorizationResponse({}),
+ (e) => e is FormatException);
});
test('with an error parameter throws an AuthorizationException', () {
grant.getAuthorizationUrl(redirectUrl);
- expect(grant.handleAuthorizationResponse({'error': 'invalid_request'}),
- throwsAuthorizationException);
+ expectFutureThrows(
+ grant.handleAuthorizationResponse({'error': 'invalid_request'}),
+ (e) => e is AuthorizationException);
});
test('sends an authorization code request', () {
@@ -163,8 +175,8 @@ void main() {
test("can't be called twice", () {
grant.getAuthorizationUrl(redirectUrl);
grant.handleAuthorizationCode('auth code');
- expect(grant.handleAuthorizationCode('auth code'),
- throwsStateError);
+ expectFutureThrows(grant.handleAuthorizationCode('auth code'),
+ (e) => e is StateError);
});
test('sends an authorization code request', () {
« no previous file with comments | « pkg/oauth2/lib/src/utils.dart ('k') | pkg/oauth2/test/client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698