summaryrefslogtreecommitdiffstats
path: root/devtools/shared/webconsole/test/chrome/test_object_actor.html
blob: f42035e2cee112527ed76d1cc2e9df76d4147dc1 (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
<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="utf8">
  <title>Test for the object actor</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" 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">
"use strict";

SimpleTest.waitForExplicitFinish();

SpecialPowers.pushPrefEnv({
  "set":  [["security.allow_eval_with_system_principal", true]]
});

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

  const longString = (new Array(DevToolsServer.LONG_STRING_LENGTH + 3)).join("\u0629");
  createTestGlobalVariable(longString);

  const {state} = await attachConsoleToTab(["ConsoleAPI"]);
  const onConsoleApiCall = state.webConsoleFront.once("consoleAPICall");
  top.console.log("hello", top.wrappedJSObject.foobarObject);
  const {message} = await onConsoleApiCall;

  info("checking the console API call packet");
  checkConsoleAPICall(message, {
    level: "log",
    filename: /test_object_actor/,
    arguments: ["hello", {
      type: "object",
      actor: /[a-z]/,
    }],
  });

  info("inspecting object properties");
  const {ownProperties} = await message.arguments[1].getPrototypeAndProperties();

  const 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: "HTMLDocument",
        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,
          DevToolsServer.LONG_STRING_INITIAL_LENGTH),
        length: longString.length,
      },
    },
    "testfoo": {
      value: false,
    },
  };
  is(Object.keys(ownProperties).length, Object.keys(expectedProps).length,
     "number of enumerable properties");
  checkObject(ownProperties, expectedProps);

  await closeDebugger(state);
  SimpleTest.finish();
}


function createTestGlobalVariable(longString) {
  // Here we put the objects in the correct window, to avoid having them all
  // wrapped by proxies for cross-compartment access.
  const 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;
}

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