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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug763468_perwindowpb.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     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
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +// This test makes sure that opening a new tab in private browsing mode opens about:privatebrowsing
     1.9 +function test() {
    1.10 +  // initialization
    1.11 +  waitForExplicitFinish();
    1.12 +  let windowsToClose = [];
    1.13 +  let newTab;
    1.14 +  let newTabPrefName = "browser.newtab.url";
    1.15 +  let newTabURL;
    1.16 +  let mode;
    1.17 +
    1.18 +  function doTest(aIsPrivateMode, aWindow, aCallback) {
    1.19 +    whenNewTabLoaded(aWindow, function () {
    1.20 +      if (aIsPrivateMode) {
    1.21 +        mode = "per window private browsing";
    1.22 +        newTabURL = "about:privatebrowsing";
    1.23 +      } else {
    1.24 +        mode = "normal";
    1.25 +        newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
    1.26 +      }
    1.27 +
    1.28 +      is(aWindow.gBrowser.currentURI.spec, newTabURL,
    1.29 +        "URL of NewTab should be " + newTabURL + " in " + mode +  " mode");
    1.30 +
    1.31 +      aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
    1.32 +      aCallback()
    1.33 +    });
    1.34 +  };
    1.35 +
    1.36 +  function testOnWindow(aOptions, aCallback) {
    1.37 +    whenNewWindowLoaded(aOptions, function(aWin) {
    1.38 +      windowsToClose.push(aWin);
    1.39 +      // execute should only be called when need, like when you are opening
    1.40 +      // web pages on the test. If calling executeSoon() is not necesary, then
    1.41 +      // call whenNewWindowLoaded() instead of testOnWindow() on your test.
    1.42 +      executeSoon(function() aCallback(aWin));
    1.43 +    });
    1.44 +  };
    1.45 +
    1.46 +   // this function is called after calling finish() on the test.
    1.47 +  registerCleanupFunction(function() {
    1.48 +    windowsToClose.forEach(function(aWin) {
    1.49 +      aWin.close();
    1.50 +    });
    1.51 +  });
    1.52 +
    1.53 +  // test first when not on private mode
    1.54 +  testOnWindow({}, function(aWin) {
    1.55 +    doTest(false, aWin, function() {
    1.56 +      // then test when on private mode
    1.57 +      testOnWindow({private: true}, function(aWin) {
    1.58 +        doTest(true, aWin, function() {
    1.59 +          // then test again when not on private mode
    1.60 +          testOnWindow({}, function(aWin) {
    1.61 +            doTest(false, aWin, finish);
    1.62 +          });
    1.63 +        });
    1.64 +      });
    1.65 +    });
    1.66 +  });
    1.67 +}

mercurial