browser_console_microtask.js (1729B)
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 // The console input should be evaluated with microtask level != 0. 6 7 "use strict"; 8 9 add_task(async function () { 10 // Needed for the execute() function below 11 await pushPref("security.allow_parent_unrestricted_js_loads", true); 12 13 const hud = await BrowserConsoleManager.toggleBrowserConsole(); 14 15 hud.iframeWindow.focus(); 16 execute( 17 hud, 18 ` 19 { 20 let logCount = 0; 21 22 queueMicrotask(() => { 23 console.log("#" + logCount + ": in microtask"); 24 logCount++; 25 }); 26 27 console.log("#" + logCount + ": before createXULElement"); 28 logCount++; 29 30 // This shouldn't perform microtask checkpoint. 31 document.createXULElement("browser"); 32 33 console.log("#" + logCount + ": after createXULElement"); 34 logCount++; 35 } 36 ` 37 ); 38 39 const beforeCreateXUL = await waitFor(() => 40 findConsoleAPIMessage(hud, "before createXULElement") 41 ); 42 const afterCreateXUL = await waitFor(() => 43 findConsoleAPIMessage(hud, "after createXULElement") 44 ); 45 const inMicroTask = await waitFor(() => 46 findConsoleAPIMessage(hud, "in microtask") 47 ); 48 49 const getMessageIndex = msg => { 50 const text = msg.textContent; 51 return text.match(/^#(\d+)/)[1]; 52 }; 53 54 is( 55 getMessageIndex(beforeCreateXUL), 56 "0", 57 "before createXULElement log is displayed first" 58 ); 59 is( 60 getMessageIndex(afterCreateXUL), 61 "1", 62 "after createXULElement log is displayed second" 63 ); 64 is(getMessageIndex(inMicroTask), "2", "in microtask log is displayed last"); 65 66 ok(true, "Expected messages are displayed in the browser console"); 67 });