michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This test makes sure that opening a new tab in private browsing mode opens about:privatebrowsing michael@0: function test() { michael@0: // initialization michael@0: waitForExplicitFinish(); michael@0: let windowsToClose = []; michael@0: let newTab; michael@0: let newTabPrefName = "browser.newtab.url"; michael@0: let newTabURL; michael@0: let mode; michael@0: michael@0: function doTest(aIsPrivateMode, aWindow, aCallback) { michael@0: whenNewTabLoaded(aWindow, function () { michael@0: if (aIsPrivateMode) { michael@0: mode = "per window private browsing"; michael@0: newTabURL = "about:privatebrowsing"; michael@0: } else { michael@0: mode = "normal"; michael@0: newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank"; michael@0: } michael@0: michael@0: is(aWindow.gBrowser.currentURI.spec, newTabURL, michael@0: "URL of NewTab should be " + newTabURL + " in " + mode + " mode"); michael@0: michael@0: aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab); michael@0: aCallback() michael@0: }); michael@0: }; michael@0: michael@0: function testOnWindow(aOptions, aCallback) { michael@0: whenNewWindowLoaded(aOptions, function(aWin) { michael@0: windowsToClose.push(aWin); michael@0: // execute should only be called when need, like when you are opening michael@0: // web pages on the test. If calling executeSoon() is not necesary, then michael@0: // call whenNewWindowLoaded() instead of testOnWindow() on your test. michael@0: executeSoon(function() aCallback(aWin)); michael@0: }); michael@0: }; michael@0: michael@0: // this function is called after calling finish() on the test. michael@0: registerCleanupFunction(function() { michael@0: windowsToClose.forEach(function(aWin) { michael@0: aWin.close(); michael@0: }); michael@0: }); michael@0: michael@0: // test first when not on private mode michael@0: testOnWindow({}, function(aWin) { michael@0: doTest(false, aWin, function() { michael@0: // then test when on private mode michael@0: testOnWindow({private: true}, function(aWin) { michael@0: doTest(true, aWin, function() { michael@0: // then test again when not on private mode michael@0: testOnWindow({}, function(aWin) { michael@0: doTest(false, aWin, finish); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }