| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 pub_tests; | 5 library pub_tests; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return _jsonRpcRequest(method, resolvedParams); | 351 return _jsonRpcRequest(method, resolvedParams); |
| 352 }).then((response) { | 352 }).then((response) { |
| 353 expect(response["error"]["code"], errorCode); | 353 expect(response["error"]["code"], errorCode); |
| 354 expect(response["error"]["message"], errorMessage); | 354 expect(response["error"]["message"], errorMessage); |
| 355 | 355 |
| 356 return response["error"]["data"]; | 356 return response["error"]["data"]; |
| 357 }); | 357 }); |
| 358 }, "send $method with $params to web socket and expect error $errorCode"); | 358 }, "send $method with $params to web socket and expect error $errorCode"); |
| 359 } | 359 } |
| 360 | 360 |
| 361 /// Validates that [root] was not bound to a port when pub serve started. |
| 362 Future expectNotServed(String root) { |
| 363 return schedule(() { |
| 364 expect(_ports.containsKey(root), isFalse); |
| 365 }); |
| 366 } |
| 367 |
| 361 /// The next id to use for a JSON-RPC 2.0 request. | 368 /// The next id to use for a JSON-RPC 2.0 request. |
| 362 var _rpcId = 0; | 369 var _rpcId = 0; |
| 363 | 370 |
| 364 /// Sends a JSON-RPC 2.0 request calling [method] with [params]. | 371 /// Sends a JSON-RPC 2.0 request calling [method] with [params]. |
| 365 /// | 372 /// |
| 366 /// Returns the response object. | 373 /// Returns the response object. |
| 367 Future<Map> _jsonRpcRequest(String method, Map params) { | 374 Future<Map> _jsonRpcRequest(String method, Map params) { |
| 368 var id = _rpcId++; | 375 var id = _rpcId++; |
| 369 _webSocket.add(JSON.encode({ | 376 _webSocket.add(JSON.encode({ |
| 370 "jsonrpc": "2.0", | 377 "jsonrpc": "2.0", |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 /// included. Unlike [getServerUrl], this should only be called after the ports | 414 /// included. Unlike [getServerUrl], this should only be called after the ports |
| 408 /// are known. | 415 /// are known. |
| 409 String _getServerUrlSync([String root, String path]) { | 416 String _getServerUrlSync([String root, String path]) { |
| 410 if (root == null) root = 'web'; | 417 if (root == null) root = 'web'; |
| 411 expect(_ports, contains(root)); | 418 expect(_ports, contains(root)); |
| 412 var url = "http://127.0.0.1:${_ports[root]}"; | 419 var url = "http://127.0.0.1:${_ports[root]}"; |
| 413 if (path != null) url = "$url/$path"; | 420 if (path != null) url = "$url/$path"; |
| 414 return url; | 421 return url; |
| 415 } | 422 } |
| 416 | 423 |
| OLD | NEW |