Index: test/inspector/debugger/get-possible-breakpoints.js |
diff --git a/test/inspector/debugger/get-possible-breakpoints.js b/test/inspector/debugger/get-possible-breakpoints.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..99bcb5c516f3089a37779c41078d47a71e2d45b0 |
--- /dev/null |
+++ b/test/inspector/debugger/get-possible-breakpoints.js |
@@ -0,0 +1,144 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+// Flags: --expose-gc |
+ |
+print("Test for Debugger.getPossibleBreakpoints"); |
+ |
+Protocol.Runtime.enable(); |
+Protocol.Debugger.enable(); |
+ |
+/** |
+ * - collected script |
dgozman
2016/11/03 21:13:13
Remove?
kozy
2016/11/03 22:17:13
Removed.
|
+ * - on paused |
+ */ |
+ |
+InspectorTest.runTestSuite([ |
+ function getPossibleBreakpointsInRange(next) { |
+ var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ return Promise.resolve().then(() => 42); }\n\n"; |
+ var scriptId; |
+ compileScript(source) |
+ .then(id => scriptId = id) |
+ .then(() => InspectorTest.log("Test start.scriptId != end.scriptId.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 0, scriptId: scriptId + "0" }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test not existing scriptId.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: "-1" }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test end < start.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 1, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test empty range in first line.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 16, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test one character range in first line.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 17, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test empty range in not first line.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber: 16, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test one character range in not first line.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber: 17, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test end is undefined")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test end.lineNumber > scripts.lineCount()")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber: 0, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test one string")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 1, columnNumber: 0, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(() => InspectorTest.log("Test end.columnNumber > end.line.length(), should be the same as previous.")) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 256, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(next); |
+ }, |
+ |
+ function getPossibleBreakpointsInArrow(next) { |
+ var source = "function foo() { return Promise.resolve().then(() => 239).then(() => 42).then(() => () => 42) }"; |
+ var scriptId; |
+ compileScript(source) |
+ .then(id => scriptId = id) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }})) |
+ .then(InspectorTest.logMessage) |
+ .then(next); |
+ }, |
+ |
+ function arrowFunctionFirstLine(next) { |
+ Protocol.Debugger.onPaused(message => { |
+ InspectorTest.log("paused in " + message.params.callFrames[0].functionName); |
+ InspectorTest.logMessage(message.params.callFrames[0].location); |
+ Protocol.Debugger.resume(); |
+ }); |
+ |
+ var source = `function foo1() { Promise.resolve().then(() => 42) } |
+function foo2() { Promise.resolve().then(() => 42) }`; |
+ waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, { lineNumber: 1, columnNumber: 0 }) |
+ .then(InspectorTest.logMessage) |
+ .then(setAllBreakpoints) |
+ .then(() => Protocol.Runtime.evaluate({ expression: "foo1(); foo2()"})) |
+ .then(next); |
+ }, |
+ |
+ function arrowFunctionOnPause(next) { |
+ function dumpAndResume(message) { |
+ InspectorTest.log("paused in " + message.params.callFrames[0].functionName); |
+ InspectorTest.logMessage(message.params.callFrames[0].location); |
+ Protocol.Debugger.resume(); |
+ } |
+ |
+ // TODO(kozyatinskiy): where pauses before foo3 and foo4 calls?! |
dgozman
2016/11/03 21:13:13
?!?!!11!111!!!?
kozy
2016/11/03 22:17:13
Removed.
|
+ var source = `debugger; function foo3() { Promise.resolve().then(() => 42) } |
+function foo4() { Promise.resolve().then(() => 42) };\nfoo3();\nfoo4();`; |
+ waitForPossibleBreakpointsOnPause(source, { lineNumber: 0, columnNumber: 0 }, undefined, next) |
+ .then(InspectorTest.logMessage) |
+ .then(setAllBreakpoints) |
+ .then(() => Protocol.Debugger.onPaused(dumpAndResume)) |
+ .then(() => Protocol.Debugger.resume()); |
+ } |
+ |
+]); |
+ |
+function compileScript(source) { |
+ var promise = Protocol.Debugger.onceScriptParsed().then(message => message.params.scriptId); |
+ Protocol.Runtime.compileScript({ expression: source, sourceURL: "", persistScript: true }); |
+ return promise; |
+} |
+ |
+function waitForPossibleBreakpoints(source, start, end) { |
+ var promise = Protocol.Debugger.onceScriptParsed() |
+ .then(msg => { (start || {}).scriptId = msg.params.scriptId; (end || {}).scriptId = msg.params.scriptId }) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: end })); |
+ Protocol.Runtime.evaluate({ expression: source }); |
+ return promise; |
+} |
+ |
+function waitForPossibleBreakpointsOnPause(source, start, end, next) { |
+ var promise = Protocol.Debugger.oncePaused() |
+ .then(msg => { (start || {}).scriptId = msg.params.callFrames[0].location.scriptId; (end || {}).scriptId = msg.params.callFrames[0].location.scriptId }) |
+ .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: end })); |
+ Protocol.Runtime.evaluate({ expression: source }).then(next); |
+ return promise; |
+} |
+ |
+function setAllBreakpoints(message) { |
+ var promises = []; |
+ for (var location of message.result.locations) |
+ promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(checkBreakpointAndDump)); |
+ return Promise.all(promises); |
+} |
+ |
+function checkBreakpointAndDump(message) { |
+ if (message.error) { |
+ InspectorTest.log("FAIL: error in setBreakpoint"); |
+ InspectorTest.logMessage(message); |
+ return; |
+ } |
+ var id_data = message.result.breakpointId.split(":"); |
+ if (id_data[1] * 1 !== message.result.actualLocation.lineNumber || id_data[2] * 1 !== message.result.actualLocation.columnNumber) { |
dgozman
2016/11/03 21:13:13
parseInt
kozy
2016/11/03 22:17:13
Done.
|
+ InspectorTest.log("FAIL: possible breakpoint was resolved in another location"); |
+ InspectorTest.logMessage(message); |
+ } |
+ InspectorTest.logMessage(message); |
+} |