summaryrefslogtreecommitdiffstats
path: root/devtools/shared/webconsole/test/test_object_actor.html
blob: 09176a5aac9efb515c29de83ec4592ec2888129b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="utf8">
  <title>Test for the object actor</title>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript;version=1.8" src="common.js"></script>
  <!-- Any copyright is dedicated to the Public Domain.
     - http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for the object actor</p>

<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();

let expectedProps = [];

function startTest()
{
  removeEventListener("load", startTest);

  attachConsoleToTab(["ConsoleAPI"], onAttach);
}

function onAttach(aState, aResponse)
{
  onConsoleCall = onConsoleCall.bind(null, aState);
  aState.dbgClient.addListener("consoleAPICall", onConsoleCall);

  let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 3)).join("\u0629");

  // Here we put the objects in the correct window, to avoid having them all
  // wrapped by proxies for cross-compartment access.

  let foobarObject = top.Object.create(null);
  foobarObject.tamarbuta = longString;
  foobarObject.foo = 1;
  foobarObject.foobar = "hello";
  foobarObject.omg = null;
  foobarObject.testfoo = false;
  foobarObject.notInspectable = top.Object.create(null);
  foobarObject.omgfn = new top.Function("return 'myResult'");
  foobarObject.abArray = new top.Array("a", "b");
  foobarObject.foobaz = top.document;

  top.Object.defineProperty(foobarObject, "getterAndSetter", {
    enumerable: true,
    get: new top.Function("return 'foo';"),
    set: new top.Function("1+2"),
  });

  foobarObject.longStringObj = top.Object.create(null);
  foobarObject.longStringObj.toSource = new top.Function("'" + longString + "'");
  foobarObject.longStringObj.toString = new top.Function("'" + longString + "'");
  foobarObject.longStringObj.boom = "explode";

  top.wrappedJSObject.foobarObject = foobarObject;
  top.console.log("hello", top.wrappedJSObject.foobarObject);

  expectedProps = {
    "abArray": {
      value: {
        type: "object",
        class: "Array",
        actor: /[a-z]/,
      },
    },
    "foo": {
      configurable: true,
      enumerable: true,
      writable: true,
      value: 1,
    },
    "foobar": {
      value: "hello",
    },
    "foobaz": {
      value: {
        type: "object",
        class: "XULDocument",
        actor: /[a-z]/,
      },
    },
    "getterAndSetter": {
      get: {
        type: "object",
        class: "Function",
        actor: /[a-z]/,
      },
      set: {
        type: "object",
        class: "Function",
        actor: /[a-z]/,
      },
    },
    "longStringObj": {
      value: {
        type: "object",
        class: "Object",
        actor: /[a-z]/,
      },
    },
    "notInspectable": {
      value: {
        type: "object",
        class: "Object",
        actor: /[a-z]/,
      },
    },
    "omg": {
      value: { type: "null" },
    },
    "omgfn": {
      value: {
        type: "object",
        class: "Function",
        actor: /[a-z]/,
      },
    },
    "tamarbuta": {
      value: {
        type: "longString",
        initial: longString.substring(0,
          DebuggerServer.LONG_STRING_INITIAL_LENGTH),
        length: longString.length,
      },
    },
    "testfoo": {
      value: false,
    },
  };
}

function onConsoleCall(aState, aType, aPacket)
{
  is(aPacket.from, aState.actor, "console API call actor");

  info("checking the console API call packet");

  checkConsoleAPICall(aPacket.message, {
    level: "log",
    filename: /test_object_actor/,
    functionName: "onAttach",
    arguments: ["hello", {
      type: "object",
      actor: /[a-z]/,
    }],
  });

  aState.dbgClient.removeListener("consoleAPICall", onConsoleCall);

  info("inspecting object properties");
  let args = aPacket.message.arguments;
  onProperties = onProperties.bind(null, aState);

  let client = new ObjectClient(aState.dbgClient, args[1]);
  client.getPrototypeAndProperties(onProperties);
}

function onProperties(aState, aResponse)
{
  let props = aResponse.ownProperties;
  is(Object.keys(props).length, Object.keys(expectedProps).length,
     "number of enumerable properties");
  checkObject(props, expectedProps);

  expectedProps = [];

  closeDebugger(aState, function() {
    SimpleTest.finish();
  });
}

addEventListener("load", startTest);
</script>
</body>
</html>