3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
8 // A general-purpose engine for sending a sequence of protocol commands.
9 // The clients provide requests and response handlers, while the engine catches
10 // errors and makes sure that once there's nothing to do completeTest() is called.
11 // @param step is an object with command, params and callback fields
12 function runRequestSeries(step
)
16 function processStep(s
)
21 InspectorTest
.log(e
.stack
);
22 InspectorTest
.completeTest();
26 function processStepOrFail(s
)
29 InspectorTest
.completeTest();
33 // A simple loopback step.
34 var next
= s
.callback();
39 var innerCallback = function(response
)
41 if ("error" in response
) {
42 InspectorTest
.log(response
.error
.message
);
43 InspectorTest
.completeTest();
48 next
= s
.callback(response
.result
);
50 InspectorTest
.log(e
.stack
);
51 InspectorTest
.completeTest();
56 InspectorTest
.sendCommand(s
.command
, s
.params
, innerCallback
);
60 var firstStep
= { callback
: callbackStart5
};
62 runRequestSeries(firstStep
);
64 // 'Object5' section -- check properties of '5' wrapped as object (has an internal property).
66 function callbackStart5()
68 // Create an wrapper object with additional property.
69 var expression
= "(function(){var r = Object(5); r.foo = 'cat';return r;})()";
71 return { command
: "Runtime.evaluate", params
: {expression
: expression
}, callback
: callbackEval5
};
73 function callbackEval5(result
)
75 var id
= result
.result
.objectId
;
77 throw new Error("objectId is expected");
79 command
: "Runtime.getProperties", params
: {objectId
: id
, ownProperties
: true}, callback
: callbackProperties5
82 function callbackProperties5(result
)
84 logGetPropertiesResult("Object(5)", result
);
85 return { callback
: callbackStartNotOwn
};
89 // 'Not own' section -- check all properties of the object, including ones from it prototype chain.
91 function callbackStartNotOwn()
93 // Create an wrapper object with additional property.
94 var expression
= "({ a: 2, set b(_) {}, get b() {return 5;}, __proto__: { a: 3, c: 4, get d() {return 6;} }})";
96 return { command
: "Runtime.evaluate", params
: {expression
: expression
}, callback
: callbackEvalNotOwn
};
98 function callbackEvalNotOwn(result
)
100 var id
= result
.result
.objectId
;
101 if (id
=== undefined)
102 throw new Error("objectId is expected");
104 command
: "Runtime.getProperties", params
: {objectId
: id
, ownProperties
: false}, callback
: callbackPropertiesNotOwn
107 function callbackPropertiesNotOwn(result
)
109 logGetPropertiesResult("Not own properties", result
);
110 return { callback
: callbackStartAccessorsOnly
};
114 // 'Accessors only' section -- check only accessor properties of the object.
116 function callbackStartAccessorsOnly()
118 // Create an wrapper object with additional property.
119 var expression
= "({ a: 2, set b(_) {}, get b() {return 5;}, c: 'c', set d(_){} })";
121 return { command
: "Runtime.evaluate", params
: {expression
: expression
}, callback
: callbackEvalAccessorsOnly
};
123 function callbackEvalAccessorsOnly(result
)
125 var id
= result
.result
.objectId
;
126 if (id
=== undefined)
127 throw new Error("objectId is expected");
129 command
: "Runtime.getProperties", params
: {objectId
: id
, ownProperties
: true, accessorPropertiesOnly
: true}, callback
: callbackPropertiesAccessorsOnly
132 function callbackPropertiesAccessorsOnly(result
)
134 logGetPropertiesResult("Accessor only properties", result
);
135 return { callback
: callbackStartArray
};
139 // 'Array' section -- check properties of an array.
141 function callbackStartArray()
143 var expression
= "['red', 'green', 'blue']";
144 return { command
: "Runtime.evaluate", params
: {expression
: expression
}, callback
: callbackEvalArray
};
146 function callbackEvalArray(result
)
148 var id
= result
.result
.objectId
;
149 if (id
=== undefined)
150 throw new Error("objectId is expected");
152 command
: "Runtime.getProperties", params
: {objectId
: id
, ownProperties
: true}, callback
: callbackPropertiesArray
155 function callbackPropertiesArray(result
)
157 logGetPropertiesResult("array", result
);
158 return { callback
: callbackStartBound
};
162 // 'Bound' section -- check properties of a bound function (has a bunch of internal properties).
164 function callbackStartBound()
166 var expression
= "Number.bind({}, 5)";
167 return { command
: "Runtime.evaluate", params
: {expression
: expression
}, callback
: callbackEvalBound
};
169 function callbackEvalBound(result
)
171 var id
= result
.result
.objectId
;
172 if (id
=== undefined)
173 throw new Error("objectId is expected");
175 command
: "Runtime.getProperties", params
: {objectId
: id
, ownProperties
: true}, callback
: callbackPropertiesBound
178 function callbackPropertiesBound(result
)
180 logGetPropertiesResult("Bound function", result
);
181 return; // End of test
185 // A helper function that dumps object properties and internal properties in sorted order.
186 function logGetPropertiesResult(title
, protocolResult
)
188 function hasGetterSetter(property
, fieldName
)
190 var v
= property
[fieldName
];
193 return v
.type
!== "undefined"
196 InspectorTest
.log("Properties of " + title
);
197 var propertyArray
= protocolResult
.result
;
198 propertyArray
.sort(NamedThingComparator
);
199 for (var i
= 0; i
< propertyArray
.length
; i
++) {
200 var p
= propertyArray
[i
];
202 var own
= p
.isOwn
? "own" : "inherited";
204 InspectorTest
.log(" " + p
.name
+ " " + own
+ " " + v
.type
+ " " + v
.value
);
206 InspectorTest
.log(" " + p
.name
+ " " + own
+ " no value" +
207 (hasGetterSetter(p
, "get") ? ", getter" : "") + (hasGetterSetter(p
, "set") ? ", setter" : ""));
209 var internalPropertyArray
= protocolResult
.internalProperties
;
210 if (internalPropertyArray
) {
211 InspectorTest
.log("Internal properties");
212 internalPropertyArray
.sort(NamedThingComparator
);
213 for (var i
= 0; i
< internalPropertyArray
.length
; i
++) {
214 var p
= internalPropertyArray
[i
];
216 InspectorTest
.log(" " + p
.name
+ " " + v
.type
+ " " + v
.value
);
220 function NamedThingComparator(o1
, o2
)
222 return o1
.name
=== o2
.name
? 0 : (o1
.name
< o2
.name
? -1 : 1);
228 <body onLoad=
"runTest();">