toolkit/devtools/webconsole/test/test_object_actor.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c33883783a50
1 <!DOCTYPE HTML>
2 <html lang="en">
3 <head>
4 <meta charset="utf8">
5 <title>Test for the object actor</title>
6 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
7 <script type="text/javascript;version=1.8" src="common.js"></script>
8 <!-- Any copyright is dedicated to the Public Domain.
9 - http://creativecommons.org/publicdomain/zero/1.0/ -->
10 </head>
11 <body>
12 <p>Test for the object actor</p>
13
14 <script class="testbody" type="text/javascript;version=1.8">
15 SimpleTest.waitForExplicitFinish();
16
17 let expectedProps = [];
18
19 function startTest()
20 {
21 removeEventListener("load", startTest);
22
23 attachConsole(["ConsoleAPI"], onAttach, true);
24 }
25
26 function onAttach(aState, aResponse)
27 {
28 onConsoleCall = onConsoleCall.bind(null, aState);
29 aState.dbgClient.addListener("consoleAPICall", onConsoleCall);
30
31 let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 3)).join("\u0629");
32
33 // Here we put the objects in the correct window, to avoid having them all
34 // wrapped by proxies for cross-compartment access.
35
36 let foobarObject = top.Object.create(null);
37 foobarObject.tamarbuta = longString;
38 foobarObject.foo = 1;
39 foobarObject.foobar = "hello";
40 foobarObject.omg = null;
41 foobarObject.testfoo = false;
42 foobarObject.notInspectable = top.Object.create(null);
43 foobarObject.omgfn = new top.Function("return 'myResult'");
44 foobarObject.abArray = new top.Array("a", "b");
45 foobarObject.foobaz = top.document;
46
47 top.Object.defineProperty(foobarObject, "getterAndSetter", {
48 enumerable: true,
49 get: new top.Function("return 'foo';"),
50 set: new top.Function("1+2"),
51 });
52
53 foobarObject.longStringObj = top.Object.create(null);
54 foobarObject.longStringObj.toSource = new top.Function("'" + longString + "'");
55 foobarObject.longStringObj.toString = new top.Function("'" + longString + "'");
56 foobarObject.longStringObj.boom = "explode";
57
58 top.wrappedJSObject.foobarObject = foobarObject;
59 top.console.log("hello", top.wrappedJSObject.foobarObject);
60
61 expectedProps = {
62 "abArray": {
63 value: {
64 type: "object",
65 class: "Array",
66 actor: /[a-z]/,
67 },
68 },
69 "foo": {
70 configurable: true,
71 enumerable: true,
72 writable: true,
73 value: 1,
74 },
75 "foobar": {
76 value: "hello",
77 },
78 "foobaz": {
79 value: {
80 type: "object",
81 class: "XULDocument",
82 actor: /[a-z]/,
83 },
84 },
85 "getterAndSetter": {
86 get: {
87 type: "object",
88 class: "Function",
89 actor: /[a-z]/,
90 },
91 set: {
92 type: "object",
93 class: "Function",
94 actor: /[a-z]/,
95 },
96 },
97 "longStringObj": {
98 value: {
99 type: "object",
100 class: "Object",
101 actor: /[a-z]/,
102 },
103 },
104 "notInspectable": {
105 value: {
106 type: "object",
107 class: "Object",
108 actor: /[a-z]/,
109 },
110 },
111 "omg": {
112 value: { type: "null" },
113 },
114 "omgfn": {
115 value: {
116 type: "object",
117 class: "Function",
118 actor: /[a-z]/,
119 },
120 },
121 "tamarbuta": {
122 value: {
123 type: "longString",
124 initial: longString.substring(0,
125 DebuggerServer.LONG_STRING_INITIAL_LENGTH),
126 length: longString.length,
127 },
128 },
129 "testfoo": {
130 value: false,
131 },
132 };
133 }
134
135 function onConsoleCall(aState, aType, aPacket)
136 {
137 is(aPacket.from, aState.actor, "console API call actor");
138
139 info("checking the console API call packet");
140
141 checkConsoleAPICall(aPacket.message, {
142 level: "log",
143 filename: /test_object_actor/,
144 functionName: "onAttach",
145 arguments: ["hello", {
146 type: "object",
147 actor: /[a-z]/,
148 }],
149 });
150
151 aState.dbgClient.removeListener("consoleAPICall", onConsoleCall);
152
153 info("inspecting object properties");
154 let args = aPacket.message.arguments;
155 onProperties = onProperties.bind(null, aState);
156
157 let client = new ObjectClient(aState.dbgClient, args[1]);
158 client.getPrototypeAndProperties(onProperties);
159 }
160
161 function onProperties(aState, aResponse)
162 {
163 let props = aResponse.ownProperties;
164 is(Object.keys(props).length, Object.keys(expectedProps).length,
165 "number of enumerable properties");
166 checkObject(props, expectedProps);
167
168 expectedProps = [];
169
170 closeDebugger(aState, function() {
171 SimpleTest.finish();
172 });
173 }
174
175 addEventListener("load", startTest);
176 </script>
177 </body>
178 </html>

mercurial