Commit c949f19b authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

inspector: add couple tests

Test to cover a lot of injected script source corner cases.

R=dgozman@chromium.org

Bug: chromium:595206
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia631de58c5a92b39ec3933c56cf7e3f108b9bd9e
Reviewed-on: https://chromium-review.googlesource.com/c/1292688
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56863}
parent c2021a85
......@@ -142,14 +142,22 @@ InspectorTest.ContextGroup = class {
setupInjectedScriptEnvironment(session) {
let scriptSource = '';
// First define all getters on Object.prototype.
let injectedScriptSource = utils.read('src/inspector/injected-script-source.js');
let getterRegex = /\.[a-zA-Z0-9]+/g;
let match;
let getters = new Set();
while (match = getterRegex.exec(injectedScriptSource)) {
getters.add(match[0].substr(1));
}
let getters = ["length","internalConstructorName","subtype","getProperty",
"objectHasOwnProperty","nullifyPrototype","primitiveTypes",
"closureTypes","prototype","all","RemoteObject","bind",
"PropertyDescriptor","object","get","set","value","configurable",
"enumerable","symbol","getPrototypeOf","nativeAccessorDescriptor",
"isBuiltin","hasGetter","hasSetter","getOwnPropertyDescriptor",
"description","formatAccessorsAsProperties","isOwn","name",
"typedArrayProperties","keys","getOwnPropertyNames",
"getOwnPropertySymbols","isPrimitiveValue","com","toLowerCase",
"ELEMENT","trim","replace","DOCUMENT","size","byteLength","toString",
"stack","substr","message","indexOf","key","type","unserializableValue",
"objectId","className","preview","proxyTargetValue","customPreview",
"CustomPreview","resolve","then","console","error","header","hasBody",
"stringify","ObjectPreview","ObjectPreviewType","properties",
"ObjectPreviewSubtype","getInternalProperties","wasThrown","indexes",
"overflow","valuePreview","entries"];
scriptSource += `(function installSettersAndGetters() {
let defineProperty = Object.defineProperty;
let ObjectPrototype = Object.prototype;
......@@ -158,7 +166,7 @@ InspectorTest.ContextGroup = class {
set() { debugger; throw 42; }, get() { debugger; throw 42; },
__proto__: null
});`,
scriptSource += Array.from(getters).map(getter => `
scriptSource += getters.map(getter => `
defineProperty(ObjectPrototype, '${getter}', {
set() { debugger; throw 42; }, get() { debugger; throw 42; },
__proto__: null
......@@ -401,6 +409,9 @@ InspectorTest.runTestSuite = function(testSuite) {
}
InspectorTest.runAsyncTestSuite = async function(testSuite) {
const selected = testSuite.filter(test => test.name.startsWith('f_'));
if (selected.length)
testSuite = selected;
for (var test of testSuite) {
InspectorTest.log("\nRunning test: " + test.name);
try {
......
......@@ -15,7 +15,7 @@ function testFunction() {
console.dir('dir');
console.dirxml('dirxml');
console.table([[1,2],[3,4]]);
console.table([[1,2],[3,4]], [1,2]);
console.table([[1,2],[3,4]], ['1','2']);
console.trace('trace');
console.trace();
console.group();
......
console.table
{
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
type : string
value : apples
}
[1] : {
name : 1
type : string
value : oranges
}
[2] : {
name : 2
type : string
value : bananas
}
]
subtype : array
type : object
}
{
description : Person
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : John
}
[1] : {
name : lastName
type : string
value : Smith
}
]
type : object
}
{
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
subtype : array
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
type : string
value : John
}
[1] : {
name : 1
type : string
value : Smith
}
]
subtype : array
type : object
}
}
[1] : {
name : 1
subtype : array
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
type : string
value : Jane
}
[1] : {
name : 1
type : string
value : Doe
}
]
subtype : array
type : object
}
}
[2] : {
name : 2
subtype : array
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
type : string
value : Emily
}
[1] : {
name : 1
type : string
value : Jones
}
]
subtype : array
type : object
}
}
]
subtype : array
type : object
}
{
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : John
}
[1] : {
name : lastName
type : string
value : Smith
}
]
subtype : array
type : object
}
}
[1] : {
name : 1
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : Jane
}
[1] : {
name : lastName
type : string
value : Doe
}
]
subtype : array
type : object
}
}
[2] : {
name : 2
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : Emily
}
[1] : {
name : lastName
type : string
value : Jones
}
]
subtype : array
type : object
}
}
]
subtype : array
type : object
}
{
description : Object
overflow : false
properties : [
[0] : {
name : mother
type : object
valuePreview : {
description : Object
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : Jane
}
[1] : {
name : lastName
type : string
value : Smith
}
]
type : object
}
}
[1] : {
name : father
type : object
valuePreview : {
description : Object
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : John
}
[1] : {
name : lastName
type : string
value : Smith
}
]
type : object
}
}
[2] : {
name : daughter
type : object
valuePreview : {
description : Object
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : Emily
}
[1] : {
name : lastName
type : string
value : Smith
}
]
type : object
}
}
]
type : object
}
{
description : Array(3)
overflow : false
properties : [
[0] : {
name : 0
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : John
}
]
subtype : array
type : object
}
}
[1] : {
name : 1
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : Jane
}
]
subtype : array
type : object
}
}
[2] : {
name : 2
type : object
valuePreview : {
description : Array(3)
overflow : false
properties : [
[0] : {
name : firstName
type : string
value : Emily
}
]
subtype : array
type : object
}
}
]
subtype : array
type : object
}
// Copyright 2018 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.
const { session, contextGroup, Protocol } =
InspectorTest.start('console.table');
(async function test() {
Protocol.Runtime.enable();
Protocol.Runtime.evaluate({
expression: `console.table(['apples', 'oranges', 'bananas'])`
});
await waitConsoleAPICalledAndDump();
Protocol.Runtime.evaluate({
expression: `function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
var me = new Person('John', 'Smith');
console.table(me);`
});
await waitConsoleAPICalledAndDump();
Protocol.Runtime.evaluate({
expression: `var people = [
['John', 'Smith'], ['Jane', 'Doe'], ['Emily', 'Jones']];
console.table(people);`
});
await waitConsoleAPICalledAndDump();
Protocol.Runtime.evaluate({
expression: `function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var john = new Person('John', 'Smith');
var jane = new Person('Jane', 'Doe');
var emily = new Person('Emily', 'Jones');
console.table([john, jane, emily]);`
});
await waitConsoleAPICalledAndDump();
Protocol.Runtime.evaluate({
expression: `var family = {};
family.mother = new Person('Jane', 'Smith');
family.father = new Person('John', 'Smith');
family.daughter = new Person('Emily', 'Smith');
console.table(family);`
});
await waitConsoleAPICalledAndDump();
Protocol.Runtime.evaluate({
expression: `console.table([john, jane, emily], ['firstName'])`
});
await waitConsoleAPICalledAndDump();
InspectorTest.completeTest();
})()
async function waitConsoleAPICalledAndDump() {
const { params : {
args: [ arg ]
} } = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.logMessage(arg.preview);
}
......@@ -61,6 +61,7 @@ Object.defineProperty(parentObj, 'propNotNamedProto', {
get: deterministicNativeFunction,
set: function() {}
});
inspector.allowAccessorFormatting(parentObj);
var objInheritsGetterProperty = {__proto__: parentObj};
inspector.allowAccessorFormatting(objInheritsGetterProperty);
......
......@@ -323,6 +323,108 @@ expression: it = new Map([[1,2],[3,4]]).entries(); it.next(); it.next(); it
]
}
}
expression: new Map([[1, undefined], [2, () => 42], [3, /abc/], [4, new Error()]]).entries()
[
[0] : {
key : 1
}
[1] : {
key : 2
value : {
}
}
[2] : {
key : 3
value : {
}
}
[3] : {
key : 4
value : {
}
}
]
{
id : <messageId>
result : {
internalProperties : [
[0] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
[0] : {
configurable : true
enumerable : true
isOwn : true
name : 0
value : {
className : Object
description : {1 => undefined}
objectId : <objectId>
subtype : internal#entry
type : object
}
writable : true
}
[1] : {
configurable : true
enumerable : true
isOwn : true
name : 1
value : {
className : Object
description : {2 => () => 42}
objectId : <objectId>
subtype : internal#entry
type : object
}
writable : true
}
[2] : {
configurable : true
enumerable : true
isOwn : true
name : 2
value : {
className : Object
description : {3 => /abc/}
objectId : <objectId>
subtype : internal#entry
type : object
}
writable : true
}
[3] : {
configurable : true
enumerable : true
isOwn : true
name : 3
value : {
className : Object
description : {4 => Error at <anonymous>:1:57}
objectId : <objectId>
subtype : internal#entry
type : object
}
writable : true
}
[4] : {
configurable : false
enumerable : false
isOwn : true
name : length
value : {
description : 4
type : number
value : 4
}
writable : true
}
]
}
}
Running test: sets
expression: new Set([1,2])
......
......@@ -19,6 +19,7 @@ InspectorTest.runTestSuite([
.then(() => checkExpression('it = new Map([[1,2],[3,4]]).keys(); it.next(); it'))
.then(() => checkExpression('it = new Map([[1,2],[3,4]]).values(); it.next(); it'))
.then(() => checkExpression('it = new Map([[1,2],[3,4]]).entries(); it.next(); it.next(); it'))
.then(() => checkExpression('new Map([[1, undefined], [2, () => 42], [3, /abc/], [4, new Error()]]).entries()'))
.then(next);
},
......
This diff is collapsed.
Tests Runtime.getProperties.
Running test: testObject
{
id : <messageId>
result : {
internalProperties : [
[0] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
[0] : {
configurable : true
enumerable : true
isOwn : true
name : a
value : {
description : 1
type : number
value : 1
}
writable : true
}
[1] : {
configurable : true
enumerable : false
isOwn : true
name : __proto__
value : {
className : Object
description : Object
objectId : <objectId>
type : object
}
writable : true
}
]
}
}
{
id : <messageId>
result : {
internalProperties : [
[0] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
[0] : {
configurable : false
enumerable : true
isOwn : true
name : d
value : {
description : 42
type : number
value : 42
}
writable : false
}
[1] : {
configurable : false
enumerable : false
isOwn : true
name : a
value : {
description : 42
type : number
value : 42
}
writable : false
}
[2] : {
configurable : false
enumerable : false
isOwn : true
name : b
value : {
description : 42
type : number
value : 42
}
writable : true
}
[3] : {
configurable : true
enumerable : false
isOwn : true
name : c
value : {
description : 42
type : number
value : 42
}
writable : false
}
[4] : {
configurable : false
enumerable : false
get : {
className : Function
description : () => 42
objectId : <objectId>
type : function
}
isOwn : true
name : e
set : {
className : Function
description : () => 0
objectId : <objectId>
type : function
}
}
[5] : {
configurable : false
enumerable : false
isOwn : true
name : Symbol(42)
symbol : {
description : Symbol(42)
objectId : <objectId>
type : symbol
}
value : {
description : 239
type : number
value : 239
}
writable : false
}
[6] : {
configurable : true
enumerable : false
isOwn : true
name : __proto__
value : {
className : Object
description : Object
objectId : <objectId>
type : object
}
writable : true
}
]
}
}
// Copyright 2018 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.
const {session, contextGroup, Protocol} =
InspectorTest.start('Tests Runtime.getProperties.');
InspectorTest.runAsyncTestSuite([
async function testObject() {
await getProperties('({a: 1})', { ownProperties: true });
await getProperties(`(function(){
let b = {};
Object.defineProperty(b, 'a', {
configurable: false,
enumerable: false,
value: 42,
writable: false
});
Object.defineProperty(b, 'b', {
configurable: false,
enumerable: false,
value: 42,
writable: true
});
Object.defineProperty(b, 'c', {
configurable: true,
enumerable: false,
value: 42,
writable: false
});
Object.defineProperty(b, 'd', {
configurable: false,
enumerable: true,
value: 42,
writable: false
});
Object.defineProperty(b, 'e', {
set: () => 0,
get: () => 42
});
Object.defineProperty(b, Symbol(42), {
value: 239
});
return b;
})()`, { ownProperties: true });
}
]);
async function getProperties(expression, options) {
try {
const { result: { result: { objectId } } } =
await Protocol.Runtime.evaluate({ expression });
const result = await Protocol.Runtime.getProperties({
objectId,
ownProperties: options.ownProperties
});
InspectorTest.logMessage(result);
} catch (e) {
InspectorTest.log(e.stack);
}
}
This diff is collapsed.
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