[inspector] run more tests with InspectorTest.setupInjectedScriptEnvironment

+ bonus: new version of get-properties.js test - good illustration of out progress in tests.

BUG=none
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2774493002
Cr-Commit-Position: refs/heads/master@{#44121}
This commit is contained in:
kozyatinskiy 2017-03-24 11:43:22 -07:00 committed by Commit bot
parent f633c5f383
commit c72c90bc74
5 changed files with 77 additions and 226 deletions

View File

@ -1,9 +1,12 @@
Properties of Object(5)
Checks Runtime.getProperties method
Running test: testObject5
__proto__ own object undefined
foo own string cat
Internal properties
[[PrimitiveValue]] number 5
Properties of Not own properties
Running test: testNotOwn
__defineGetter__ inherited function undefined
__defineSetter__ inherited function undefined
__lookupGetter__ inherited function undefined
@ -20,16 +23,19 @@ Properties of Not own properties
toLocaleString inherited function undefined
toString inherited function undefined
valueOf inherited function undefined
Properties of Accessor only properties
Running test: testAccessorsOnly
b own no value, getter, setter
d own no value, setter
Properties of array
Running test: testArray
0 own string red
1 own string green
2 own string blue
__proto__ own object undefined
length own number 3
Properties of Bound function
Running test: testBound
__proto__ own function undefined
length own number 0
name own string bound Number
@ -37,8 +43,10 @@ Internal properties
[[BoundArgs]] object undefined
[[BoundThis]] object undefined
[[TargetFunction]] function undefined
Properties of Object that throws on length access
Running test: testObjectThrowsLength
__proto__ own object undefined
length own no value, getter
Properties of TypedArray without length
Running test: testTypedArrayWithoutLength
__proto__ own object undefined

View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
InspectorTest.setupInjectedScriptEnvironment();
Protocol.Runtime.evaluate({ "expression": "({p1: {a:1}, p2: {b:'foo', bb:'bar'}})" }).then(callbackEvaluate);
function callbackEvaluate(result)

View File

@ -2,235 +2,73 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// 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);
InspectorTest.log('Checks Runtime.getProperties method');
function processStep(s)
{
try {
processStepOrFail(s);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
}
}
InspectorTest.runAsyncTestSuite([
async function testObject5() {
let objectId = (await Protocol.Runtime.evaluate({
expression: '(function(){var r = Object(5); r.foo = \'cat\';return r;})()'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: true });
logGetPropertiesResult(props.result);
},
function processStepOrFail(s)
{
if (!s) {
InspectorTest.completeTest();
return;
}
if (!s.command) {
// A simple loopback step.
var next = s.callback();
processStep(next);
return;
}
async function testNotOwn() {
let objectId = (await Protocol.Runtime.evaluate({
expression: '({ a: 2, set b(_) {}, get b() {return 5;}, __proto__: { a: 3, c: 4, get d() {return 6;} }})'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: false });
logGetPropertiesResult(props.result);
},
var innerCallback = function(response)
{
if ("error" in response) {
InspectorTest.log(response.error.message);
InspectorTest.completeTest();
return;
}
var next;
try {
next = s.callback(response.result);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
return;
}
processStep(next);
}
var command = s.command.split(".");
Protocol[command[0]][command[1]](s.params).then(innerCallback);
}
}
async function testAccessorsOnly() {
let objectId = (await Protocol.Runtime.evaluate({
expression: '({ a: 2, set b(_) {}, get b() {return 5;}, c: \'c\', set d(_){} })'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: true, accessorPropertiesOnly: true });
logGetPropertiesResult(props.result);
},
var firstStep = { callback: callbackStart5 };
async function testArray() {
let objectId = (await Protocol.Runtime.evaluate({
expression: '[\'red\', \'green\', \'blue\']'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: true });
logGetPropertiesResult(props.result);
},
runRequestSeries(firstStep);
async function testBound() {
let objectId = (await Protocol.Runtime.evaluate({
expression: 'Number.bind({}, 5)'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: true });
logGetPropertiesResult(props.result);
},
// 'Object5' section -- check properties of '5' wrapped as object (has an internal property).
async function testObjectThrowsLength() {
let objectId = (await Protocol.Runtime.evaluate({
expression: '({get length() { throw \'Length called\'; }})'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: true });
logGetPropertiesResult(props.result);
},
function callbackStart5()
{
// Create an wrapper object with additional property.
var expression = "(function(){var r = Object(5); r.foo = 'cat';return r;})()";
async function testTypedArrayWithoutLength() {
let objectId = (await Protocol.Runtime.evaluate({
expression: '({__proto__: Uint8Array.prototype})'
})).result.result.objectId;
let props = await Protocol.Runtime.getProperties({ objectId, ownProperties: true });
logGetPropertiesResult(props.result);
},
]);
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEval5 };
}
function callbackEval5(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackProperties5
};
}
function callbackProperties5(result)
{
logGetPropertiesResult("Object(5)", result);
return { callback: callbackStartNotOwn };
}
// 'Not own' section -- check all properties of the object, including ones from it prototype chain.
function callbackStartNotOwn()
{
// Create an wrapper object with additional property.
var expression = "({ a: 2, set b(_) {}, get b() {return 5;}, __proto__: { a: 3, c: 4, get d() {return 6;} }})";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalNotOwn };
}
function callbackEvalNotOwn(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: false}, callback: callbackPropertiesNotOwn
};
}
function callbackPropertiesNotOwn(result)
{
logGetPropertiesResult("Not own properties", result);
return { callback: callbackStartAccessorsOnly };
}
// 'Accessors only' section -- check only accessor properties of the object.
function callbackStartAccessorsOnly()
{
// Create an wrapper object with additional property.
var expression = "({ a: 2, set b(_) {}, get b() {return 5;}, c: 'c', set d(_){} })";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalAccessorsOnly };
}
function callbackEvalAccessorsOnly(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true, accessorPropertiesOnly: true}, callback: callbackPropertiesAccessorsOnly
};
}
function callbackPropertiesAccessorsOnly(result)
{
logGetPropertiesResult("Accessor only properties", result);
return { callback: callbackStartArray };
}
// 'Array' section -- check properties of an array.
function callbackStartArray()
{
var expression = "['red', 'green', 'blue']";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalArray };
}
function callbackEvalArray(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesArray
};
}
function callbackPropertiesArray(result)
{
logGetPropertiesResult("array", result);
return { callback: callbackStartBound };
}
// 'Bound' section -- check properties of a bound function (has a bunch of internal properties).
function callbackStartBound()
{
var expression = "Number.bind({}, 5)";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalBound };
}
function callbackEvalBound(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesBound
};
}
function callbackPropertiesBound(result)
{
logGetPropertiesResult("Bound function", result);
return { callback: callbackStartObjectThrowsLength };
}
// Object throws on length access
function callbackStartObjectThrowsLength() {
var expression = "({get length() { throw 'Length called'; }})";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalObjectThrowsLength };
}
function callbackEvalObjectThrowsLength(result) {
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesObjectThrowsLength
};
}
function callbackPropertiesObjectThrowsLength(result) {
logGetPropertiesResult("Object that throws on length access", result);
return { callback: callbackStartTypedArrayWithoutLength };
}
// Typed array without length
function callbackStartTypedArrayWithoutLength() {
var expression = "({__proto__: Uint8Array.prototype})";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalTypedArrayWithoutLength };
}
function callbackEvalTypedArrayWithoutLength(result) {
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesTypedArrayWithoutLength
};
}
function callbackPropertiesTypedArrayWithoutLength(result) {
logGetPropertiesResult("TypedArray without length", result);
return; // End of test
}
// A helper function that dumps object properties and internal properties in sorted order.
function logGetPropertiesResult(title, protocolResult)
{
function hasGetterSetter(property, fieldName)
{
function logGetPropertiesResult(protocolResult) {
function hasGetterSetter(property, fieldName) {
var v = property[fieldName];
if (!v)
return false;
if (!v) return false;
return v.type !== "undefined"
}
InspectorTest.log("Properties of " + title);
var propertyArray = protocolResult.result;
propertyArray.sort(NamedThingComparator);
for (var i = 0; i < propertyArray.length; i++) {
@ -254,8 +92,7 @@ function logGetPropertiesResult(title, protocolResult)
}
}
function NamedThingComparator(o1, o2)
{
function NamedThingComparator(o1, o2) {
return o1.name === o2.name ? 0 : (o1.name < o2.name ? -1 : 1);
}
}

View File

@ -4,6 +4,8 @@
InspectorTest.log("Test that descriptions for arrays, maps, and sets include the correct length or size.")
InspectorTest.setupInjectedScriptEnvironment();
Promise.all([
testExpression("new Set()"),
testExpression("new Set([1,2])"),

View File

@ -22,6 +22,8 @@ InspectorTest.addScript(`
}
`);
InspectorTest.setupInjectedScriptEnvironment();
Protocol.Debugger.enable();
Protocol.Runtime.enable();