browser_ConsoleStoragePBTest_perwindowpb.js (1753B)
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 const testURI = 6 "http://example.com/browser/dom/tests/browser/test-console-api.html"; 7 8 function getInnerWindowId(aWindow) { 9 return aWindow.windowGlobalChild.innerWindowId; 10 } 11 12 async function doTest(aIsPrivateMode) { 13 const window = await BrowserTestUtils.openNewBrowserWindow({ 14 private: aIsPrivateMode, 15 }); 16 17 const ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService( 18 Ci.nsIConsoleAPIStorage 19 ); 20 21 const innerID = getInnerWindowId(window); 22 const beforeEvents = ConsoleAPIStorage.getEvents(innerID); 23 BrowserTestUtils.startLoadingURIString( 24 window.gBrowser.selectedBrowser, 25 testURI 26 ); 27 28 await BrowserTestUtils.browserLoaded(window.gBrowser.selectedBrowser, { 29 wantLoad: testURI, 30 }); 31 32 const consoleEventPromise = new Promise(res => { 33 function listener() { 34 ConsoleAPIStorage.removeLogEventListener(listener); 35 res(); 36 } 37 ConsoleAPIStorage.addLogEventListener( 38 listener, 39 window.document.nodePrincipal 40 ); 41 }); 42 43 window.nativeConsole.log("foo bar baz (private: " + aIsPrivateMode + ")"); 44 45 await consoleEventPromise; 46 47 const afterEvents = ConsoleAPIStorage.getEvents(innerID); 48 // We expect that console API messages are always stored. 49 is( 50 beforeEvents.length == afterEvents.length - 1, 51 true, 52 "storage should occur" 53 ); 54 55 await BrowserTestUtils.closeWindow(window); 56 } 57 58 add_task(async function test_console_storage() { 59 await doTest(false); 60 }); 61 62 add_task(async function test_console_storage_private_browsing() { 63 await doTest(true); 64 });