summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/test-console-custom-formatters-errors.html
blob: 450672e78ef10c1172bd1db52e8626c9ee113181 (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
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <title>Webconsole erroneous custom formatters test page</title>
  </head>
  <body>
    <p>Erroneous custom formatters test page</p>
    <script>
      "use strict";

      window.devtoolsFormatters = [
        {
          // this header is invalid because it is not a function
          header: 1,
        },
        {
          // this header is invalid because it doesn't return JsonML
          header: () => 1,
        },
        {
          // this header is invalid because the returned array misses an element type
          header: () => [],
        },
        {
          // this header is invalid because it throws an exception
          header: () => { throw new Error("ERROR"); },
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("hasBodyNotAFunction") ?
              ["div", "hasBody not a function"] :
              null;
          },
          // this hasBody is invalid because it is not a function
          hasBody: 1,
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("hasBodyThrows") ?
              ["div", "hasBody throws"] :
              null;
          },
          // this hasBody throws an exception
          hasBody: () => { throw new Error("ERROR"); },
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("bodyNotAFunction") ?
              ["div", "body not a function"] :
              null;
          },
          hasBody: () => true,
          // this body is invalid because it is not a function
          body: 1,
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("bodyReturnsNull") ?
              ["div", "body returns null"] :
              null;
          },
          hasBody: () => true,
          // this body is invalid because it doesn't return JsonML
          body: () => null,
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("bodyNoJsonMl") ?
              ["div", "body doesn't return JsonML"] :
              null;
          },
          hasBody: () => true,
          // this body is invalid because it doesn't return JsonML
          body: () => 1,
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("bodyNoElementType") ?
              ["div", "body array misses element type"] :
              null;
          },
          hasBody: () => true,
          // this body is invalid because the returned array misses an element type
          body: () => [],
        },
        {
          header: (obj) => {
            return obj.hasOwnProperty("bodyThrows") ?
              ["div", "body throws"] :
              null;
          },
          hasBody: () => true,
          // this body is invalid because it throws an exception
          body: () => { throw new Error("ERROR"); },
        },
        {
          header: (obj) => {
            if (obj?.hasOwnProperty("objectTagWithNoAttribute")) {
              // This is invalid because "object" tag should have attributes
              return ["object"];
            }
            return null;
          },
        },
        {
          header: (obj) => {
            if (obj?.hasOwnProperty("objectTagWithoutObjectAttribute")) {
              // This is invalid because "object" tag should have an "object" attribute
              return [
                  "object",
                  { config: "something" }
                ];
            }
            return null;
          },
        },
        {
          header: (obj) => {
            if (obj?.hasOwnProperty("infiniteObjectTag")) {
              // This is invalid because this triggers an infinite loop (object is being
              // replaced by itself, which will keep triggering the custom formatter hook)
              return [ "object", { object: obj }];
            }
            return null;
          },
        },
        {
          // the returned value is invalid because the tagName isn't a string
          header: (obj) => {
            if (obj?.hasOwnProperty("invalidTag")) {
              return [ 42 ];
            }
            return null;
          },
        },
        {
          header: (obj) => {
            if (obj.hasOwnProperty("customFormatHeader")) {
              return ["span", {"style": "font-size: 3rem;"}, "custom formatted header"];
            }
            return null;
          },
          hasBody: () => false
        },
        {
          header: (obj) => {
            if (obj.hasOwnProperty("customFormatHeaderAndBody")) {
              return ["span", {"style": "font-style: italic;"}, "custom formatted body"];
            }
            return null;
          },
          hasBody: () => true,
          body: (obj) => ["span", {"style": "font-family: serif; font-size: 2rem;"}, obj.customFormatHeaderAndBody]
        },
        {
          header: (obj) => {
            if (obj.hasOwnProperty("privileged")) {
              // This should throw as the hooks should not have privileged access
              window.windowUtils.garbageCollect();
              return ["span", {}, "privileged"];
            }
            return null;
          },
        },
      ];

      [
        {},
        {hasBodyNotAFunction: true},
        {hasBodyThrows: true},
        {bodyNotAFunction: true},
        {bodyReturnsNull: true},
        {bodyNoJsonMl: true},
        {bodyNoElementType: true},
        {bodyThrows: true},
        {objectTagWithNoAttribute: true},
        {objectTagWithoutObjectAttribute: true},
        {infiniteObjectTag: true},
        {invalidTag: true},
        {privileged: true},
      ].forEach(variable => console.log(variable));
    </script>
  </body>
</html>