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.

     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/. */
     5 function test() {
     6   //initialization
     7   waitForExplicitFinish();
     8   let newTabPrefName = "browser.newtab.url";
     9   let newTabURL;
    10   let testURL = "http://example.com/";
    11   let mode;
    13   function doTest(aIsPrivateMode, aWindow, aCallback) {
    14     openNewTab(aWindow, function () {
    15       if (aIsPrivateMode) {
    16         mode = "per window private browsing";
    17         newTabURL = "about:privatebrowsing";
    18       } else {
    19         mode = "normal";
    20         newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
    21       }
    23       // Check the new tab opened while in normal/private mode
    24       is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL,
    25         "URL of NewTab should be " + newTabURL + " in " + mode +  " mode");
    26       // Set the custom newtab url
    27       Services.prefs.setCharPref(newTabPrefName, testURL);
    28       ok(Services.prefs.prefHasUserValue(newTabPrefName), "Custom newtab url is set");
    30       // Open a newtab after setting the custom newtab url
    31       openNewTab(aWindow, function () {
    32         is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL,
    33            "URL of NewTab should be the custom url");
    35         // clear the custom url preference
    36         Services.prefs.clearUserPref(newTabPrefName);
    37         ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
    39         aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
    40         aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
    41         aWindow.close();
    42         aCallback()
    43       });
    44     });
    45   }
    47   function testOnWindow(aIsPrivate, aCallback) {
    48     whenNewWindowLoaded({private: aIsPrivate}, function(win) {
    49       executeSoon(function() aCallback(win));
    50     });
    51   }
    53   // check whether any custom new tab url has been configured
    54   ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
    56   // test normal mode
    57   testOnWindow(false, function(aWindow) {
    58     doTest(false, aWindow, function() {
    59       // test private mode
    60       testOnWindow(true, function(aWindow) {
    61         doTest(true, aWindow, function() {
    62           finish();
    63         });
    64       });
    65     });
    66   });
    67 }
    69 function openNewTab(aWindow, aCallback) {
    70   // Open a new tab
    71   aWindow.BrowserOpenTab();
    73   let browser = aWindow.gBrowser.selectedBrowser;
    74   if (browser.contentDocument.readyState == "complete") {
    75     executeSoon(aCallback);
    76     return;
    77   }
    79   browser.addEventListener("load", function onLoad() {
    80     browser.removeEventListener("load", onLoad, true);
    81     executeSoon(aCallback);
    82   }, true);
    83 }

mercurial