browser_bug767836_perwindowpb.js (2116B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 async function doTest(isPrivate) { 7 let win = await BrowserTestUtils.openNewBrowserWindow({ private: isPrivate }); 8 let defaultURL = AboutNewTab.newTabURL; 9 let newTabURL; 10 let mode; 11 let testURL = "https://example.com/"; 12 if (isPrivate) { 13 mode = "per window private browsing"; 14 newTabURL = "about:privatebrowsing"; 15 } else { 16 mode = "normal"; 17 newTabURL = "about:newtab"; 18 } 19 20 await openNewTab(win, newTabURL); 21 // Check the new tab opened while in normal/private mode 22 is( 23 win.gBrowser.selectedBrowser.currentURI.spec, 24 newTabURL, 25 "URL of NewTab should be " + newTabURL + " in " + mode + " mode" 26 ); 27 28 // Set the custom newtab url 29 AboutNewTab.newTabURL = testURL; 30 is(AboutNewTab.newTabURL, testURL, "Custom newtab url is set"); 31 32 // Open a newtab after setting the custom newtab url 33 await openNewTab(win, testURL); 34 is( 35 win.gBrowser.selectedBrowser.currentURI.spec, 36 testURL, 37 "URL of NewTab should be the custom url" 38 ); 39 40 // Clear the custom url. 41 AboutNewTab.resetNewTabURL(); 42 is(AboutNewTab.newTabURL, defaultURL, "No custom newtab url is set"); 43 44 win.gBrowser.removeTab(win.gBrowser.selectedTab); 45 win.gBrowser.removeTab(win.gBrowser.selectedTab); 46 await BrowserTestUtils.closeWindow(win); 47 } 48 49 add_task(async function test_newTabService() { 50 // check whether any custom new tab url has been configured 51 ok(!AboutNewTab.newTabURLOverridden, "No custom newtab url is set"); 52 53 // test normal mode 54 await doTest(false); 55 56 // test private mode 57 await doTest(true); 58 }); 59 60 async function openNewTab(aWindow, aExpectedURL) { 61 // Open a new tab 62 aWindow.BrowserCommands.openTab(); 63 let browser = aWindow.gBrowser.selectedBrowser; 64 65 // We're already loaded. 66 if (browser.currentURI.spec === aExpectedURL) { 67 return; 68 } 69 70 // Wait for any location change. 71 await BrowserTestUtils.waitForLocationChange(aWindow.gBrowser); 72 }