Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.protocol; | 5 library test.protocol; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 142 |
| 143 | 143 |
| 144 @reflectiveTest | 144 @reflectiveTest |
| 145 class RequestTest { | 145 class RequestTest { |
| 146 void test_fromJson() { | 146 void test_fromJson() { |
| 147 Request original = new Request('one', 'aMethod'); | 147 Request original = new Request('one', 'aMethod'); |
| 148 String json = JSON.encode(original.toJson()); | 148 String json = JSON.encode(original.toJson()); |
| 149 Request request = new Request.fromString(json); | 149 Request request = new Request.fromString(json); |
| 150 expect(request.id, equals('one')); | 150 expect(request.id, equals('one')); |
| 151 expect(request.method, equals('aMethod')); | 151 expect(request.method, equals('aMethod')); |
| 152 expect(request.clientRequestTime, isNull); | |
| 152 } | 153 } |
| 153 | 154 |
| 154 void test_fromJson_invalidId() { | 155 void test_fromJson_invalidId() { |
| 155 String json = | 156 String json = |
| 156 '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}}'; | 157 '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}}'; |
| 157 Request request = new Request.fromString(json); | 158 Request request = new Request.fromString(json); |
| 158 expect(request, isNull); | 159 expect(request, isNull); |
| 159 } | 160 } |
| 160 | 161 |
| 161 void test_fromJson_invalidMethod() { | 162 void test_fromJson_invalidMethod() { |
| 162 String json = | 163 String json = |
| 163 '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}}'; | 164 '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}}'; |
| 164 Request request = new Request.fromString(json); | 165 Request request = new Request.fromString(json); |
| 165 expect(request, isNull); | 166 expect(request, isNull); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void test_fromJson_invalidParams() { | 169 void test_fromJson_invalidParams() { |
| 169 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; | 170 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; |
| 170 Request request = new Request.fromString(json); | 171 Request request = new Request.fromString(json); |
| 171 expect(request, isNull); | 172 expect(request, isNull); |
| 172 } | 173 } |
| 173 | 174 |
| 175 void test_fromJson_withBadClientTime() { | |
| 176 Request original = new Request('one', 'aMethod', null, 347); | |
| 177 Map<String, Object> map = original.toJson(); | |
| 178 // Insert bad value - should be int but client sent string instead | |
| 179 map[Request.CLIENT_REQUEST_TIME] = '347'; | |
| 180 String json = JSON.encode(map); | |
| 181 Request request = new Request.fromString(json); | |
| 182 expect(request.id, equals('one')); | |
| 183 expect(request.method, equals('aMethod')); | |
| 184 // Verify that bad value is ignored | |
|
Brian Wilkerson
2015/01/23 14:57:20
We should not ignore an invalid value. The field i
danrubel
2015/01/23 16:00:43
Good point. Done.
| |
| 185 expect(request.clientRequestTime, isNull); | |
| 186 } | |
| 187 | |
| 188 void test_fromJson_withClientTime() { | |
| 189 Request original = new Request('one', 'aMethod', null, 347); | |
| 190 String json = JSON.encode(original.toJson()); | |
| 191 Request request = new Request.fromString(json); | |
| 192 expect(request.id, equals('one')); | |
| 193 expect(request.method, equals('aMethod')); | |
| 194 expect(request.clientRequestTime, 347); | |
| 195 } | |
| 196 | |
| 174 void test_fromJson_withParams() { | 197 void test_fromJson_withParams() { |
| 175 Request original = new Request('one', 'aMethod', { | 198 Request original = new Request('one', 'aMethod', { |
| 176 'foo': 'bar' | 199 'foo': 'bar' |
| 177 }); | 200 }); |
| 178 String json = JSON.encode(original.toJson()); | 201 String json = JSON.encode(original.toJson()); |
| 179 Request request = new Request.fromString(json); | 202 Request request = new Request.fromString(json); |
| 180 expect(request.id, equals('one')); | 203 expect(request.id, equals('one')); |
| 181 expect(request.method, equals('aMethod')); | 204 expect(request.method, equals('aMethod')); |
| 182 expect(request.toJson()['params'], equals({ | 205 expect(request.toJson()['params'], equals({ |
| 183 'foo': 'bar' | 206 'foo': 'bar' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 expect(response.toJson(), equals({ | 239 expect(response.toJson(), equals({ |
| 217 Response.ID: '', | 240 Response.ID: '', |
| 218 Response.ERROR: { | 241 Response.ERROR: { |
| 219 'code': 'INVALID_REQUEST', | 242 'code': 'INVALID_REQUEST', |
| 220 'message': 'Invalid request' | 243 'message': 'Invalid request' |
| 221 } | 244 } |
| 222 })); | 245 })); |
| 223 } | 246 } |
| 224 | 247 |
| 225 void test_create_unanalyzedPriorityFiles() { | 248 void test_create_unanalyzedPriorityFiles() { |
| 226 Response response = | 249 Response response = new Response.unanalyzedPriorityFiles('0', 'file list'); |
| 227 new Response.unanalyzedPriorityFiles('0', 'file list'); | |
| 228 expect(response.id, equals('0')); | 250 expect(response.id, equals('0')); |
| 229 expect(response.error, isNotNull); | 251 expect(response.error, isNotNull); |
| 230 expect(response.toJson(), equals({ | 252 expect(response.toJson(), equals({ |
| 231 Response.ID: '0', | 253 Response.ID: '0', |
| 232 Response.ERROR: { | 254 Response.ERROR: { |
| 233 'code': 'UNANALYZED_PRIORITY_FILES', | 255 'code': 'UNANALYZED_PRIORITY_FILES', |
| 234 'message': "Unanalyzed files cannot be a priority: 'file list'" | 256 'message': "Unanalyzed files cannot be a priority: 'file list'" |
| 235 } | 257 } |
| 236 })); | 258 })); |
| 237 } | 259 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 Response original = new Response('myId', result: { | 291 Response original = new Response('myId', result: { |
| 270 'foo': 'bar' | 292 'foo': 'bar' |
| 271 }); | 293 }); |
| 272 Response response = new Response.fromJson(original.toJson()); | 294 Response response = new Response.fromJson(original.toJson()); |
| 273 expect(response.id, equals('myId')); | 295 expect(response.id, equals('myId')); |
| 274 Map<String, Object> result = response.toJson()['result']; | 296 Map<String, Object> result = response.toJson()['result']; |
| 275 expect(result.length, equals(1)); | 297 expect(result.length, equals(1)); |
| 276 expect(result['foo'], equals('bar')); | 298 expect(result['foo'], equals('bar')); |
| 277 } | 299 } |
| 278 } | 300 } |
| OLD | NEW |