|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Test the webconsole output for various types of objects. |
|
7 |
|
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-02.html"; |
|
9 |
|
10 let inputTests = [ |
|
11 // 0 - native named function |
|
12 { |
|
13 input: "document.getElementById", |
|
14 output: "function getElementById()", |
|
15 printOutput: "function getElementById() {\n [native code]\n}", |
|
16 inspectable: true, |
|
17 variablesViewLabel: "getElementById()", |
|
18 }, |
|
19 |
|
20 // 1 - anonymous function |
|
21 { |
|
22 input: "(function() { return 42; })", |
|
23 output: "function ()", |
|
24 printOutput: "function () { return 42; }", |
|
25 inspectable: true, |
|
26 }, |
|
27 |
|
28 // 2 - named function |
|
29 { |
|
30 input: "window.testfn1", |
|
31 output: "function testfn1()", |
|
32 printOutput: "function testfn1() { return 42; }", |
|
33 inspectable: true, |
|
34 variablesViewLabel: "testfn1()", |
|
35 }, |
|
36 |
|
37 // 3 - anonymous function, but spidermonkey gives us an inferred name. |
|
38 { |
|
39 input: "testobj1.testfn2", |
|
40 output: "function testobj1.testfn2()", |
|
41 printOutput: "function () { return 42; }", |
|
42 inspectable: true, |
|
43 variablesViewLabel: "testobj1.testfn2()", |
|
44 }, |
|
45 |
|
46 // 4 - named function with custom display name |
|
47 { |
|
48 input: "window.testfn3", |
|
49 output: "function testfn3DisplayName()", |
|
50 printOutput: "function testfn3() { return 42; }", |
|
51 inspectable: true, |
|
52 variablesViewLabel: "testfn3DisplayName()", |
|
53 }, |
|
54 |
|
55 // 5 - basic array |
|
56 { |
|
57 input: "window.array1", |
|
58 output: 'Array [ 1, 2, 3, "a", "b", "c", "4", "5" ]', |
|
59 printOutput: "1,2,3,a,b,c,4,5", |
|
60 inspectable: true, |
|
61 variablesViewLabel: "Array[8]", |
|
62 }, |
|
63 |
|
64 // 6 - array with objects |
|
65 { |
|
66 input: "window.array2", |
|
67 output: 'Array [ "a", HTMLDocument \u2192 test-console-output-02.html, <body>, ' + |
|
68 "DOMStringMap[0], DOMTokenList[0] ]", |
|
69 printOutput: '"a,[object HTMLDocument],[object HTMLBodyElement],' + |
|
70 '[object DOMStringMap],"', |
|
71 inspectable: true, |
|
72 variablesViewLabel: "Array[5]", |
|
73 }, |
|
74 |
|
75 // 7 - array with more than 10 elements |
|
76 { |
|
77 input: "window.array3", |
|
78 output: 'Array [ 1, Window \u2192 test-console-output-02.html, null, "a", "b", ' + |
|
79 'undefined, false, "", -Infinity, testfn3DisplayName(), 3 more\u2026 ]', |
|
80 printOutput: '"1,[object Window],,a,b,,false,,-Infinity,' + |
|
81 'function testfn3() { return 42; },[object Object],foo,bar"', |
|
82 inspectable: true, |
|
83 variablesViewLabel: "Array[13]", |
|
84 }, |
|
85 |
|
86 // 8 - array with holes and a cyclic reference |
|
87 { |
|
88 input: "window.array4", |
|
89 output: 'Array [ , , , , , "test", Array[7] ]', |
|
90 printOutput: '",,,,,test,"', |
|
91 inspectable: true, |
|
92 variablesViewLabel: "Array[7]", |
|
93 }, |
|
94 |
|
95 // 9 |
|
96 { |
|
97 input: "window.typedarray1", |
|
98 output: 'Int32Array [ 1, 287, 8651, 40983, 8754 ]', |
|
99 printOutput: "[object Int32Array]", |
|
100 inspectable: true, |
|
101 variablesViewLabel: "Int32Array[5]", |
|
102 }, |
|
103 |
|
104 // 10 - Set with cyclic reference |
|
105 { |
|
106 input: "window.set1", |
|
107 output: 'Set [ 1, 2, null, Array[13], "a", "b", undefined, <head>, Set[9] ]', |
|
108 printOutput: "[object Set]", |
|
109 inspectable: true, |
|
110 variablesViewLabel: "Set[9]", |
|
111 }, |
|
112 |
|
113 // 11 - Object with cyclic reference and a getter |
|
114 { |
|
115 input: "window.testobj2", |
|
116 output: 'Object { a: "b", c: "d", e: 1, f: "2", foo: Object, bar: Object, ' + |
|
117 "getterTest: Getter }", |
|
118 printOutput: "[object Object]", |
|
119 inspectable: true, |
|
120 variablesViewLabel: "Object", |
|
121 }, |
|
122 |
|
123 // 12 - Object with more than 10 properties |
|
124 { |
|
125 input: "window.testobj3", |
|
126 output: 'Object { a: "b", c: "d", e: 1, f: "2", g: true, h: null, i: undefined, ' + |
|
127 'j: "", k: StyleSheetList[0], l: NodeList[5], 2 more\u2026 }', |
|
128 printOutput: "[object Object]", |
|
129 inspectable: true, |
|
130 variablesViewLabel: "Object", |
|
131 }, |
|
132 |
|
133 // 13 - Object with a non-enumerable property that we do not show |
|
134 { |
|
135 input: "window.testobj4", |
|
136 output: 'Object { a: "b", c: "d", 1 more\u2026 }', |
|
137 printOutput: "[object Object]", |
|
138 inspectable: true, |
|
139 variablesViewLabel: "Object", |
|
140 }, |
|
141 |
|
142 // 14 - Map with cyclic references |
|
143 { |
|
144 input: "window.map1", |
|
145 output: 'Map { a: "b", HTMLCollection[2]: Object, Map[3]: Set[9] }', |
|
146 printOutput: "[object Map]", |
|
147 inspectable: true, |
|
148 variablesViewLabel: "Map[3]", |
|
149 }, |
|
150 ]; |
|
151 |
|
152 function test() { |
|
153 requestLongerTimeout(2); |
|
154 Task.spawn(function*() { |
|
155 const {tab} = yield loadTab(TEST_URI); |
|
156 const hud = yield openConsole(tab); |
|
157 yield checkOutputForInputs(hud, inputTests); |
|
158 inputTests = null; |
|
159 }).then(finishTest); |
|
160 } |