Web Inspector: API View of Native DOM APIs looks poor (TypeErrors for native getters)
[WebKit-https.git] / LayoutTests / inspector / runtime / getProperties.html
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector/resources/protocol-test.js"></script>
4 <script>
5 function test()
6 {
7     var suite = ProtocolTest.createAsyncSuite("Runtime.getProperties");
8
9     addGetPropertiesTestCase({
10         name: "CheckPropertiesOfWrapperObject",
11         description: "Check properties of `Object(5)`.",
12         expression: "(function(){var r = Object(5); r.foo = 'cat';return r;})()",
13     });
14
15     addGetPropertiesTestCase({
16         name: "CheckPropertiesOfArray",
17         description: "Check properties of `['red', 'green', 'blue']`.",
18         expression: "['red', 'green', 'blue']",
19     });
20
21     addGetPropertiesTestCase({
22         name: "CheckPropertiesOfBoundConstructor",
23         description: "Check properties of a bound function (has a bunch of internal properties).",
24         expression: "Number.bind({}, 5)",
25     });
26
27     addGetPropertiesTestCase({
28         name: "CheckPropertiesOfBoundFunctionNoArguments",
29         description: "Check properties of a bound function with no bound arguments.",
30         expression: "(function(){}).bind(null)",
31     });
32
33     suite.runTestCasesAndFinish();
34
35     function addGetPropertiesTestCase(args) {
36         var {name, description, expression} = args;
37
38         suite.addTestCase({
39             name,
40             description,
41             test: function(resolve, reject) {
42                 ProtocolTest.log("Evaluating expression: " + expression);
43                 InspectorProtocol.awaitCommand({
44                     method: "Runtime.evaluate",
45                     params: {expression}
46                 })
47                 .then(function(reply) {
48                     var objectId = reply.result.objectId;
49                     if (objectId === undefined)
50                         throw new Error("objectId is expected");
51
52                     return InspectorProtocol.awaitCommand({
53                         method: "Runtime.getProperties",
54                         params: {objectId, ownProperties: true}
55                     });
56                 })
57                 .then(function(reply) {
58                     dumpGetPropertiesResult(reply);
59                     resolve();
60                 })
61                 .catch(reject);
62             }
63         });
64     }
65
66     // A helper function that dumps object properties and internal properties in sorted order.
67     function dumpGetPropertiesResult(protocolResult) {
68         var properties = protocolResult.result;
69         if (properties) {
70             ProtocolTest.log("Properties:");
71             properties.sort(NamedThingComparator);
72             properties.map(dumpSingleProperty);
73         }
74
75         var internalProperties = protocolResult.internalProperties;
76         if (internalProperties) {
77             ProtocolTest.log("Internal properties:");
78             internalProperties.sort(NamedThingComparator);
79             internalProperties.map(dumpSingleProperty);
80         }
81
82         function dumpSingleProperty(property) {
83             var {name, value, get, set} = property;
84             if (value)
85                 ProtocolTest.log(`  ${name} ${value.type} ${value.value || value.description}`);
86             else if (get || set)
87                 ProtocolTest.log(`  ${name} ${get ? "getter" : "-"} ${set ? "setter" : ""}`);
88             else
89                 ProtocolTest.log(`  ${name}`);
90         }
91
92         function NamedThingComparator(o1, o2) {
93             return o1.name.localeCompare(o2.name);
94         }
95     }
96 }
97 </script>
98 </head>
99 <body onLoad="runTest()">
100 </body>
101 </html>