browser_webconsole_limit_multiline.js (2040B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests that the code with > 5 lines in multiline editor mode 5 // is collapsible 6 // Check Bug 1578212 for more info 7 8 "use strict"; 9 const { ELLIPSIS } = require("resource://devtools/shared/l10n.js"); 10 11 const SMALL_EXPRESSION = `function fib(n) { 12 if (n <= 1) 13 return 1; 14 return fib(n-1) + fib(n-2); 15 }`; 16 17 const LONG_EXPRESSION = `${SMALL_EXPRESSION} 18 fib(3);`; 19 20 add_task(async function () { 21 const hud = await openNewTabAndConsole( 22 "data:text/html,<!DOCTYPE html><meta charset=utf8>Test multi-line commands expandability" 23 ); 24 info("Test that we don't slice messages with <= 5 lines"); 25 const message = await executeAndWaitForMessageByType( 26 hud, 27 SMALL_EXPRESSION, 28 "function fib", 29 ".command" 30 ); 31 32 is( 33 message.node.querySelector(".collapse-button"), 34 null, 35 "Collapse button does not exist" 36 ); 37 38 info("Test messages with > 5 lines are sliced"); 39 40 const messageExp = await executeAndWaitForMessageByType( 41 hud, 42 LONG_EXPRESSION, 43 "function fib", 44 ".command" 45 ); 46 47 const toggleArrow = messageExp.node.querySelector(".collapse-button"); 48 ok(toggleArrow, "Collapse button exists"); 49 // Check for elipsis 50 ok(messageExp.node.innerText.includes(ELLIPSIS), "Has ellipsis"); 51 52 info("Test clicking the button expands/collapses the message"); 53 54 const isOpen = node2 => node2.classList.contains("open"); 55 56 toggleArrow.click(); // expand 57 await waitFor(() => isOpen(messageExp.node) === true); 58 59 ok( 60 !messageExp.node.innerText.includes(ELLIPSIS), 61 "Opened message doesn't have ellipsis" 62 ); 63 is( 64 messageExp.node.innerText.trim().split("\n").length, 65 LONG_EXPRESSION.split("\n").length, 66 "Expanded code has same number of lines as original" 67 ); 68 69 toggleArrow.click(); // expand 70 await waitFor(() => isOpen(messageExp.node) === false); 71 72 is( 73 messageExp.node.innerText.trim().split("\n").length, 74 5, 75 "Code is truncated & only 5 lines shown" 76 ); 77 });