Commit 5e57f660 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector] prepare inspector tests for liveedit rework

Extracted from https://chromium-review.googlesource.com/c/v8/v8/+/1105493

R=dgozman@chromium.org

Bug: v8:7862
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ibd2fb5341e617929b07b26abea31a1579a456d93
Reviewed-on: https://chromium-review.googlesource.com/1107312Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53899}
parent 618bc445
......@@ -11,13 +11,9 @@ Running test: testIncorrectScriptId
Running test: testSourceWithSyntaxError
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 2
exceptionId : <exceptionId>
lineNumber : 0
text : Invalid or unexpected token
}
error : {
code : -32000
message : Uncaught [object Object]
}
id : <messageId>
}
......@@ -2,22 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start('Check that setScriptSource completes correctly when an exception is thrown.');
let {session, contextGroup, Protocol} = InspectorTest.start(
'Check that setScriptSource completes correctly when an exception is' +
' thrown.');
Protocol.Debugger.enable();
InspectorTest.runTestSuite([
function testIncorrectScriptId(next) {
Protocol.Debugger.setScriptSource({ scriptId: '-1', scriptSource: '0' })
.then(InspectorTest.logMessage)
.then(next);
InspectorTest.runAsyncTestSuite([
async function testIncorrectScriptId() {
InspectorTest.logMessage(await Protocol.Debugger.setScriptSource(
{scriptId: '-1', scriptSource: '0'}));
},
function testSourceWithSyntaxError(next) {
Protocol.Debugger.onceScriptParsed()
.then(message => Protocol.Debugger.setScriptSource({ scriptId: message.params.scriptId, scriptSource: 'a # b' }))
.then(InspectorTest.logMessage)
.then(next);
async function testSourceWithSyntaxError() {
contextGroup.addScript('function foo() {}');
const {params} = await Protocol.Debugger.onceScriptParsed();
const msg = await Protocol.Debugger.setScriptSource({
scriptId: params.scriptId,
scriptSource: 'function foo() {\n return a # b;\n}'
});
InspectorTest.logMessage(msg);
}
]);
Tests Debugger.setScriptSource
Function evaluate: {"type":"number","value":6,"description":"6"}
PASS, result value: 6
Function evaluate: {"type":"number","value":8,"description":"8"}
PASS, result value: 8
Has error reported: PASS
Reported error is a compile error: PASS
PASS, result value: 1
TestExpression(2,4) === 6
Update current script source 'a + b' -> 'a * b'..
{
callFrames : [
]
stackChanged : false
}
TestExpression(2,4) === 8
Update current script source 'a * b' -> 'a # b'..
{
exceptionDetails : {
columnNumber : 13
exceptionId : <exceptionId>
lineNumber : 1
text : Invalid or unexpected token
}
}
TestExpression(2,4) === 8
......@@ -2,153 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start('Tests Debugger.setScriptSource');
const {session, contextGroup, Protocol} =
InspectorTest.start('Tests Debugger.setScriptSource');
contextGroup.addScript(
`function TestExpression(a, b) {
return a + b;
}`);
// A general-purpose engine for sending a sequence of protocol commands.
// The clients provide requests and response handlers, while the engine catches
// errors and makes sure that once there's nothing to do completeTest() is called.
// @param step is an object with command, params and callback fields
function runRequestSeries(step) {
processStep(step);
function processStep(currentStep) {
try {
processStepOrFail(currentStep);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
}
}
function processStepOrFail(currentStep) {
if (!currentStep) {
InspectorTest.completeTest();
return;
}
if (!currentStep.command) {
// A simple loopback step.
var next = currentStep.callback();
processStep(next);
return;
}
var innerCallback = function(response) {
var next;
if ("error" in response) {
if (!("errorHandler" in currentStep)) {
// Error message is not logged intentionally, it may be platform-specific.
InspectorTest.log("Protocol command '" + currentStep.command + "' failed");
InspectorTest.completeTest();
return;
}
try {
next = currentStep.errorHandler(response.error);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
return;
}
} else {
try {
next = currentStep.callback(response.result);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
return;
}
}
processStep(next);
}
var command = currentStep.command.split(".");
Protocol[command[0]][command[1]](currentStep.params).then(innerCallback);
}
}
function logEqualsCheck(actual, expected)
{
if (actual === expected) {
InspectorTest.log("PASS, result value: " + actual);
} else {
InspectorTest.log("FAIL, actual value: " + actual + ", expected: " + expected);
}
}
function logCheck(description, success)
{
InspectorTest.log(description + ": " + (success ? "PASS" : "FAIL"));
}
var firstStep = { callback: enableDebugger };
runRequestSeries(firstStep);
function enableDebugger() {
return { command: "Debugger.enable", params: {}, callback: evalFunction };
}
function evalFunction(response) {
var expression = "TestExpression(2, 4)";
return { command: "Runtime.evaluate", params: { expression: expression }, callback: callbackEvalFunction };
}
function callbackEvalFunction(result) {
InspectorTest.log("Function evaluate: " + JSON.stringify(result.result));
logEqualsCheck(result.result.value, 6);
return { command: "Runtime.evaluate", params: { expression: "TestExpression" }, callback: callbackEvalFunctionObject };
}
function callbackEvalFunctionObject(result) {
return { command: "Runtime.getProperties", params: { objectId: result.result.objectId }, callback: callbackFunctionDetails };
}
function callbackFunctionDetails(result)
{
var scriptId;
for (var prop of result.internalProperties) {
if (prop.name === "[[FunctionLocation]]")
scriptId = prop.value.value.scriptId;
}
return createScriptManipulationArc(scriptId, null);
}
// Several steps with scriptId in context.
function createScriptManipulationArc(scriptId, next) {
return { command: "Debugger.getScriptSource", params: { scriptId: scriptId }, callback: callbackGetScriptSource };
var originalText;
function callbackGetScriptSource(result) {
originalText = result.scriptSource;
var patched = originalText.replace("a + b", "a * b");
return { command: "Debugger.setScriptSource", params: { scriptId: scriptId, scriptSource: patched }, callback: callbackSetScriptSource };
}
function callbackSetScriptSource(result) {
var expression = "TestExpression(2, 4)";
return { command: "Runtime.evaluate", params: { expression: expression }, callback: callbackEvalFunction2 };
}
function callbackEvalFunction2(result) {
InspectorTest.log("Function evaluate: " + JSON.stringify(result.result));
logEqualsCheck(result.result.value, 8);
var patched = originalText.replace("a + b", "a # b");
return { command: "Debugger.setScriptSource", params: { scriptId: scriptId, scriptSource: patched }, callback: errorCallbackSetScriptSource2 };
}
function errorCallbackSetScriptSource2(result) {
var exceptionDetails = result.exceptionDetails;
logCheck("Has error reported", !!exceptionDetails);
logCheck("Reported error is a compile error", !!exceptionDetails);
if (exceptionDetails)
logEqualsCheck(exceptionDetails.lineNumber, 1);
return next;
}
}
(async function test() {
Protocol.Debugger.enable();
const {params: {scriptId}} = await Protocol.Debugger.onceScriptParsed();
const {result: {result: {value}}} =
await Protocol.Runtime.evaluate({expression: 'TestExpression(2, 4)'});
InspectorTest.log(`TestExpression(2,4) === ${value}`);
{
const {result: {scriptSource}} =
await Protocol.Debugger.getScriptSource({scriptId});
InspectorTest.log(`Update current script source 'a + b' -> 'a * b'..`);
const {result} = await Protocol.Debugger.setScriptSource(
{scriptId, scriptSource: scriptSource.replace('a + b', 'a * b')})
InspectorTest.logMessage(result);
const {result: {result: {value}}} =
await Protocol.Runtime.evaluate({expression: 'TestExpression(2, 4)'});
InspectorTest.log(`TestExpression(2,4) === ${value}`);
}
{
const {result: {scriptSource}} =
await Protocol.Debugger.getScriptSource({scriptId});
InspectorTest.log(`Update current script source 'a * b' -> 'a # b'..`);
const {result} = await Protocol.Debugger.setScriptSource(
{scriptId, scriptSource: scriptSource.replace('a * b', 'a # b')})
InspectorTest.logMessage(result);
const {result: {result: {value}}} =
await Protocol.Runtime.evaluate({expression: 'TestExpression(2, 4)'});
InspectorTest.log(`TestExpression(2,4) === ${value}`);
}
InspectorTest.completeTest();
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment