summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/node/components/console-api-call.test.js
blob: ff9d381d94bcd2f3a61a4e6c1e5d942d9beb0f96 (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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test utils.
const expect = require("expect");
const { render, mount } = require("enzyme");
const sinon = require("sinon");

// React
const { createFactory } = require("devtools/client/shared/vendor/react");
const Provider = createFactory(require("react-redux").Provider);
const { setupStore } = require("devtools/client/webconsole/test/node/helpers");

// Components under test.
const ConsoleApiCall = createFactory(
  require("devtools/client/webconsole/components/Output/message-types/ConsoleApiCall")
);
const {
  MESSAGE_OPEN,
  MESSAGE_CLOSE,
} = require("devtools/client/webconsole/constants");
const {
  INDENT_WIDTH,
} = require("devtools/client/webconsole/components/Output/MessageIndent");
const { prepareMessage } = require("devtools/client/webconsole/utils/messages");

// Test fakes.
const {
  stubPreparedMessages,
  stubPackets,
} = require("devtools/client/webconsole/test/node/fixtures/stubs/index");
const serviceContainer = require("devtools/client/webconsole/test/node/fixtures/serviceContainer");

describe("ConsoleAPICall component:", () => {
  describe("console.log", () => {
    it("renders string grips", () => {
      const message = stubPreparedMessages.get("console.log('foobar', 'test')");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe("foobar test");
      expect(wrapper.find(".objectBox-string").length).toBe(2);
      const selector =
        "div.message.cm-s-mozilla span span.message-flex-body " +
        "span.message-body.devtools-monospace";
      expect(wrapper.find(selector).length).toBe(1);

      // There should be the location
      const locationLink = wrapper.find(`.message-location`);
      expect(locationLink.length).toBe(1);
      expect(locationLink.text()).toBe("test-console-api.html:1:35");
    });

    it("renders string grips with custom style", () => {
      const message = stubPreparedMessages.get("console.log(%cfoobar)");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      const elements = wrapper.find(".objectBox-string");
      expect(elements.text()).toBe("foobar");
      expect(elements.length).toBe(2);

      const firstElementStyle = elements.eq(0).prop("style");
      // Allowed styles are applied accordingly on the first element.
      expect(firstElementStyle.color).toBe(`blue`);
      expect(firstElementStyle["font-size"]).toBe(`1.3em`);
      // Forbidden styles are not applied.
      expect(firstElementStyle["background-image"]).toBe(undefined);
      expect(firstElementStyle.position).toBe(undefined);
      expect(firstElementStyle.top).toBe(undefined);

      const secondElementStyle = elements.eq(1).prop("style");
      // Allowed styles are applied accordingly on the second element.
      expect(secondElementStyle.color).toBe(`red`);
      expect(secondElementStyle["line-height"]).toBe("1.5");
      // Forbidden styles are not applied.
      expect(secondElementStyle.background).toBe(undefined);
    });

    it("renders string grips with data-url background", () => {
      const message = stubPreparedMessages.get("console.log(%cfoobar)");

      const dataURL =
        "url(data:image/png,base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAAXNSR0IArs4c6QAAAaZJREFUKBV9UjFLQlEUPueaaUUEDZESNTYI9RfK5oimIGxJcy4IodWxpeZKiHBwc6ghIiIaWqNB/ANiBSU6vHfvU+89nSPpINKB996993zfPef7zkP4CyLCzl02Y7VNg4aE8y2QoYrTVJg+ublCROpjURb0ko11mt2i05BkEDjt+CGgvzUYehrvqtTUefFD8KpXoemK1ich1MDALppIPITROARqlwzWJKdbtihYIWH7dv/AenRBAdYmOriKmUJDEv1oHaVnOy39bn27wJjsfLl0qawHaWkFNOWGCUKcOSs0uM0c6wPyWC+H4k2Ce+b+w89yMDKC0LPzWadgORTJxh8YM5ITIdUmw4b5jt9MssaJrdD9DtZGMvjQ+zEbvUoBVgWj2K2CWGsDeyqih4n1zeyk1S4vlcDCteRRbGwe7z2yO0lOiOU5YA3SklTgYee5/WVw1IVoZGnxrVTv+e4dpmIyB74xSayPBQ8GS5qvZgIRjPFfUQlHQ+s9kpSUil9bOxl2U0aQIO0Mf6tA6hoi4Xsw7QfGsHv4OiAJ8b/4XNmeC9pYRgTvF+HgISP3T9PvAAAAAElFTkSuQmCC)";

      message.userProvidedStyles[0] = `background-image: ${dataURL}`;

      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));
      const elements = wrapper.find(".objectBox-string");
      const firstElementStyle = elements.eq(0).prop("style");

      // data-url background applied
      expect(firstElementStyle["background-image"]).toBe(dataURL);
    });

    it("renders custom styled logs with empty style as expected", () => {
      const message = stubPreparedMessages.get(
        'console.log("%cHello%c|%cWorld")'
      );
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      const elements = wrapper.find(".objectBox-string");
      expect(elements.text()).toBe("Hello|World");
      expect(elements.length).toBe(3);

      const firstElementStyle = elements.eq(0).prop("style");
      // Allowed styles are applied accordingly on the first element.
      expect(firstElementStyle.color).toBe("red");

      const secondElementStyle = elements.eq(1).prop("style");
      expect(secondElementStyle.color).toBe(undefined);

      const thirdElementStyle = elements.eq(2).prop("style");
      // Allowed styles are applied accordingly on the third element.
      expect(thirdElementStyle.color).toBe("blue");
    });

    it("renders prefixed messages", () => {
      const packet = stubPackets.get("console.log('foobar', 'test')");
      const stub = {
        ...packet,
        message: {
          ...packet.message,
          prefix: "MyNicePrefix",
        },
      };

      const wrapper = render(
        ConsoleApiCall({
          message: prepareMessage(stub, { getNextId: () => "p" }),
          serviceContainer,
        })
      );
      const prefix = wrapper.find(".console-message-prefix");
      expect(prefix.text()).toBe("MyNicePrefix: ");

      expect(wrapper.find(".message-body").text()).toBe(
        "MyNicePrefix: foobar test"
      );

      // There should be the location
      const locationLink = wrapper.find(`.message-location`);
      expect(locationLink.length).toBe(1);
      expect(locationLink.text()).toBe("test-console-api.html:1:35");
    });

    it("renders repeat node", () => {
      const message = stubPreparedMessages.get("console.log('foobar', 'test')");
      const wrapper = render(
        ConsoleApiCall({
          message,
          serviceContainer,
          repeat: 107,
        })
      );

      expect(wrapper.find(".message-repeats").text()).toBe("107");
      expect(wrapper.find(".message-repeats").prop("title")).toBe(
        "107 repeats"
      );

      const selector =
        "span > span.message-flex-body > " +
        "span.message-body.devtools-monospace + span.message-repeats";
      expect(wrapper.find(selector).length).toBe(1);
    });

    it("has the expected indent", () => {
      const message = stubPreparedMessages.get("console.log('foobar', 'test')");

      const indent = 10;
      let wrapper = render(
        ConsoleApiCall({
          message: Object.assign({}, message, { indent }),
          serviceContainer,
        })
      );
      let indentEl = wrapper.find(".indent");
      expect(indentEl.prop("style").width).toBe(`${indent * INDENT_WIDTH}px`);
      expect(indentEl.prop("data-indent")).toBe(`${indent}`);

      wrapper = render(ConsoleApiCall({ message, serviceContainer }));
      indentEl = wrapper.find(".indent");
      expect(indentEl.prop("style").width).toBe(`0`);
      expect(indentEl.prop("data-indent")).toBe(`0`);
    });

    it("renders a timestamp when passed a truthy timestampsVisible prop", () => {
      const message = stubPreparedMessages.get("console.log('foobar', 'test')");
      const wrapper = render(
        ConsoleApiCall({
          message,
          serviceContainer,
          timestampsVisible: true,
        })
      );
      const {
        timestampString,
      } = require("devtools/client/webconsole/utils/l10n");

      expect(wrapper.find(".timestamp").text()).toBe(
        timestampString(message.timeStamp)
      );
    });

    it("does not render a timestamp when not asked to", () => {
      const message = stubPreparedMessages.get("console.log('foobar', 'test')");
      const wrapper = render(
        ConsoleApiCall({
          message,
          serviceContainer,
        })
      );

      expect(wrapper.find(".timestamp").length).toBe(0);
    });
  });

  describe("console.count", () => {
    it("renders", () => {
      const messages = [
        {
          key: "console.count('bar')",
          expectedBodyText: "bar: 1",
        },
        {
          key: "console.count | default: 1",
          expectedBodyText: "default: 1",
        },
        {
          key: "console.count | default: 2",
          expectedBodyText: "default: 2",
        },
        {
          key: "console.count | test counter: 1",
          expectedBodyText: "test counter: 1",
        },
        {
          key: "console.count | test counter: 2",
          expectedBodyText: "test counter: 2",
        },
        {
          key: "console.count | default: 3",
          expectedBodyText: "default: 3",
        },
        {
          key: "console.count | default: 4",
          expectedBodyText: "default: 4",
        },
        {
          key: "console.count | test counter: 3",
          expectedBodyText: "test counter: 3",
        },
        {
          key: "console.countReset | test counter: 0",
          expectedBodyText: "test counter: 0",
        },
        {
          key: "console.countReset | counterDoesntExist",
          expectedBodyText: "Counter “test counter” doesn’t exist.",
        },
      ];

      for (const { key, expectedBodyText } of messages) {
        const message = stubPreparedMessages.get(key);
        const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

        expect(wrapper.find(".message-body").text()).toBe(expectedBodyText);
      }
    });
  });

  describe("console.assert", () => {
    it("renders", () => {
      const message = stubPreparedMessages.get(
        "console.assert(false, {message: 'foobar'})"
      );

      // We need to wrap the ConsoleApiElement in a Provider in order for the
      // ObjectInspector to work.
      const wrapper = render(
        Provider(
          { store: setupStore() },
          ConsoleApiCall({ message, serviceContainer })
        )
      );

      expect(wrapper.find(".message-body").text()).toBe(
        'Assertion failed: Object { message: "foobar" }'
      );
    });
  });

  describe("console.time", () => {
    it("does not show anything", () => {
      const message = stubPreparedMessages.get("console.time('bar')");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe("");
    });
    it("shows an error if called again", () => {
      const message = stubPreparedMessages.get("timerAlreadyExists");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe(
        "Timer “bar” already exists."
      );
    });
  });

  describe("console.timeLog", () => {
    it("renders as expected", () => {
      let message = stubPreparedMessages.get("console.timeLog('bar') - 1");
      // We need to wrap the ConsoleApiElement in a Provider in order for the
      // ObjectInspector to work.
      let wrapper = render(
        Provider(
          { store: setupStore() },
          ConsoleApiCall({ message, serviceContainer })
        )
      );

      expect(wrapper.find(".message-body").text()).toBe(message.parameters[0]);
      expect(wrapper.find(".message-body").text()).toMatch(
        /^bar: \d+(\.\d+)?ms$/
      );

      message = stubPreparedMessages.get("console.timeLog('bar') - 2");
      // We need to wrap the ConsoleApiElement in a Provider in order for the
      // ObjectInspector to work.
      wrapper = render(
        Provider(
          { store: setupStore() },
          ConsoleApiCall({ message, serviceContainer })
        )
      );
      expect(wrapper.find(".message-body").text()).toMatch(
        /^bar: \d+(\.\d+)?ms second call Object \{ state\: 1 \}$/
      );
    });
    it("shows an error if the timer doesn't exist", () => {
      const message = stubPreparedMessages.get("timeLog.timerDoesntExist");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe(
        "Timer “bar” doesn’t exist."
      );
    });
  });

  describe("console.timeEnd", () => {
    it("renders as expected", () => {
      const message = stubPreparedMessages.get("console.timeEnd('bar')");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe(message.messageText);
      expect(wrapper.find(".message-body").text()).toMatch(
        /^bar: \d+(\.\d+)?ms - timer ended$/
      );
    });
    it("shows an error if the timer doesn't exist", () => {
      const message = stubPreparedMessages.get("timeEnd.timerDoesntExist");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe(
        "Timer “bar” doesn’t exist."
      );
    });
  });

  // Unskip will happen in Bug 1529548.
  describe.skip("console.trace", () => {
    it("renders", () => {
      const message = stubPreparedMessages.get("console.trace()");
      const wrapper = render(
        ConsoleApiCall({ message, serviceContainer, open: true })
      );
      const filepath =
        "http://example.com/browser/devtools/client/webconsole/" +
        "test/fixtures/stub-generators/" +
        "test-console-api.html";

      expect(wrapper.find(".message-body").text()).toBe("console.trace()");

      const frameLinks = wrapper.find(`.stack-trace span.frame-link[data-url]`);
      expect(frameLinks.length).toBe(3);

      expect(
        frameLinks
          .eq(0)
          .find(".frame-link-function-display-name")
          .text()
      ).toBe("testStacktraceFiltering");
      expect(
        frameLinks
          .eq(0)
          .find(".frame-link-filename")
          .text()
      ).toBe(filepath);

      expect(
        frameLinks
          .eq(1)
          .find(".frame-link-function-display-name")
          .text()
      ).toBe("foo");
      expect(
        frameLinks
          .eq(1)
          .find(".frame-link-filename")
          .text()
      ).toBe(filepath);

      expect(
        frameLinks
          .eq(2)
          .find(".frame-link-function-display-name")
          .text()
      ).toBe("triggerPacket");
      expect(
        frameLinks
          .eq(2)
          .find(".frame-link-filename")
          .text()
      ).toBe(filepath);

      // it should not be collapsible.
      expect(wrapper.find(`.theme-twisty`).length).toBe(0);
    });
    it("render with arguments", () => {
      const message = stubPreparedMessages.get(
        "console.trace('bar', {'foo': 'bar'}, [1,2,3])"
      );
      // We need to wrap the ConsoleApiElement in a Provider in order for the
      // ObjectInspector to work.
      const wrapper = render(
        Provider(
          { store: setupStore() },
          ConsoleApiCall({ message, serviceContainer, open: true })
        )
      );

      const filepath =
        "http://example.com/browser/devtools/client/webconsole/" +
        "test/fixtures/stub-generators/test-console-api.html";

      expect(wrapper.find(".message-body").text()).toBe(
        'console.trace() bar Object { foo: "bar" } Array(3) [ 1, 2, 3 ]'
      );

      const frameLinks = wrapper.find(`.stack-trace span.frame-link[data-url]`);
      expect(frameLinks.length).toBe(3);

      expect(
        frameLinks
          .eq(0)
          .find(".frame-link-function-display-name")
          .text()
      ).toBe("testStacktraceWithLog");
      expect(
        frameLinks
          .eq(0)
          .find(".frame-link-filename")
          .text()
      ).toBe(filepath);

      expect(
        frameLinks
          .eq(1)
          .find(".frame-link-function-display-name")
          .text()
      ).toBe("foo");
      expect(
        frameLinks
          .eq(1)
          .find(".frame-link-filename")
          .text()
      ).toBe(filepath);

      expect(
        frameLinks
          .eq(2)
          .find(".frame-link-function-display-name")
          .text()
      ).toBe("triggerPacket");
      expect(
        frameLinks
          .eq(2)
          .find(".frame-link-filename")
          .text()
      ).toBe(filepath);

      // it should not be collapsible.
      expect(wrapper.find(`.theme-twisty`).length).toBe(0);
    });
  });

  describe("console.group", () => {
    it("renders", () => {
      const message = stubPreparedMessages.get("console.group('bar')");
      const wrapper = render(
        ConsoleApiCall({ message, serviceContainer, open: true })
      );

      expect(wrapper.find(".message-body").text()).toBe("bar");
      expect(wrapper.find(".collapse-button[aria-expanded=true]").length).toBe(
        1
      );
    });

    it("renders group with custom style", () => {
      const message = stubPreparedMessages.get("console.group(%cfoo%cbar)");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));
      expect(wrapper.find(".message-body").text()).toBe("foobar");

      const elements = wrapper.find(".objectBox-string");
      expect(elements.length).toBe(2);

      const firstElementStyle = elements.eq(0).prop("style");
      // Allowed styles are applied accordingly on the first element.
      expect(firstElementStyle.color).toBe(`blue`);
      expect(firstElementStyle["font-size"]).toBe(`1.3em`);
      // Forbidden styles are not applied.
      expect(firstElementStyle["background-image"]).toBe(undefined);
      expect(firstElementStyle.position).toBe(undefined);
      expect(firstElementStyle.top).toBe(undefined);

      const secondElementStyle = elements.eq(1).prop("style");
      // Allowed styles are applied accordingly on the second element.
      expect(secondElementStyle.color).toBe(`red`);
      // Forbidden styles are not applied.
      expect(secondElementStyle.background).toBe(undefined);
    });

    it("toggle the group when the collapse button is clicked", () => {
      const store = setupStore();
      store.dispatch = sinon.spy();
      const message = stubPreparedMessages.get("console.group('bar')");

      let wrapper = mount(
        Provider(
          { store },
          ConsoleApiCall({
            message,
            open: true,
            dispatch: store.dispatch,
            serviceContainer,
          })
        )
      );
      wrapper.find(".collapse-button[aria-expanded='true']").simulate("click");
      let call = store.dispatch.getCall(0);
      expect(call.args[0]).toEqual({
        id: message.id,
        type: MESSAGE_CLOSE,
      });

      wrapper = mount(
        Provider(
          { store },
          ConsoleApiCall({
            message,
            open: false,
            dispatch: store.dispatch,
            serviceContainer,
          })
        )
      );
      wrapper.find(".collapse-button").simulate("click");
      call = store.dispatch.getCall(1);
      expect(call.args[0]).toEqual({
        id: message.id,
        type: MESSAGE_OPEN,
      });
    });

    it("toggle the group when the group name is clicked", () => {
      const store = setupStore();
      store.dispatch = sinon.spy();
      const message = stubPreparedMessages.get("console.group('bar')");

      let wrapper = mount(
        Provider(
          { store },
          ConsoleApiCall({
            message,
            open: true,
            dispatch: store.dispatch,
            serviceContainer,
          })
        )
      );
      wrapper.find(".message-flex-body").simulate("click");
      let call = store.dispatch.getCall(0);
      expect(call.args[0]).toEqual({
        id: message.id,
        type: MESSAGE_CLOSE,
      });

      wrapper = mount(
        Provider(
          { store },
          ConsoleApiCall({
            message,
            open: false,
            dispatch: store.dispatch,
            serviceContainer,
          })
        )
      );
      wrapper.find(".message-flex-body").simulate("click");
      call = store.dispatch.getCall(1);
      expect(call.args[0]).toEqual({
        id: message.id,
        type: MESSAGE_OPEN,
      });
    });

    it("doesn't toggle the group when the location link is clicked", () => {
      const store = setupStore();
      store.dispatch = sinon.spy();
      const message = stubPreparedMessages.get("console.group('bar')");

      const wrapper = mount(
        Provider(
          { store },
          ConsoleApiCall({
            message,
            open: true,
            dispatch: store.dispatch,
            serviceContainer,
          })
        )
      );
      wrapper.find(".frame-link-source").simulate("click");
      const call = store.dispatch.getCall(0);
      expect(call).toNotExist();
    });
  });

  describe("console.groupEnd", () => {
    it("does not show anything", () => {
      const message = stubPreparedMessages.get("console.groupEnd('bar')");
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      expect(wrapper.find(".message-body").text()).toBe("");
    });
  });

  describe("console.groupCollapsed", () => {
    it("renders", () => {
      const message = stubPreparedMessages.get("console.groupCollapsed('foo')");
      const wrapper = render(
        ConsoleApiCall({ message, serviceContainer, open: false })
      );

      expect(wrapper.find(".message-body").text()).toBe("foo");
      expect(wrapper.find(".collapse-button:not(.expanded)").length).toBe(1);
    });

    it("renders group with custom style", () => {
      const message = stubPreparedMessages.get(
        "console.groupCollapsed(%cfoo%cbaz)"
      );
      const wrapper = render(ConsoleApiCall({ message, serviceContainer }));

      const elements = wrapper.find(".objectBox-string");
      expect(elements.text()).toBe("foobaz");
      expect(elements.length).toBe(2);

      const firstElementStyle = elements.eq(0).prop("style");
      // Allowed styles are applied accordingly on the first element.
      expect(firstElementStyle.color).toBe(`blue`);
      expect(firstElementStyle["font-size"]).toBe(`1.3em`);
      // Forbidden styles are not applied.
      expect(firstElementStyle["background-image"]).toBe(undefined);
      expect(firstElementStyle.position).toBe(undefined);
      expect(firstElementStyle.top).toBe(undefined);

      const secondElementStyle = elements.eq(1).prop("style");
      // Allowed styles are applied accordingly on the second element.
      expect(secondElementStyle.color).toBe(`red`);
      // Forbidden styles are not applied.
      expect(secondElementStyle.background).toBe(undefined);
    });
  });

  describe("console.dirxml", () => {
    it("renders", () => {
      const message = stubPreparedMessages.get("console.dirxml(window)");
      // We need to wrap the ConsoleApiElement in a Provider in order for the
      // ObjectInspector to work.
      const wrapper = render(
        Provider(
          { store: setupStore() },
          ConsoleApiCall({ message, serviceContainer })
        )
      );

      expect(wrapper.find(".message-body").text()).toBe(
        "Window http://example.com/browser/devtools/client/webconsole/test/browser/test-console-api.html"
      );
    });
  });

  describe("console.dir", () => {
    it("renders", () => {
      const message = stubPreparedMessages.get("console.dir({C, M, Y, K})");

      // We need to wrap the ConsoleApiElement in a Provider in order for the
      // ObjectInspector to work.
      const wrapper = render(
        Provider(
          { store: setupStore() },
          ConsoleApiCall({ message, serviceContainer })
        )
      );

      expect(wrapper.find(".message-body").text()).toBe(
        `Object { cyan: "C", magenta: "M", yellow: "Y", black: "K" }`
      );
    });
  });
});