browser_dbg-tabs-pretty-print.js (2670B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 // Tests re-opening pretty printed tabs on load 6 7 "use strict"; 8 9 add_task(async function () { 10 let dbg = await initDebugger("doc-minified.html", "math.min.js"); 11 12 await selectSourceFromSourceTree(dbg, "math.min.js"); 13 assertSourceIcon(dbg, "math.min.js", "javascript"); 14 await togglePrettyPrint(dbg); 15 16 const tabs = findElement(dbg, "sourceTabs").children; 17 is(tabs.length, 1, "We still have only one tab opened"); 18 is(tabs[0].textContent, "math.min.js", "The tab title is correct"); 19 20 // Test reloading the debugger 21 await reload(dbg); 22 23 await waitForSelectedSource(dbg, "math.min.js:formatted"); 24 ok(true, "Pretty printed source is selected on reload"); 25 26 // Select any other source 27 await selectSourceFromSourceTree(dbg, "doc-minified.html"); 28 await togglePrettyPrint(dbg); 29 30 // Ensure that we can re-select the pretty printed source from the Source Tree 31 await selectSourceFromSourceTree(dbg, "math.min.js"); 32 await waitForSelectedSource(dbg, "math.min.js:formatted"); 33 const tab = findElement(dbg, "activeTab"); 34 is(tab.textContent, "math.min.js", "we stayed on the same tab after reload"); 35 is(countTabs(dbg), 2, "There is two tabs opened"); 36 37 const focusedTreeElement = findElementWithSelector( 38 dbg, 39 ".sources-list .focused .label" 40 ); 41 is( 42 focusedTreeElement.textContent.trim(), 43 "math.min.js", 44 "Pretty printed source is selected in tree" 45 ); 46 await dbg.toolbox.closeToolbox(); 47 48 // Do not use `initDebugger` as it resets all settings, including tabs 49 const toolbox = await openNewTabAndToolbox( 50 EXAMPLE_URL + "doc-minified.html", 51 "jsdebugger" 52 ); 53 dbg = createDebuggerContext(toolbox); 54 55 await waitForSelectedSource(dbg, "math.min.js:formatted"); 56 const [htmlTab, jsTab] = findElement(dbg, "sourceTabs").children; 57 is( 58 jsTab.textContent, 59 "math.min.js", 60 "After closing and re-opening the toolbox, the tab for the js tab is restored" 61 ); 62 is( 63 htmlTab.textContent, 64 "doc-minified.html", 65 "After closing and re-opening the toolbox, the tab for the html tab is restored" 66 ); 67 is(countTabs(dbg), 2, "There is still two opened tabs after re-opening"); 68 69 info( 70 "Click on the html source tab and verify the source is selected and pretty printed" 71 ); 72 htmlTab.click(); 73 await waitForSelectedSource(dbg, "doc-minified.html:formatted"); 74 ok( 75 findElement(dbg, "prettyPrintButton").classList.contains("pretty"), 76 "The restored HTML source is pretty printed" 77 ); 78 });