browser_dbg-console-async.js (1549B)
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 // Return a promise with a reference to jsterm, opening the split 6 // console if necessary. This cleans up the split console pref so 7 // it won't pollute other tests. 8 9 "use strict"; 10 11 add_task(async function () { 12 Services.prefs.setBoolPref("devtools.toolbox.splitconsole.open", true); 13 Services.prefs.setBoolPref( 14 "devtools.debugger.features.map-await-expression", 15 true 16 ); 17 18 const dbg = await initDebugger( 19 "doc-script-switching.html", 20 "script-switching-01.js" 21 ); 22 23 await selectSource(dbg, "script-switching-01.js"); 24 25 // open the console 26 await getDebuggerSplitConsole(dbg); 27 ok(dbg.toolbox.splitConsole, "Split console is shown."); 28 29 const webConsole = await dbg.toolbox.getPanel("webconsole"); 30 const wrapper = webConsole.hud.ui.wrapper; 31 32 wrapper.dispatchEvaluateExpression(` 33 let sleep = async (time, v) => new Promise( 34 res => setTimeout(() => res(v+'!!!'), time) 35 ) 36 `); 37 38 await hasMessageByType(dbg, "sleep", ".command"); 39 40 wrapper.dispatchEvaluateExpression(`await sleep(200, "DONE")`); 41 await hasMessageByType(dbg, "DONE!!!", ".result"); 42 }); 43 44 async function hasMessageByType(dbg, msg, typeSelector) { 45 const webConsole = await dbg.toolbox.getPanel("webconsole"); 46 const hud = webConsole.hud; 47 return waitFor( 48 async () => !!findMessagesByType(hud, msg, typeSelector).length 49 ); 50 }