summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/components/test/chrome/test_frame_01.html
blob: f763b21395cfb8ae3d7e27843ba0f30ef3c18b99 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html>
  <!--
Test the formatting of the file name, line and columns are correct in frame components,
with optional columns, unknown and non-URL sources.
-->
  <head>
    <meta charset="utf-8" />
    <title>Frame component test</title>
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <link
      rel="stylesheet"
      type="text/css"
      href="chrome://mochikit/content/tests/SimpleTest/test.css"
    />
  </head>
  <body>
    <pre id="test">
<script src="head.js" type="application/javascript"></script>
<script type="application/javascript">

'use strict'

window.onload = async function () {
  try {
    const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
    const React = browserRequire("devtools/client/shared/vendor/react");
    const Frame = React.createFactory(browserRequire("devtools/client/shared/components/Frame"));
    ok(Frame, "Should get Frame");

    // Check when there's a column
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 55,
        column: 10,
      }
    }, {
      file: "mahscripts.js",
      line: 55,
      column: 10,
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55:10",
    });

    // Check when there's no column
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 55,
      }
    }, {
      file: "mahscripts.js",
      line: 55,
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55",
    });

    // Check when column === 0
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 55,
        column: 0,
      }
    }, {
      file: "mahscripts.js",
      line: 55,
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55",
    });

    // Check when there's an error in CSS (View source in Style Editor)
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/cafebabe.css",
        line: 13,
      },
      messageSource: "css",
    }, {
        file: "cafebabe.css",
        line: 13,
        shouldLink: true,
        tooltip: "View source in Style Editor → https://myfile.com/cafebabe.css:13",
    });


    // Check when there's no parseable URL source;
    // should not link but should render line/columns
    await checkFrameComponent({
      frame: {
        source: "self-hosted",
        line: 1,
      }
    }, {
      file: "self-hosted",
      line: "1",
      shouldLink: false,
      tooltip: "self-hosted:1",
    });
    await checkFrameComponent({
      frame: {
        source: "self-hosted",
        line: 1,
        column: 10,
      }
    }, {
      file: "self-hosted",
      line: "1",
      column: "10",
      shouldLink: false,
      tooltip: "self-hosted:1:10",
    });

    // Check when there's no source;
    // should not link but should render line/columns
    await checkFrameComponent({
      frame: {
        line: 1,
      }
    }, {
      file: "(unknown)",
      line: "1",
      shouldLink: false,
      tooltip: "(unknown):1",
    });
    await checkFrameComponent({
      frame: {
        line: 1,
        column: 10,
      }
    }, {
      file: "(unknown)",
      line: "1",
      column: "10",
      shouldLink: false,
      tooltip: "(unknown):1:10",
    });

    // Check when there's a column, but no line;
    // no line/column info should render
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        column: 55,
      }
    }, {
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    // Check when line is 0; this should be an invalid
    // line option, so don't render line/column
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 0,
        column: 55,
      }
    }, {
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    // Check that line and column can be strings
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: "10",
        column: "55",
      }
    }, {
      file: "mahscripts.js",
      line: 10,
      column: 55,
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:10:55",
    });

    // Check that line and column can be strings,
    // and that the `0` rendering rules apply when they are strings as well
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: "0",
        column: "55",
      }
    }, {
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    // Check that the showFullSourceUrl option works correctly
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 0,
      },
      showFullSourceUrl: true
    }, {
      file: "https://myfile.com/mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    // Check that the showFunctionName option works correctly
    await checkFrameComponent({
      frame: {
        functionDisplayName: "myfun",
        source: "https://myfile.com/mahscripts.js",
        line: 0,
      }
    }, {
      functionName: null,
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    await checkFrameComponent({
      frame: {
        functionDisplayName: "myfun",
        source: "https://myfile.com/mahscripts.js",
        line: 0,
      },
      showFunctionName: true
    }, {
      functionName: "myfun",
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    // Check that anonymous function name is not displayed unless explicitly enabled
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 0,
      },
      showFunctionName: true
    }, {
      functionName: null,
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 0,
      },
      showFunctionName: true,
      showAnonymousFunctionName: true
    }, {
      functionName: "<anonymous>",
      file: "mahscripts.js",
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js",
    });

    // Check if file is rendered with "/" for root documents when showEmptyPathAsHost is false
    await checkFrameComponent({
      frame: {
        source: "https://www.cnn.com/",
        line: "1",
      },
      showEmptyPathAsHost: false,
    }, {
      file: "/",
      line: "1",
      shouldLink: true,
      tooltip: "View source in Debugger → https://www.cnn.com/:1",
    });

    // Check if file is rendered with hostname for root documents when showEmptyPathAsHost is true
    await checkFrameComponent({
      frame: {
        source: "https://www.cnn.com/",
        line: "1",
      },
      showEmptyPathAsHost: true,
    }, {
      file: "www.cnn.com",
      line: "1",
      shouldLink: true,
      tooltip: "View source in Debugger → https://www.cnn.com/:1",
    });

    const resolvedLocation = {
      sourceId: "whatever",
      line: 23,
      sourceUrl: "https://bugzilla.mozilla.org/original.js",
    };
    const mockSourceMapURLService = {
      subscribeByLocation (loc, callback) {
        // Resolve immediately.
        callback({
          url: resolvedLocation.sourceUrl,
          line: resolvedLocation.line,
          column: undefined,
        });
        return () => {};
      },
    };
    await checkFrameComponent({
      frame: {
        line: 97,
        source: "https://bugzilla.mozilla.org/bundle.js",
      },
      sourceMapURLService: mockSourceMapURLService,
    }, {
      file: "original.js",
      line: resolvedLocation.line,
      shouldLink: true,
      tooltip: "View source in Debugger → https://bugzilla.mozilla.org/original.js:23",
      source: "https://bugzilla.mozilla.org/original.js",
    });

    // Check when a message comes from a logPoint,
    // a prefix should render before source
    await checkFrameComponent({
      frame: {
        source: "https://myfile.com/mahscripts.js",
        line: 55,
        column: 10,
        options: { logPoint: true },
      }
    }, {
      file: "mahscripts.js",
      line: 55,
      column: 10,
      shouldLink: true,
      tooltip: "View source in Debugger → https://myfile.com/mahscripts.js:55:10",
    });

    function checkFrameComponent(input, expected) {
      const props = Object.assign({ onClick: () => {} }, input);
      const frame = ReactDOM.render(Frame(props), window.document.body);
      const el = ReactDOM.findDOMNode(frame);
      const { source } = input.frame;
      checkFrameString(Object.assign({ el, source }, expected));
      ReactDOM.unmountComponentAtNode(window.document.body);
    }

  } catch (e) {
    ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
  } finally {
    SimpleTest.finish();
  }
};
</script>
</pre>
  </body>
</html>