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

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

Issue 23596007: Remove usage of dart:json. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 7 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 unified diff | Download patch | Annotate | Revision Log
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 client_test; 5 library client_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:json' as JSON; 8 import 'dart:convert';
9 9
10 import 'package:http/http.dart' as http; 10 import 'package:http/http.dart' as http;
11 import 'package:oauth2/oauth2.dart' as oauth2; 11 import 'package:oauth2/oauth2.dart' as oauth2;
12 import 'package:unittest/unittest.dart'; 12 import 'package:unittest/unittest.dart';
13 13
14 import 'utils.dart'; 14 import 'utils.dart';
15 15
16 final Uri requestUri = Uri.parse("http://example.com/resource"); 16 final Uri requestUri = Uri.parse("http://example.com/resource");
17 17
18 final Uri tokenEndpoint = Uri.parse('http://example.com/token'); 18 final Uri tokenEndpoint = Uri.parse('http://example.com/token');
(...skipping 23 matching lines...) Expand all
42 "request", () { 42 "request", () {
43 var expiration = new DateTime.now().subtract(new Duration(hours: 1)); 43 var expiration = new DateTime.now().subtract(new Duration(hours: 1));
44 var credentials = new oauth2.Credentials( 44 var credentials = new oauth2.Credentials(
45 'access token', 'refresh token', tokenEndpoint, [], expiration); 45 'access token', 'refresh token', tokenEndpoint, [], expiration);
46 var client = new oauth2.Client('identifier', 'secret', credentials, 46 var client = new oauth2.Client('identifier', 'secret', credentials,
47 httpClient: httpClient); 47 httpClient: httpClient);
48 48
49 httpClient.expectRequest((request) { 49 httpClient.expectRequest((request) {
50 expect(request.method, equals('POST')); 50 expect(request.method, equals('POST'));
51 expect(request.url.toString(), equals(tokenEndpoint.toString())); 51 expect(request.url.toString(), equals(tokenEndpoint.toString()));
52 return new Future.value(new http.Response(JSON.stringify({ 52 return new Future.value(new http.Response(JSON.encode({
53 'access_token': 'new access token', 53 'access_token': 'new access token',
54 'token_type': 'bearer' 54 'token_type': 'bearer'
55 }), 200, headers: {'content-type': 'application/json'})); 55 }), 200, headers: {'content-type': 'application/json'}));
56 }); 56 });
57 57
58 httpClient.expectRequest((request) { 58 httpClient.expectRequest((request) {
59 expect(request.method, equals('GET')); 59 expect(request.method, equals('GET'));
60 expect(request.url.toString(), equals(requestUri.toString())); 60 expect(request.url.toString(), equals(requestUri.toString()));
61 expect(request.headers['authorization'], 61 expect(request.headers['authorization'],
62 equals('Bearer new access token')); 62 equals('Bearer new access token'));
(...skipping 29 matching lines...) Expand all
92 92
93 test("can manually refresh the credentials", () { 93 test("can manually refresh the credentials", () {
94 var credentials = new oauth2.Credentials( 94 var credentials = new oauth2.Credentials(
95 'access token', 'refresh token', tokenEndpoint); 95 'access token', 'refresh token', tokenEndpoint);
96 var client = new oauth2.Client('identifier', 'secret', credentials, 96 var client = new oauth2.Client('identifier', 'secret', credentials,
97 httpClient: httpClient); 97 httpClient: httpClient);
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 return new Future.value(new http.Response(JSON.stringify({ 102 return new Future.value(new http.Response(JSON.encode({
103 'access_token': 'new access token', 103 'access_token': 'new access token',
104 'token_type': 'bearer' 104 'token_type': 'bearer'
105 }), 200, headers: {'content-type': 'application/json'})); 105 }), 200, headers: {'content-type': 'application/json'}));
106 }); 106 });
107 107
108 expect(client.refreshCredentials().then((_) { 108 expect(client.refreshCredentials().then((_) {
109 expect(client.credentials.accessToken, equals('new access token')); 109 expect(client.credentials.accessToken, equals('new access token'));
110 }), completes); 110 }), completes);
111 }); 111 });
112 112
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return new Future.value(new http.Response('bad job', 401, 218 return new Future.value(new http.Response('bad job', 401,
219 headers: {'www-authenticate': 'Bearer'})); 219 headers: {'www-authenticate': 'Bearer'}));
220 }); 220 });
221 221
222 expect( 222 expect(
223 client.get(requestUri).then((response) => response.statusCode), 223 client.get(requestUri).then((response) => response.statusCode),
224 completion(equals(401))); 224 completion(equals(401)));
225 }); 225 });
226 }); 226 });
227 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698