| 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 import 'package:observatory/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'service_test_common.dart'; | 8 import 'service_test_common.dart'; |
| 9 import 'test_helper.dart'; | 9 import 'test_helper.dart'; |
| 10 import 'deferred_library.dart' deferred as deferredLib; | 10 import 'deferred_library.dart' deferred as deferredLib; |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 | 12 |
| 13 const int LINE_A = 24; | 13 const int LINE_A = 24; |
| 14 const int LINE_B = 26; | 14 const int LINE_B = 26; |
| 15 | 15 |
| 16 int value = 0; | 16 int value = 0; |
| 17 | 17 |
| 18 int incValue(int amount) { | 18 int incValue(int amount) { |
| 19 value += amount; | 19 value += amount; |
| 20 return amount; | 20 return amount; |
| 21 } | 21 } |
| 22 | 22 |
| 23 Future testMain() async { | 23 Future testMain() async { |
| 24 incValue(incValue(1)); // line A. | 24 incValue(incValue(1)); // line A. |
| 25 | 25 |
| 26 incValue(incValue(1)); // line B. | 26 incValue(incValue(1)); // line B. |
| 27 | 27 |
| 28 await deferredLib.loadLibrary(); | 28 await deferredLib.loadLibrary(); |
| 29 deferredLib.deferredTest(); | 29 deferredLib.deferredTest(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 var tests = [ | 32 var tests = [ |
| 33 hasPausedAtStart, | 33 hasPausedAtStart, |
| 34 | 34 |
| 35 // Test future breakpoints. | 35 // Test future breakpoints. |
| 36 (Isolate isolate) async { | 36 (Isolate isolate) async { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 completer.complete(null); | 88 completer.complete(null); |
| 89 } | 89 } |
| 90 }); | 90 }); |
| 91 await isolate.resume(); | 91 await isolate.resume(); |
| 92 await completer.future; | 92 await completer.future; |
| 93 | 93 |
| 94 // The second breakpoint hits after value has been modified once. | 94 // The second breakpoint hits after value has been modified once. |
| 95 expect((await rootLib.evaluate('value')).valueAsString, equals('1')); | 95 expect((await rootLib.evaluate('value')).valueAsString, equals('1')); |
| 96 | 96 |
| 97 // Remove the breakpoints. | 97 // Remove the breakpoints. |
| 98 expect( | 98 expect((await isolate.removeBreakpoint(futureBpt1)).type, |
| 99 (await isolate.removeBreakpoint(futureBpt1)).type, equals('Success')); | 99 equals('Success')); |
| 100 expect( | 100 expect((await isolate.removeBreakpoint(futureBpt2)).type, |
| 101 (await isolate.removeBreakpoint(futureBpt2)).type, equals('Success')); | 101 equals('Success')); |
| 102 }, | 102 }, |
| 103 | 103 |
| 104 // Test breakpoints in deferred libraries (latent breakpoints). | 104 // Test breakpoints in deferred libraries (latent breakpoints). |
| 105 (Isolate isolate) async { | 105 (Isolate isolate) async { |
| 106 var rootLib = isolate.rootLibrary; | 106 var rootLib = isolate.rootLibrary; |
| 107 var uri = rootLib.scripts[0].uri; | 107 var uri = rootLib.scripts[0].uri; |
| 108 var lastSlashPos = uri.lastIndexOf('/'); | 108 var lastSlashPos = uri.lastIndexOf('/'); |
| 109 var deferredUri = uri.substring(0, lastSlashPos) + '/deferred_library.dart'; | 109 var deferredUri =uri.substring(0, lastSlashPos) + '/deferred_library.dart'; |
| 110 | 110 |
| 111 // Latent breakpoint. | 111 // Latent breakpoint. |
| 112 var latentBpt1 = await isolate.addBreakpointByScriptUri(deferredUri, 15); | 112 var latentBpt1 = await isolate.addBreakpointByScriptUri(deferredUri, 15); |
| 113 expect(latentBpt1.number, equals(3)); | 113 expect(latentBpt1.number, equals(3)); |
| 114 expect(latentBpt1.resolved, isFalse); | 114 expect(latentBpt1.resolved, isFalse); |
| 115 expect(await latentBpt1.location.getLine(), equals(15)); | 115 expect(await latentBpt1.location.getLine(), equals(15)); |
| 116 expect(await latentBpt1.location.getColumn(), equals(null)); | 116 expect(await latentBpt1.location.getColumn(), equals(null)); |
| 117 | 117 |
| 118 // Latent breakpoint with specific column. | 118 // Latent breakpoint with specific column. |
| 119 var latentBpt2 = await isolate.addBreakpointByScriptUri(deferredUri, 15, 3); | 119 var latentBpt2 = |
| 120 await isolate.addBreakpointByScriptUri(deferredUri, 15, 3); |
| 120 expect(latentBpt2.number, equals(4)); | 121 expect(latentBpt2.number, equals(4)); |
| 121 expect(latentBpt2.resolved, isFalse); | 122 expect(latentBpt2.resolved, isFalse); |
| 122 expect(await latentBpt2.location.getLine(), equals(15)); | 123 expect(await latentBpt2.location.getLine(), equals(15)); |
| 123 expect(await latentBpt2.location.getColumn(), equals(3)); | 124 expect(await latentBpt2.location.getColumn(), equals(3)); |
| 124 | 125 |
| 125 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 126 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 126 Completer completer = new Completer(); | 127 Completer completer = new Completer(); |
| 127 var subscription; | 128 var subscription; |
| 128 var resolvedCount = 0; | 129 var resolvedCount = 0; |
| 129 subscription = stream.listen((ServiceEvent event) async { | 130 subscription = stream.listen((ServiceEvent event) async { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 expect(resolvedCount, equals(2)); | 143 expect(resolvedCount, equals(2)); |
| 143 expect(latentBpt1.resolved, isTrue); | 144 expect(latentBpt1.resolved, isTrue); |
| 144 expect(await latentBpt1.location.getLine(), equals(15)); | 145 expect(await latentBpt1.location.getLine(), equals(15)); |
| 145 expect(await latentBpt1.location.getColumn(), equals(12)); | 146 expect(await latentBpt1.location.getColumn(), equals(12)); |
| 146 expect(latentBpt2.resolved, isTrue); | 147 expect(latentBpt2.resolved, isTrue); |
| 147 expect(await latentBpt2.location.getLine(), equals(15)); | 148 expect(await latentBpt2.location.getLine(), equals(15)); |
| 148 expect(await latentBpt2.location.getColumn(), equals(3)); | 149 expect(await latentBpt2.location.getColumn(), equals(3)); |
| 149 | 150 |
| 150 // The first breakpoint hits before value is modified. | 151 // The first breakpoint hits before value is modified. |
| 151 expect((await rootLib.evaluate('deferredLib.value')).valueAsString, | 152 expect((await rootLib.evaluate('deferredLib.value')).valueAsString, |
| 152 equals('0')); | 153 equals('0')); |
| 153 | 154 |
| 154 stream = await isolate.vm.getEventStream(VM.kDebugStream); | 155 stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 155 completer = new Completer(); | 156 completer = new Completer(); |
| 156 subscription = stream.listen((ServiceEvent event) async { | 157 subscription = stream.listen((ServiceEvent event) async { |
| 157 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 158 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 158 subscription.cancel(); | 159 subscription.cancel(); |
| 159 completer.complete(null); | 160 completer.complete(null); |
| 160 } | 161 } |
| 161 }); | 162 }); |
| 162 await isolate.resume(); | 163 await isolate.resume(); |
| 163 await completer.future; | 164 await completer.future; |
| 164 | 165 |
| 165 // The second breakpoint hits after value has been modified once. | 166 // The second breakpoint hits after value has been modified once. |
| 166 expect((await rootLib.evaluate('deferredLib.value')).valueAsString, | 167 expect((await rootLib.evaluate('deferredLib.value')).valueAsString, |
| 167 equals('-1')); | 168 equals('-1')); |
| 168 | 169 |
| 169 // Remove the breakpoints. | 170 // Remove the breakpoints. |
| 170 expect( | 171 expect((await isolate.removeBreakpoint(latentBpt1)).type, |
| 171 (await isolate.removeBreakpoint(latentBpt1)).type, equals('Success')); | 172 equals('Success')); |
| 172 expect( | 173 expect((await isolate.removeBreakpoint(latentBpt2)).type, |
| 173 (await isolate.removeBreakpoint(latentBpt2)).type, equals('Success')); | 174 equals('Success')); |
| 174 }, | 175 }, |
| 175 | 176 |
| 177 |
| 176 // Test resolution of column breakpoints. | 178 // Test resolution of column breakpoints. |
| 177 (Isolate isolate) async { | 179 (Isolate isolate) async { |
| 178 var script = isolate.rootLibrary.scripts[0]; | 180 var script = isolate.rootLibrary.scripts[0]; |
| 179 // Try all columns, including some columns that are too big. | 181 // Try all columns, including some columns that are too big. |
| 180 for (int col = 1; col <= 50; col++) { | 182 for (int col = 1; col <= 50; col++) { |
| 181 var bpt = await isolate.addBreakpoint(script, LINE_A, col); | 183 var bpt = await isolate.addBreakpoint(script, LINE_A, col); |
| 182 expect(bpt.resolved, isTrue); | 184 expect(bpt.resolved, isTrue); |
| 183 int resolvedLine = await bpt.location.getLine(); | 185 int resolvedLine = await bpt.location.getLine(); |
| 184 int resolvedCol = await bpt.location.getColumn(); | 186 int resolvedCol = await bpt.location.getColumn(); |
| 185 print('20:${col} -> ${resolvedLine}:${resolvedCol}'); | 187 print('20:${col} -> ${resolvedLine}:${resolvedCol}'); |
| 186 if (col <= 10) { | 188 if (col <= 10) { |
| 187 expect(resolvedLine, equals(LINE_A)); | 189 expect(resolvedLine, equals(LINE_A)); |
| 188 expect(resolvedCol, equals(3)); | 190 expect(resolvedCol, equals(3)); |
| 189 } else if (col <= 19) { | 191 } else if (col <= 19) { |
| 190 expect(resolvedLine, equals(LINE_A)); | 192 expect(resolvedLine, equals(LINE_A)); |
| 191 expect(resolvedCol, equals(12)); | 193 expect(resolvedCol, equals(12)); |
| 192 } else { | 194 } else { |
| 193 expect(resolvedLine, equals(LINE_B)); | 195 expect(resolvedLine, equals(LINE_B)); |
| 194 expect(resolvedCol, equals(12)); | 196 expect(resolvedCol, equals(12)); |
| 195 } | 197 } |
| 196 expect((await isolate.removeBreakpoint(bpt)).type, equals('Success')); | 198 expect((await isolate.removeBreakpoint(bpt)).type, equals('Success')); |
| 197 } | 199 } |
| 198 | 200 |
| 199 // Make sure that a zero column is an error. | 201 // Make sure that a zero column is an error. |
| 200 var caughtException = false; | 202 var caughtException = false; |
| 201 try { | 203 try { |
| 202 await isolate.addBreakpoint(script, 20, 0); | 204 await isolate.addBreakpoint(script, 20, 0); |
| 203 expect(false, isTrue, reason: 'Unreachable'); | 205 expect(false, isTrue, reason:'Unreachable'); |
| 204 } on ServerRpcException catch (e) { | 206 } on ServerRpcException catch(e) { |
| 205 caughtException = true; | 207 caughtException = true; |
| 206 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 208 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
| 207 expect(e.message, "addBreakpoint: invalid 'column' parameter: 0"); | 209 expect(e.message, |
| 210 "addBreakpoint: invalid 'column' parameter: 0"); |
| 208 } | 211 } |
| 209 expect(caughtException, isTrue); | 212 expect(caughtException, isTrue); |
| 210 }, | 213 }, |
| 211 ]; | 214 ]; |
| 212 | 215 |
| 213 main(args) => runIsolateTests(args, tests, | 216 main(args) => runIsolateTests(args, tests, |
| 214 testeeConcurrent: testMain, pause_on_start: true); | 217 testeeConcurrent: testMain, |
| 218 pause_on_start: true); |
| OLD | NEW |