1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug767836_perwindowpb.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test() { 1.9 + //initialization 1.10 + waitForExplicitFinish(); 1.11 + let newTabPrefName = "browser.newtab.url"; 1.12 + let newTabURL; 1.13 + let testURL = "http://example.com/"; 1.14 + let mode; 1.15 + 1.16 + function doTest(aIsPrivateMode, aWindow, aCallback) { 1.17 + openNewTab(aWindow, function () { 1.18 + if (aIsPrivateMode) { 1.19 + mode = "per window private browsing"; 1.20 + newTabURL = "about:privatebrowsing"; 1.21 + } else { 1.22 + mode = "normal"; 1.23 + newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank"; 1.24 + } 1.25 + 1.26 + // Check the new tab opened while in normal/private mode 1.27 + is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL, 1.28 + "URL of NewTab should be " + newTabURL + " in " + mode + " mode"); 1.29 + // Set the custom newtab url 1.30 + Services.prefs.setCharPref(newTabPrefName, testURL); 1.31 + ok(Services.prefs.prefHasUserValue(newTabPrefName), "Custom newtab url is set"); 1.32 + 1.33 + // Open a newtab after setting the custom newtab url 1.34 + openNewTab(aWindow, function () { 1.35 + is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL, 1.36 + "URL of NewTab should be the custom url"); 1.37 + 1.38 + // clear the custom url preference 1.39 + Services.prefs.clearUserPref(newTabPrefName); 1.40 + ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set"); 1.41 + 1.42 + aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab); 1.43 + aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab); 1.44 + aWindow.close(); 1.45 + aCallback() 1.46 + }); 1.47 + }); 1.48 + } 1.49 + 1.50 + function testOnWindow(aIsPrivate, aCallback) { 1.51 + whenNewWindowLoaded({private: aIsPrivate}, function(win) { 1.52 + executeSoon(function() aCallback(win)); 1.53 + }); 1.54 + } 1.55 + 1.56 + // check whether any custom new tab url has been configured 1.57 + ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set"); 1.58 + 1.59 + // test normal mode 1.60 + testOnWindow(false, function(aWindow) { 1.61 + doTest(false, aWindow, function() { 1.62 + // test private mode 1.63 + testOnWindow(true, function(aWindow) { 1.64 + doTest(true, aWindow, function() { 1.65 + finish(); 1.66 + }); 1.67 + }); 1.68 + }); 1.69 + }); 1.70 +} 1.71 + 1.72 +function openNewTab(aWindow, aCallback) { 1.73 + // Open a new tab 1.74 + aWindow.BrowserOpenTab(); 1.75 + 1.76 + let browser = aWindow.gBrowser.selectedBrowser; 1.77 + if (browser.contentDocument.readyState == "complete") { 1.78 + executeSoon(aCallback); 1.79 + return; 1.80 + } 1.81 + 1.82 + browser.addEventListener("load", function onLoad() { 1.83 + browser.removeEventListener("load", onLoad, true); 1.84 + executeSoon(aCallback); 1.85 + }, true); 1.86 +} 1.87 \ No newline at end of file