Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-getProperties.html

Issue 2954093003: [DevTools] Migrate inspector-protocol/runtime tests to new harness (Closed)
Patch Set: fail: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resource s/inspector-protocol-test.js"></script>
4 <script>
5
6 function test()
7 {
8 // A general-purpose engine for sending a sequence of protocol commands.
9 // The clients provide requests and response handlers, while the engine catc hes
10 // errors and makes sure that once there's nothing to do completeTest() is c alled.
11 // @param step is an object with command, params and callback fields
12 function runRequestSeries(step)
13 {
14 processStep(step);
15
16 function processStep(s)
17 {
18 try {
19 processStepOrFail(s);
20 } catch (e) {
21 InspectorTest.log(e.stack);
22 InspectorTest.completeTest();
23 }
24 }
25
26 function processStepOrFail(s)
27 {
28 if (!s) {
29 InspectorTest.completeTest();
30 return;
31 }
32 if (!s.command) {
33 // A simple loopback step.
34 var next = s.callback();
35 processStep(next);
36 return;
37 }
38
39 var innerCallback = function(response)
40 {
41 if ("error" in response) {
42 InspectorTest.log(response.error.message);
43 InspectorTest.completeTest();
44 return;
45 }
46 var next;
47 try {
48 next = s.callback(response.result);
49 } catch (e) {
50 InspectorTest.log(e.stack);
51 InspectorTest.completeTest();
52 return;
53 }
54 processStep(next);
55 }
56 InspectorTest.sendCommand(s.command, s.params, innerCallback);
57 }
58 }
59
60 var firstStep = { callback: callbackStart5 };
61
62 runRequestSeries(firstStep);
63
64 // 'Object5' section -- check properties of '5' wrapped as object (has an i nternal property).
65
66 function callbackStart5()
67 {
68 // Create an wrapper object with additional property.
69 var expression = "(function(){var r = Object(5); r.foo = 'cat';return r; })()";
70
71 return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEval5 };
72 }
73 function callbackEval5(result)
74 {
75 var id = result.result.objectId;
76 if (id === undefined)
77 throw new Error("objectId is expected");
78 return {
79 command: "Runtime.getProperties", params: {objectId: id, ownProperti es: true}, callback: callbackProperties5
80 };
81 }
82 function callbackProperties5(result)
83 {
84 logGetPropertiesResult("Object(5)", result);
85 return { callback: callbackStartNotOwn };
86 }
87
88
89 // 'Not own' section -- check all properties of the object, including ones f rom it prototype chain.
90
91 function callbackStartNotOwn()
92 {
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;} }})";
95
96 return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalNotOwn };
97 }
98 function callbackEvalNotOwn(result)
99 {
100 var id = result.result.objectId;
101 if (id === undefined)
102 throw new Error("objectId is expected");
103 return {
104 command: "Runtime.getProperties", params: {objectId: id, ownProperti es: false}, callback: callbackPropertiesNotOwn
105 };
106 }
107 function callbackPropertiesNotOwn(result)
108 {
109 logGetPropertiesResult("Not own properties", result);
110 return { callback: callbackStartAccessorsOnly };
111 }
112
113
114 // 'Accessors only' section -- check only accessor properties of the object.
115
116 function callbackStartAccessorsOnly()
117 {
118 // Create an wrapper object with additional property.
119 var expression = "({ a: 2, set b(_) {}, get b() {return 5;}, c: 'c', set d(_){} })";
120
121 return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalAccessorsOnly };
122 }
123 function callbackEvalAccessorsOnly(result)
124 {
125 var id = result.result.objectId;
126 if (id === undefined)
127 throw new Error("objectId is expected");
128 return {
129 command: "Runtime.getProperties", params: {objectId: id, ownProperti es: true, accessorPropertiesOnly: true}, callback: callbackPropertiesAccessorsOn ly
130 };
131 }
132 function callbackPropertiesAccessorsOnly(result)
133 {
134 logGetPropertiesResult("Accessor only properties", result);
135 return { callback: callbackStartArray };
136 }
137
138
139 // 'Array' section -- check properties of an array.
140
141 function callbackStartArray()
142 {
143 var expression = "['red', 'green', 'blue']";
144 return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalArray };
145 }
146 function callbackEvalArray(result)
147 {
148 var id = result.result.objectId;
149 if (id === undefined)
150 throw new Error("objectId is expected");
151 return {
152 command: "Runtime.getProperties", params: {objectId: id, ownProperti es: true}, callback: callbackPropertiesArray
153 };
154 }
155 function callbackPropertiesArray(result)
156 {
157 logGetPropertiesResult("array", result);
158 return { callback: callbackStartBound };
159 }
160
161
162 // 'Bound' section -- check properties of a bound function (has a bunch of i nternal properties).
163
164 function callbackStartBound()
165 {
166 var expression = "Number.bind({}, 5)";
167 return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalBound };
168 }
169 function callbackEvalBound(result)
170 {
171 var id = result.result.objectId;
172 if (id === undefined)
173 throw new Error("objectId is expected");
174 return {
175 command: "Runtime.getProperties", params: {objectId: id, ownProperti es: true}, callback: callbackPropertiesBound
176 };
177 }
178 function callbackPropertiesBound(result)
179 {
180 logGetPropertiesResult("Bound function", result);
181 return { callback: callbackStartUserDefinedPropertyOnEvent };
182 }
183
184 function callbackStartUserDefinedPropertyOnEvent()
185 {
186 var expression = "var e = document.createEvent(\"Event\"); Object.define Property(e, \"eventPhase\", { get: function() { return 239; } })";
187 return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalUserDefinedPropertyOnEvent };
188 }
189 function callbackEvalUserDefinedPropertyOnEvent(result)
190 {
191 var id = result.result.objectId;
192 if (id === undefined)
193 throw new Error("objectId is expected");
194 return {
195 command: "Runtime.getProperties", params: {objectId: id, ownProperti es: true}, callback: callbackPropertiesUserDefinedPropertyOnEvent
196 };
197 }
198 function callbackPropertiesUserDefinedPropertyOnEvent(result)
199 {
200 logGetPropertiesResult("Event with user defined property", result);
201 return; // End of test
202 }
203
204
205 // A helper function that dumps object properties and internal properties in sorted order.
206 function logGetPropertiesResult(title, protocolResult)
207 {
208 function hasGetterSetter(property, fieldName)
209 {
210 var v = property[fieldName];
211 if (!v)
212 return false;
213 return v.type !== "undefined"
214 }
215
216 InspectorTest.log("Properties of " + title);
217 var propertyArray = protocolResult.result;
218 propertyArray.sort(NamedThingComparator);
219 for (var i = 0; i < propertyArray.length; i++) {
220 var p = propertyArray[i];
221 var v = p.value;
222 var own = p.isOwn ? "own" : "inherited";
223 if (v)
224 InspectorTest.log(" " + p.name + " " + own + " " + v.type + " " + v.value );
225 else
226 InspectorTest.log(" " + p.name + " " + own + " no value" +
227 (hasGetterSetter(p, "get") ? ", getter" : "") + (hasGetterSe tter(p, "set") ? ", setter" : ""));
228 }
229 var internalPropertyArray = protocolResult.internalProperties;
230 if (internalPropertyArray) {
231 InspectorTest.log("Internal properties");
232 internalPropertyArray.sort(NamedThingComparator);
233 for (var i = 0; i < internalPropertyArray.length; i++) {
234 var p = internalPropertyArray[i];
235 var v = p.value;
236 InspectorTest.log(" " + p.name + " " + v.type + " " + v.value);
237 }
238 }
239
240 function NamedThingComparator(o1, o2)
241 {
242 return o1.name === o2.name ? 0 : (o1.name < o2.name ? -1 : 1);
243 }
244 }
245 }
246 </script>
247 </head>
248 <body onLoad="runTest();">
249 </body>
250 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698