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 file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: //initialization michael@0: waitForExplicitFinish(); michael@0: let newTabPrefName = "browser.newtab.url"; michael@0: let newTabURL; michael@0: let testURL = "http://example.com/"; michael@0: let mode; michael@0: michael@0: function doTest(aIsPrivateMode, aWindow, aCallback) { michael@0: openNewTab(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: // Check the new tab opened while in normal/private mode michael@0: is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL, michael@0: "URL of NewTab should be " + newTabURL + " in " + mode + " mode"); michael@0: // Set the custom newtab url michael@0: Services.prefs.setCharPref(newTabPrefName, testURL); michael@0: ok(Services.prefs.prefHasUserValue(newTabPrefName), "Custom newtab url is set"); michael@0: michael@0: // Open a newtab after setting the custom newtab url michael@0: openNewTab(aWindow, function () { michael@0: is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL, michael@0: "URL of NewTab should be the custom url"); michael@0: michael@0: // clear the custom url preference michael@0: Services.prefs.clearUserPref(newTabPrefName); michael@0: ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set"); michael@0: michael@0: aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab); michael@0: aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab); michael@0: aWindow.close(); michael@0: aCallback() michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function testOnWindow(aIsPrivate, aCallback) { michael@0: whenNewWindowLoaded({private: aIsPrivate}, function(win) { michael@0: executeSoon(function() aCallback(win)); michael@0: }); michael@0: } michael@0: michael@0: // check whether any custom new tab url has been configured michael@0: ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set"); michael@0: michael@0: // test normal mode michael@0: testOnWindow(false, function(aWindow) { michael@0: doTest(false, aWindow, function() { michael@0: // test private mode michael@0: testOnWindow(true, function(aWindow) { michael@0: doTest(true, aWindow, function() { michael@0: finish(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function openNewTab(aWindow, aCallback) { michael@0: // Open a new tab michael@0: aWindow.BrowserOpenTab(); michael@0: michael@0: let browser = aWindow.gBrowser.selectedBrowser; michael@0: if (browser.contentDocument.readyState == "complete") { michael@0: executeSoon(aCallback); michael@0: return; michael@0: } michael@0: michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: executeSoon(aCallback); michael@0: }, true); michael@0: }