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

Side by Side Diff: pkg/oauth2/test/handle_access_token_response_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 handle_access_token_response_test; 5 library handle_access_token_response_test;
6 6
7 import 'dart:json' as JSON; 7 import 'dart:convert';
8 8
9 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
10 import 'package:oauth2/oauth2.dart' as oauth2; 10 import 'package:oauth2/oauth2.dart' as oauth2;
11 import 'package:oauth2/src/handle_access_token_response.dart'; 11 import 'package:oauth2/src/handle_access_token_response.dart';
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 tokenEndpoint = Uri.parse("https://example.com/token"); 16 final Uri tokenEndpoint = Uri.parse("https://example.com/token");
17 17
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 expect(() => handleError(body: 'not json'), 63 expect(() => handleError(body: 'not json'),
64 throwsFormatException); 64 throwsFormatException);
65 }); 65 });
66 66
67 test('with a non-string error causes a FormatException', () { 67 test('with a non-string error causes a FormatException', () {
68 expect(() => handleError(body: '{"error": 12}'), 68 expect(() => handleError(body: '{"error": 12}'),
69 throwsFormatException); 69 throwsFormatException);
70 }); 70 });
71 71
72 test('with a non-string error_description causes a FormatException', () { 72 test('with a non-string error_description causes a FormatException', () {
73 expect(() => handleError(body: JSON.stringify({ 73 expect(() => handleError(body: JSON.encode({
74 "error": "invalid_request", 74 "error": "invalid_request",
75 "error_description": 12 75 "error_description": 12
76 })), throwsFormatException); 76 })), throwsFormatException);
77 }); 77 });
78 78
79 test('with a non-string error_uri causes a FormatException', () { 79 test('with a non-string error_uri causes a FormatException', () {
80 expect(() => handleError(body: JSON.stringify({ 80 expect(() => handleError(body: JSON.encode({
81 "error": "invalid_request", 81 "error": "invalid_request",
82 "error_uri": 12 82 "error_uri": 12
83 })), throwsFormatException); 83 })), throwsFormatException);
84 }); 84 });
85 85
86 test('with a string error_description causes a AuthorizationException', () { 86 test('with a string error_description causes a AuthorizationException', () {
87 expect(() => handleError(body: JSON.stringify({ 87 expect(() => handleError(body: JSON.encode({
88 "error": "invalid_request", 88 "error": "invalid_request",
89 "error_description": "description" 89 "error_description": "description"
90 })), throwsAuthorizationException); 90 })), throwsAuthorizationException);
91 }); 91 });
92 92
93 test('with a string error_uri causes a AuthorizationException', () { 93 test('with a string error_uri causes a AuthorizationException', () {
94 expect(() => handleError(body: JSON.stringify({ 94 expect(() => handleError(body: JSON.encode({
95 "error": "invalid_request", 95 "error": "invalid_request",
96 "error_uri": "http://example.com/error" 96 "error_uri": "http://example.com/error"
97 })), throwsAuthorizationException); 97 })), throwsAuthorizationException);
98 }); 98 });
99 }); 99 });
100 100
101 group('a success response', () { 101 group('a success response', () {
102 oauth2.Credentials handleSuccess( 102 oauth2.Credentials handleSuccess(
103 {String contentType: "application/json", 103 {String contentType: "application/json",
104 accessToken: 'access token', 104 accessToken: 'access token',
105 tokenType: 'bearer', 105 tokenType: 'bearer',
106 expiresIn, 106 expiresIn,
107 refreshToken, 107 refreshToken,
108 scope}) { 108 scope}) {
109 return handle(new http.Response(JSON.stringify({ 109 return handle(new http.Response(JSON.encode({
110 'access_token': accessToken, 110 'access_token': accessToken,
111 'token_type': tokenType, 111 'token_type': tokenType,
112 'expires_in': expiresIn, 112 'expires_in': expiresIn,
113 'refresh_token': refreshToken, 113 'refresh_token': refreshToken,
114 'scope': scope 114 'scope': scope
115 }), 200, headers: {'content-type': contentType})); 115 }), 200, headers: {'content-type': contentType}));
116 } 116 }
117 117
118 test('returns the correct credentials', () { 118 test('returns the correct credentials', () {
119 var credentials = handleSuccess(); 119 var credentials = handleSuccess();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 test('with a non-string scope throws a FormatException', () { 181 test('with a non-string scope throws a FormatException', () {
182 expect(() => handleSuccess(scope: 12), throwsFormatException); 182 expect(() => handleSuccess(scope: 12), throwsFormatException);
183 }); 183 });
184 184
185 test('with a scope sets the scopes', () { 185 test('with a scope sets the scopes', () {
186 var credentials = handleSuccess(scope: "scope1 scope2"); 186 var credentials = handleSuccess(scope: "scope1 scope2");
187 expect(credentials.scopes, equals(["scope1", "scope2"])); 187 expect(credentials.scopes, equals(["scope1", "scope2"]));
188 }); 188 });
189 }); 189 });
190 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698