browser_webconsole_console_detection.js (1357B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests that the console doesn't trigger any function in the page when logging the message 5 6 "use strict"; 7 8 const TEST_URI = `data:text/html,<script>function logMessages() { 9 /* Check if page functions can be called by console previewers */ 10 const date = new Date(2024, 0, 1); 11 date.getTime = () => { 12 return 42; 13 }; 14 Date.prototype.getTime = date.getTime; 15 console.log("date", date); 16 17 const regexp = /foo/m; 18 regexp.toString = () => { 19 return "24"; 20 }; 21 console.log("regexp", regexp); 22 }</script>`; 23 24 add_task(async function () { 25 await addTab(TEST_URI); 26 27 info("Open the console"); 28 const hud = await openConsole(); 29 30 // Only log messages *after* the console is opened as it may not trigger the same codepath for cached messages 31 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 32 content.wrappedJSObject.logMessages(); 33 }); 34 35 const dateMessage = await waitFor(() => findConsoleAPIMessage(hud, "date")); 36 Assert.stringContains(dateMessage.textContent, "Jan 01 2024"); 37 38 const regExpMessage = await waitFor(() => 39 findConsoleAPIMessage(hud, "regexp") 40 ); 41 Assert.stringContains(regExpMessage.textContent, "/foo/m"); 42 43 await closeTabAndToolbox(); 44 });