browser_webconsole_timestamps.js (1826B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test for the message timestamps option: check if the preference toggles the 5 // display of messages in the console output. See bug 722267. 6 7 "use strict"; 8 9 const { PrefObserver } = require("resource://devtools/client/shared/prefs.js"); 10 11 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html> 12 Web Console test for bug 1307871 - preference for toggling timestamps in messages`; 13 const PREF_MESSAGE_TIMESTAMP = "devtools.webconsole.timestampMessages"; 14 15 add_task(async function () { 16 const hud = await openNewTabAndConsole(TEST_URI); 17 18 info("Call the log function defined in the test page"); 19 const onMessage = waitForMessageByType( 20 hud, 21 "simple text message", 22 ".console-api" 23 ); 24 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 25 content.wrappedJSObject.console.log("simple text message"); 26 }); 27 const message = await onMessage; 28 29 const prefValue = Services.prefs.getBoolPref(PREF_MESSAGE_TIMESTAMP); 30 ok(!prefValue, "Messages should have no timestamp by default (pref check)"); 31 ok( 32 !message.node.querySelector(".timestamp"), 33 "Messages should have no timestamp by default (element check)" 34 ); 35 36 const observer = new PrefObserver(""); 37 38 info("Change Timestamp preference"); 39 const prefChanged = observer.once(PREF_MESSAGE_TIMESTAMP, () => {}); 40 41 await toggleConsoleSetting( 42 hud, 43 ".webconsole-console-settings-menu-item-timestamps" 44 ); 45 46 await prefChanged; 47 observer.destroy(); 48 49 const timestampElement = message.node.querySelector(".timestamp"); 50 ok(timestampElement, "Messages should have timestamp"); 51 52 ok(timestampElement.getAttribute("title"), "Timestamp should have a title"); 53 54 Services.prefs.clearUserPref(PREF_MESSAGE_TIMESTAMP); 55 });