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', getObjectParams); | 21 result = await isolate.invokeRpcNoUpgrade('getObject', |
| 22 getObjectParams); |
22 expect(result['debuggable'], equals(true)); | 23 expect(result['debuggable'], equals(true)); |
23 | 24 |
24 // Change debuggable to false. | 25 // Change debuggable to false. |
25 var setDebugParams = { | 26 var setDebugParams = { |
26 'libraryId': isolate.rootLibrary.id, | 27 'libraryId': isolate.rootLibrary.id, |
27 'isDebuggable': false, | 28 'isDebuggable': false, |
28 }; | 29 }; |
29 result = await isolate.invokeRpcNoUpgrade( | 30 result = await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', |
30 'setLibraryDebuggable', setDebugParams); | 31 setDebugParams); |
31 expect(result['type'], equals('Success')); | 32 expect(result['type'], equals('Success')); |
32 | 33 |
33 // Verify. | 34 // Verify. |
34 result = await isolate.invokeRpcNoUpgrade('getObject', getObjectParams); | 35 result = await isolate.invokeRpcNoUpgrade('getObject', |
| 36 getObjectParams); |
35 expect(result['debuggable'], equals(false)); | 37 expect(result['debuggable'], equals(false)); |
| 38 |
36 }, | 39 }, |
37 | 40 |
38 // invalid library. | 41 // invalid library. |
39 (Isolate isolate) async { | 42 (Isolate isolate) async { |
40 var params = { | 43 var params = { |
41 'libraryId': 'libraries/9999999', | 44 'libraryId': 'libraries/9999999', |
42 'isDebuggable': false, | 45 'isDebuggable': false, |
43 }; | 46 }; |
44 bool caughtException; | 47 bool caughtException; |
45 try { | 48 try { |
46 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); | 49 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); |
47 expect(false, isTrue, reason: 'Unreachable'); | 50 expect(false, isTrue, reason:'Unreachable'); |
48 } on ServerRpcException catch (e) { | 51 } on ServerRpcException catch(e) { |
49 caughtException = true; | 52 caughtException = true; |
50 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 53 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
51 expect( | 54 expect(e.message, |
52 e.message, | 55 "setLibraryDebuggable: " |
53 "setLibraryDebuggable: " | 56 "invalid 'libraryId' parameter: libraries/9999999"); |
54 "invalid 'libraryId' parameter: libraries/9999999"); | |
55 } | 57 } |
56 expect(caughtException, isTrue); | 58 expect(caughtException, isTrue); |
57 }, | 59 }, |
58 | 60 |
59 // illegal (dart:_*) library. | 61 // illegal (dart:_*) library. |
60 (Isolate isolate) async { | 62 (Isolate isolate) async { |
61 await isolate.load(); | 63 await isolate.load(); |
62 Library dartInternal = isolate.libraries | 64 Library dartInternal = isolate.libraries.firstWhere( |
63 .firstWhere((Library library) => library.uri == 'dart:_internal'); | 65 (Library library) => library.uri == 'dart:_internal'); |
64 var params = { | 66 var params = { |
65 'libraryId': dartInternal.id, | 67 'libraryId': dartInternal.id, |
66 'isDebuggable': false, | 68 'isDebuggable': false, |
67 }; | 69 }; |
68 bool caughtException; | 70 bool caughtException; |
69 try { | 71 try { |
70 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); | 72 await isolate.invokeRpcNoUpgrade('setLibraryDebuggable', params); |
71 expect(false, isTrue, reason: 'Unreachable'); | 73 expect(false, isTrue, reason:'Unreachable'); |
72 } on ServerRpcException catch (e) { | 74 } on ServerRpcException catch(e) { |
73 caughtException = true; | 75 caughtException = true; |
74 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 76 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
75 expect( | 77 expect(e.message, |
76 e.message, | 78 "setLibraryDebuggable: " |
77 "setLibraryDebuggable: " | 79 "illegal 'libraryId' parameter: ${dartInternal.id}"); |
78 "illegal 'libraryId' parameter: ${dartInternal.id}"); | |
79 } | 80 } |
80 expect(caughtException, isTrue); | 81 expect(caughtException, isTrue); |
81 }, | 82 }, |
82 ]; | 83 ]; |
83 | 84 |
84 main(args) async => runIsolateTests(args, tests); | 85 main(args) async => runIsolateTests(args, tests); |
OLD | NEW |