browser/base/content/test/general/browser_bug767836_perwindowpb.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function test() {
michael@0 6 //initialization
michael@0 7 waitForExplicitFinish();
michael@0 8 let newTabPrefName = "browser.newtab.url";
michael@0 9 let newTabURL;
michael@0 10 let testURL = "http://example.com/";
michael@0 11 let mode;
michael@0 12
michael@0 13 function doTest(aIsPrivateMode, aWindow, aCallback) {
michael@0 14 openNewTab(aWindow, function () {
michael@0 15 if (aIsPrivateMode) {
michael@0 16 mode = "per window private browsing";
michael@0 17 newTabURL = "about:privatebrowsing";
michael@0 18 } else {
michael@0 19 mode = "normal";
michael@0 20 newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
michael@0 21 }
michael@0 22
michael@0 23 // Check the new tab opened while in normal/private mode
michael@0 24 is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL,
michael@0 25 "URL of NewTab should be " + newTabURL + " in " + mode + " mode");
michael@0 26 // Set the custom newtab url
michael@0 27 Services.prefs.setCharPref(newTabPrefName, testURL);
michael@0 28 ok(Services.prefs.prefHasUserValue(newTabPrefName), "Custom newtab url is set");
michael@0 29
michael@0 30 // Open a newtab after setting the custom newtab url
michael@0 31 openNewTab(aWindow, function () {
michael@0 32 is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL,
michael@0 33 "URL of NewTab should be the custom url");
michael@0 34
michael@0 35 // clear the custom url preference
michael@0 36 Services.prefs.clearUserPref(newTabPrefName);
michael@0 37 ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
michael@0 38
michael@0 39 aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
michael@0 40 aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
michael@0 41 aWindow.close();
michael@0 42 aCallback()
michael@0 43 });
michael@0 44 });
michael@0 45 }
michael@0 46
michael@0 47 function testOnWindow(aIsPrivate, aCallback) {
michael@0 48 whenNewWindowLoaded({private: aIsPrivate}, function(win) {
michael@0 49 executeSoon(function() aCallback(win));
michael@0 50 });
michael@0 51 }
michael@0 52
michael@0 53 // check whether any custom new tab url has been configured
michael@0 54 ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
michael@0 55
michael@0 56 // test normal mode
michael@0 57 testOnWindow(false, function(aWindow) {
michael@0 58 doTest(false, aWindow, function() {
michael@0 59 // test private mode
michael@0 60 testOnWindow(true, function(aWindow) {
michael@0 61 doTest(true, aWindow, function() {
michael@0 62 finish();
michael@0 63 });
michael@0 64 });
michael@0 65 });
michael@0 66 });
michael@0 67 }
michael@0 68
michael@0 69 function openNewTab(aWindow, aCallback) {
michael@0 70 // Open a new tab
michael@0 71 aWindow.BrowserOpenTab();
michael@0 72
michael@0 73 let browser = aWindow.gBrowser.selectedBrowser;
michael@0 74 if (browser.contentDocument.readyState == "complete") {
michael@0 75 executeSoon(aCallback);
michael@0 76 return;
michael@0 77 }
michael@0 78
michael@0 79 browser.addEventListener("load", function onLoad() {
michael@0 80 browser.removeEventListener("load", onLoad, true);
michael@0 81 executeSoon(aCallback);
michael@0 82 }, true);
michael@0 83 }

mercurial