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

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:522a9ad5171b
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/. */
4
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;
14
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 }
24
25 is(aWindow.gBrowser.currentURI.spec, newTabURL,
26 "URL of NewTab should be " + newTabURL + " in " + mode + " mode");
27
28 aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
29 aCallback()
30 });
31 };
32
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 };
42
43 // this function is called after calling finish() on the test.
44 registerCleanupFunction(function() {
45 windowsToClose.forEach(function(aWin) {
46 aWin.close();
47 });
48 });
49
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