browser_bug763468_perwindowpb.js (1539B)
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 "use strict"; 5 6 // This test makes sure that opening a new tab in private browsing mode opens about:privatebrowsing 7 add_task(async function testPBNewTab() { 8 registerCleanupFunction(async function () { 9 for (let win of windowsToClose) { 10 await BrowserTestUtils.closeWindow(win); 11 } 12 }); 13 14 let windowsToClose = []; 15 16 async function doTest(aIsPrivateMode) { 17 let newTabURL; 18 let mode; 19 let win = await BrowserTestUtils.openNewBrowserWindow({ 20 private: aIsPrivateMode, 21 }); 22 windowsToClose.push(win); 23 24 if (aIsPrivateMode) { 25 mode = "per window private browsing"; 26 newTabURL = "about:privatebrowsing"; 27 } else { 28 mode = "normal"; 29 newTabURL = "about:newtab"; 30 } 31 await openNewTab(win, newTabURL); 32 33 is( 34 win.gBrowser.currentURI.spec, 35 newTabURL, 36 "URL of NewTab should be " + newTabURL + " in " + mode + " mode" 37 ); 38 } 39 40 await doTest(false); 41 await doTest(true); 42 await doTest(false); 43 }); 44 45 async function openNewTab(aWindow, aExpectedURL) { 46 // Open a new tab 47 aWindow.BrowserCommands.openTab(); 48 let browser = aWindow.gBrowser.selectedBrowser; 49 50 // We're already loaded. 51 if (browser.currentURI.spec === aExpectedURL) { 52 return; 53 } 54 55 // Wait for any location change. 56 await BrowserTestUtils.waitForLocationChange(aWindow.gBrowser); 57 }