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

Side by Side Diff: pkg/oauth2/test/credentials_test.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 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
« no previous file with comments | « pkg/oauth2/test/client_test.dart ('k') | pkg/oauth2/test/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 credentials_test; 5 library credentials_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:json' as JSON; 9 import 'dart:json' as JSON;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 expect(request.method, equals('POST')); 69 expect(request.method, equals('POST'));
70 expect(request.url.toString(), equals(tokenEndpoint.toString())); 70 expect(request.url.toString(), equals(tokenEndpoint.toString()));
71 expect(request.bodyFields, equals({ 71 expect(request.bodyFields, equals({
72 "grant_type": "refresh_token", 72 "grant_type": "refresh_token",
73 "refresh_token": "refresh token", 73 "refresh_token": "refresh token",
74 "scope": "scope1 scope2", 74 "scope": "scope1 scope2",
75 "client_id": "identifier", 75 "client_id": "identifier",
76 "client_secret": "secret" 76 "client_secret": "secret"
77 })); 77 }));
78 78
79 return new Future.immediate(new http.Response(JSON.stringify({ 79 return new Future.value(new http.Response(JSON.stringify({
80 'access_token': 'new access token', 80 'access_token': 'new access token',
81 'token_type': 'bearer', 81 'token_type': 'bearer',
82 'refresh_token': 'new refresh token' 82 'refresh_token': 'new refresh token'
83 }), 200, headers: {'content-type': 'application/json'})); 83 }), 200, headers: {'content-type': 'application/json'}));
84 }); 84 });
85 85
86 86
87 expect(credentials.refresh('identifier', 'secret', httpClient: httpClient) 87 expect(credentials.refresh('identifier', 'secret', httpClient: httpClient)
88 .then((credentials) { 88 .then((credentials) {
89 expect(credentials.accessToken, equals('new access token')); 89 expect(credentials.accessToken, equals('new access token'));
90 expect(credentials.refreshToken, equals('new refresh token')); 90 expect(credentials.refreshToken, equals('new refresh token'));
91 }), completes); 91 }), completes);
92 }); 92 });
93 93
94 test("uses the old refresh token if a new one isn't provided", () { 94 test("uses the old refresh token if a new one isn't provided", () {
95 var credentials = new oauth2.Credentials( 95 var credentials = new oauth2.Credentials(
96 'access token', 'refresh token', tokenEndpoint); 96 'access token', 'refresh token', tokenEndpoint);
97 expect(credentials.canRefresh, true); 97 expect(credentials.canRefresh, true);
98 98
99 httpClient.expectRequest((request) { 99 httpClient.expectRequest((request) {
100 expect(request.method, equals('POST')); 100 expect(request.method, equals('POST'));
101 expect(request.url.toString(), equals(tokenEndpoint.toString())); 101 expect(request.url.toString(), equals(tokenEndpoint.toString()));
102 expect(request.bodyFields, equals({ 102 expect(request.bodyFields, equals({
103 "grant_type": "refresh_token", 103 "grant_type": "refresh_token",
104 "refresh_token": "refresh token", 104 "refresh_token": "refresh token",
105 "client_id": "identifier", 105 "client_id": "identifier",
106 "client_secret": "secret" 106 "client_secret": "secret"
107 })); 107 }));
108 108
109 return new Future.immediate(new http.Response(JSON.stringify({ 109 return new Future.value(new http.Response(JSON.stringify({
110 'access_token': 'new access token', 110 'access_token': 'new access token',
111 'token_type': 'bearer' 111 'token_type': 'bearer'
112 }), 200, headers: {'content-type': 'application/json'})); 112 }), 200, headers: {'content-type': 'application/json'}));
113 }); 113 });
114 114
115 115
116 expect(credentials.refresh('identifier', 'secret', httpClient: httpClient) 116 expect(credentials.refresh('identifier', 'secret', httpClient: httpClient)
117 .then((credentials) { 117 .then((credentials) {
118 expect(credentials.accessToken, equals('new access token')); 118 expect(credentials.accessToken, equals('new access token'));
119 expect(credentials.refreshToken, equals('refresh token')); 119 expect(credentials.refreshToken, equals('refresh token'));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 expect(() => fromMap({"accessToken": "foo", "scopes": 12}), 171 expect(() => fromMap({"accessToken": "foo", "scopes": 12}),
172 throwsFormatException); 172 throwsFormatException);
173 }); 173 });
174 174
175 test("should throw a FormatException if expiration is not an int", () { 175 test("should throw a FormatException if expiration is not an int", () {
176 expect(() => fromMap({"accessToken": "foo", "expiration": "12"}), 176 expect(() => fromMap({"accessToken": "foo", "expiration": "12"}),
177 throwsFormatException); 177 throwsFormatException);
178 }); 178 });
179 }); 179 });
180 } 180 }
OLDNEW
« no previous file with comments | « pkg/oauth2/test/client_test.dart ('k') | pkg/oauth2/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698