OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // VMOptions=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 library set_library_debuggable_rpc_test; | 6 library set_library_debuggable_rpc_test; |
7 | 7 |
8 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 | 10 |
11 import 'test_helper.dart'; | 11 import 'test_helper.dart'; |
12 | 12 |
13 var tests = [ | 13 var tests = [ |
14 (Isolate isolate) async { | 14 (Isolate isolate) async { |
15 var result; | 15 var result; |
16 | 16 |
17 // debuggable defaults to true. | 17 // debuggable defaults to true. |
18 var getObjectParams = { | 18 var getObjectParams = { |
19 'objectId': isolate.rootLibrary.id, | 19 'objectId': isolate.rootLibrary.id, |
20 }; | 20 }; |
21 result = await isolate.invokeRpcNoUpgrade('getObject', | 21 result = await isolate.invokeRpcNoUpgrade('getObject', getObjectParams); |
22 getObjectParams); | |
23 expect(result['debuggable'], equals(true)); | 22 expect(result['debuggable'], equals(true)); |
24 | 23 |
25 // Change debuggable to false. | 24 // Change debuggable to false. |
26 var setDebugParams = { | 25 var setDebugParams = { |
27 'libraryId': isolate.rootLibrary.id, | 26 'libraryId': isolate.rootLibrary.id, |
28 'isDebuggable': false, | 27 'isDebuggable': false, |
29 }; | 28 }; |
30 result = await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', | 29 result = await isolate.invokeRpcNoUpgrade( |
31 setDebugParams); | 30 'setLibraryDebuggable', setDebugParams); |
32 expect(result['type'], equals('Success')); | 31 expect(result['type'], equals('Success')); |
33 | 32 |
34 // Verify. | 33 // Verify. |
35 result = await isolate.invokeRpcNoUpgrade('getObject', | 34 result = await isolate.invokeRpcNoUpgrade('getObject', getObjectParams); |
36 getObjectParams); | |
37 expect(result['debuggable'], equals(false)); | 35 expect(result['debuggable'], equals(false)); |
38 | |
39 }, | 36 }, |
40 | 37 |
41 // invalid library. | 38 // invalid library. |
42 (Isolate isolate) async { | 39 (Isolate isolate) async { |
43 var params = { | 40 var params = { |
44 'libraryId': 'libraries/9999999', | 41 'libraryId': 'libraries/9999999', |
45 'isDebuggable': false, | 42 'isDebuggable': false, |
46 }; | 43 }; |
47 bool caughtException; | 44 bool caughtException; |
48 try { | 45 try { |
49 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); | 46 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); |
50 expect(false, isTrue, reason:'Unreachable'); | 47 expect(false, isTrue, reason: 'Unreachable'); |
51 } on ServerRpcException catch(e) { | 48 } on ServerRpcException catch (e) { |
52 caughtException = true; | 49 caughtException = true; |
53 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 50 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
54 expect(e.message, | 51 expect( |
55 "setLibraryDebuggable: " | 52 e.message, |
56 "invalid 'libraryId' parameter: libraries/9999999"); | 53 "setLibraryDebuggable: " |
| 54 "invalid 'libraryId' parameter: libraries/9999999"); |
57 } | 55 } |
58 expect(caughtException, isTrue); | 56 expect(caughtException, isTrue); |
59 }, | 57 }, |
60 | 58 |
61 // illegal (dart:_*) library. | 59 // illegal (dart:_*) library. |
62 (Isolate isolate) async { | 60 (Isolate isolate) async { |
63 await isolate.load(); | 61 await isolate.load(); |
64 Library dartInternal = isolate.libraries.firstWhere( | 62 Library dartInternal = isolate.libraries |
65 (Library library) => library.uri == 'dart:_internal'); | 63 .firstWhere((Library library) => library.uri == 'dart:_internal'); |
66 var params = { | 64 var params = { |
67 'libraryId': dartInternal.id, | 65 'libraryId': dartInternal.id, |
68 'isDebuggable': false, | 66 'isDebuggable': false, |
69 }; | 67 }; |
70 bool caughtException; | 68 bool caughtException; |
71 try { | 69 try { |
72 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); | 70 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); |
73 expect(false, isTrue, reason:'Unreachable'); | 71 expect(false, isTrue, reason: 'Unreachable'); |
74 } on ServerRpcException catch(e) { | 72 } on ServerRpcException catch (e) { |
75 caughtException = true; | 73 caughtException = true; |
76 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 74 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
77 expect(e.message, | 75 expect( |
78 "setLibraryDebuggable: " | 76 e.message, |
79 "illegal 'libraryId' parameter: ${dartInternal.id}"); | 77 "setLibraryDebuggable: " |
| 78 "illegal 'libraryId' parameter: ${dartInternal.id}"); |
80 } | 79 } |
81 expect(caughtException, isTrue); | 80 expect(caughtException, isTrue); |
82 }, | 81 }, |
83 ]; | 82 ]; |
84 | 83 |
85 main(args) async => runIsolateTests(args, tests); | 84 main(args) async => runIsolateTests(args, tests); |
OLD | NEW |