blob: 21afe57877495892f2a9b404385d8a89e0604341 [file] [log] [blame]
Al Muthanna Athamina68a03562022-11-16 13:21:171// Copyright 2022 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {
6 goToResource,
7} from '../../shared/helper.js';
Al Muthanna Athamina68a03562022-11-16 13:21:178import {
9 checkCommandResultFunction,
10 navigateToConsoleTab,
11} from '../helpers/console-helpers.js';
12
13// offset is 1 because Console.log returns undefined after logging, so we want
14// to check the output before the last one.
15const checkCommandResult = checkCommandResultFunction(1);
16
Benedikt Meurercb7952f2024-02-21 13:32:2317describe('The Console Tab', function() {
Al Muthanna Athamina2dfdf4a2022-11-28 14:11:5818 // This test takes longer than usual because each command is typed and
19 // checked individually.
20 this.timeout(20000);
21 it('Truncates large messages', async () => {
Al Muthanna Athamina68a03562022-11-16 13:21:1722 await goToResource('../resources/console/command-line-api-getEventListeners.html');
23 await navigateToConsoleTab();
24 const overMaxLength = 10001;
25
26 await checkCommandResult(
27 `console.log("a".repeat(${overMaxLength}))`,
28 `${'a'.repeat(5000)}`,
29 'Console unable to truncate long strings',
30 );
31
32 await checkCommandResult(
33 `console.log("%s", "a".repeat(${overMaxLength}))`,
34 `${'a'.repeat(5000)}`,
35 'Console unable to truncate long formatted strings',
36 );
37
38 await checkCommandResult(
39 `console.log("a".repeat(${overMaxLength}), "b".repeat(${overMaxLength}))`,
40 `${'a'.repeat(5000)} ${'b'.repeat(5000)}`,
41 'Console unable to truncate multiple long strings',
42 );
43
44 await checkCommandResult(
45 `console.log("%o", "a".repeat(${overMaxLength}))`,
46 `\'${'a'.repeat(4999)}`,
47 'Console unable to truncate DOM element',
48 );
49
50 await checkCommandResult(
51 `console.log("%c" + "a".repeat(${overMaxLength}), "color: green")`,
52 `${'a'.repeat(5000)}`,
53 'Console unable to truncate formatted string with CSS rules',
54 );
55
56 await checkCommandResult(
57 `console.log("foo %s %o bar", "a".repeat(${overMaxLength}), {a: 1})`,
58 `foo ${'a'.repeat(4996)}{a: 1} bar`,
59 'Console unable to truncate formatted string with DOM element',
60 );
61
62 await checkCommandResult(
63 `console.log({a: 1}, "a".repeat(${overMaxLength}), {b: 1})`,
64 `{a: 1} \'${'a'.repeat(4999)} {b: 1}`,
65 'Console unable to truncate string containing objects',
66 );
67
68 await checkCommandResult(
69 `console.log("a".repeat(${overMaxLength}), "https://chromium.org")`,
70 `${'a'.repeat(5000)} https://chromium.org`,
71 'Console unable to truncate string ending with a link',
72 );
73
74 await checkCommandResult(
75 `console.log("https://chromium.org", "a".repeat(${overMaxLength}))`,
76 `https://chromium.org ${'a'.repeat(5000)}`,
77 'Console unable to truncate string beginning with a link',
78 );
79
80 await checkCommandResult(
81 `console.log(RegExp("a".repeat(${overMaxLength})))`,
82 `\/${'a'.repeat(4999)}`,
83 'Console unable to truncate a regular expression',
84 );
85
86 await checkCommandResult(
87 `console.log(Symbol("a".repeat(${overMaxLength})))`,
88 `Symbol(${'a'.repeat(4993)}`,
89 'Console unable to truncate a symbol',
90 );
91
92 await checkCommandResult(
93 `console.log(["a".repeat(${overMaxLength})])`,
94 `[\'${'a'.repeat(50)}…${'a'.repeat(49)}\']`,
95 'Console unable to truncate an array',
96 );
97 });
98});