browser_webconsole_split_persist.js (4154B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the split console state is persisted. 7 8 const TEST_URI = 9 "data:text/html;charset=utf-8,<!DOCTYPE html><p>Web Console test for splitting</p>"; 10 11 add_task(async function () { 12 const getFluentString = await getFluentStringHelper([ 13 "devtools/client/toolbox.ftl", 14 ]); 15 const hideLabel = getFluentString("toolbox-meatball-menu-hideconsole-label"); 16 const showLabel = getFluentString("toolbox-meatball-menu-splitconsole-label"); 17 18 info("Opening a tab while there is no user setting on split console pref"); 19 let toolbox = await openNewTabAndToolbox(TEST_URI, "inspector"); 20 ok(!toolbox.splitConsole, "Split console is hidden by default"); 21 is( 22 await getSplitConsoleMenuLabel(toolbox), 23 showLabel, 24 "Split console menu item says split by default" 25 ); 26 27 await toggleSplitConsoleWithEscape(toolbox); 28 ok(toolbox.splitConsole, "Split console is now visible."); 29 is( 30 await getSplitConsoleMenuLabel(toolbox), 31 hideLabel, 32 "Split console menu item now says hide" 33 ); 34 ok(getVisiblePrefValue(), "Visibility pref is true"); 35 36 is( 37 parseInt(getHeightPrefValue(), 10), 38 parseInt(toolbox.webconsolePanel.style.height, 10), 39 "Panel height matches the pref" 40 ); 41 toolbox.webconsolePanel.style.height = "200px"; 42 43 await toolbox.destroy(); 44 45 info( 46 "Opening a tab while there is a true user setting on split console pref" 47 ); 48 toolbox = await openNewTabAndToolbox(TEST_URI, "inspector"); 49 ok(toolbox.splitConsole, "Split console is visible by default."); 50 ok( 51 isInputFocused(toolbox.getPanel("webconsole").hud), 52 "Split console input is focused by default" 53 ); 54 is( 55 await getSplitConsoleMenuLabel(toolbox), 56 hideLabel, 57 "Split console menu item initially says hide" 58 ); 59 is( 60 getHeightPrefValue(), 61 200, 62 "Height is set based on panel height after closing" 63 ); 64 65 toolbox.webconsolePanel.style.height = "1px"; 66 Assert.greater( 67 toolbox.webconsolePanel.clientHeight, 68 1, 69 "The actual height of the console is bound with a min height" 70 ); 71 72 await toggleSplitConsoleWithEscape(toolbox); 73 ok(!toolbox.splitConsole, "Split console is now hidden."); 74 is( 75 await getSplitConsoleMenuLabel(toolbox), 76 showLabel, 77 "Split console menu item now says split" 78 ); 79 ok(!getVisiblePrefValue(), "Visibility pref is false"); 80 81 await toolbox.destroy(); 82 83 is( 84 getHeightPrefValue(), 85 1, 86 "Height is set based on panel height after closing" 87 ); 88 89 info( 90 "Opening a tab while there is a false user setting on split " + 91 "console pref" 92 ); 93 toolbox = await openNewTabAndToolbox(TEST_URI, "inspector"); 94 95 ok(!toolbox.splitConsole, "Split console is hidden by default."); 96 ok(!getVisiblePrefValue(), "Visibility pref is false"); 97 98 await toolbox.destroy(); 99 }); 100 101 function getVisiblePrefValue() { 102 return Services.prefs.getBoolPref("devtools.toolbox.splitconsole.open"); 103 } 104 105 function getHeightPrefValue() { 106 return Services.prefs.getIntPref("devtools.toolbox.splitconsoleHeight"); 107 } 108 109 async function getSplitConsoleMenuLabel(toolbox) { 110 const button = toolbox.doc.getElementById("toolbox-meatball-menu-button"); 111 await waitUntil( 112 () => toolbox.win.getComputedStyle(button).pointerEvents === "auto" 113 ); 114 return new Promise(resolve => { 115 EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win); 116 117 toolbox.doc.addEventListener( 118 "popupshown", 119 () => { 120 const menuItem = toolbox.doc.getElementById( 121 "toolbox-meatball-menu-splitconsole" 122 ); 123 124 toolbox.doc.addEventListener( 125 "popuphidden", 126 () => { 127 resolve(menuItem?.querySelector(".label")?.textContent); 128 }, 129 { once: true } 130 ); 131 EventUtils.synthesizeKey("KEY_Escape"); 132 }, 133 { once: true } 134 ); 135 }); 136 } 137 138 function toggleSplitConsoleWithEscape(toolbox) { 139 const onceSplitConsole = toolbox.once("split-console"); 140 const toolboxWindow = toolbox.win; 141 toolboxWindow.focus(); 142 EventUtils.sendKey("ESCAPE", toolboxWindow); 143 return onceSplitConsole; 144 }