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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 // This test makes sure that opening a new tab in private browsing mode opens about:privatebrowsing
     6 function test() {
     7   // initialization
     8   waitForExplicitFinish();
     9   let windowsToClose = [];
    10   let newTab;
    11   let newTabPrefName = "browser.newtab.url";
    12   let newTabURL;
    13   let mode;
    15   function doTest(aIsPrivateMode, aWindow, aCallback) {
    16     whenNewTabLoaded(aWindow, function () {
    17       if (aIsPrivateMode) {
    18         mode = "per window private browsing";
    19         newTabURL = "about:privatebrowsing";
    20       } else {
    21         mode = "normal";
    22         newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
    23       }
    25       is(aWindow.gBrowser.currentURI.spec, newTabURL,
    26         "URL of NewTab should be " + newTabURL + " in " + mode +  " mode");
    28       aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
    29       aCallback()
    30     });
    31   };
    33   function testOnWindow(aOptions, aCallback) {
    34     whenNewWindowLoaded(aOptions, function(aWin) {
    35       windowsToClose.push(aWin);
    36       // execute should only be called when need, like when you are opening
    37       // web pages on the test. If calling executeSoon() is not necesary, then
    38       // call whenNewWindowLoaded() instead of testOnWindow() on your test.
    39       executeSoon(function() aCallback(aWin));
    40     });
    41   };
    43    // this function is called after calling finish() on the test.
    44   registerCleanupFunction(function() {
    45     windowsToClose.forEach(function(aWin) {
    46       aWin.close();
    47     });
    48   });
    50   // test first when not on private mode
    51   testOnWindow({}, function(aWin) {
    52     doTest(false, aWin, function() {
    53       // then test when on private mode
    54       testOnWindow({private: true}, function(aWin) {
    55         doTest(true, aWin, function() {
    56           // then test again when not on private mode
    57           testOnWindow({}, function(aWin) {
    58             doTest(false, aWin, finish);
    59           });
    60         });
    61       });
    62     });
    63   });
    64 }

mercurial