browser_privatebrowsing_windowtitle.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Private Browsing Tests.
15  *
16  * The Initial Developer of the Original Code is
17  * Ehsan Akhgari.
18  * Portions created by the Initial Developer are Copyright (C) 2008
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either of the GNU General Public License Version 2 or later (the "GPL"),
26  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 // This test makes sure that the window title changes correctly while switching
39 // from and to private browsing mode.
40 
41 function test() {
42  // initialization
43  gPrefService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
44  let pb = Cc["@mozilla.org/privatebrowsing;1"].
45  getService(Ci.nsIPrivateBrowsingService);
46 
47  const testPageURL = "http://localhost:8888/browser/" +
48  "browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle_page.html";
50 
51  // initialization of expected titles
52  let test_title = "Test title";
53  let app_name = document.documentElement.getAttribute("title");
54  const isOSX = ("nsILocalFileMac" in Ci);
55  let page_with_title;
56  let page_without_title;
57  let about_pb_title;
58  let pb_page_with_title;
59  let pb_page_without_title;
60  let pb_about_pb_title;
61  if (isOSX) {
62  page_with_title = test_title;
63  page_without_title = app_name;
64  about_pb_title = "Would you like to start Private Browsing?";
65  pb_page_with_title = test_title + " - (Private Browsing)";
66  pb_page_without_title = app_name + " - (Private Browsing)";
67  pb_about_pb_title = pb_page_without_title;
68  }
69  else {
70  page_with_title = test_title + " - " + app_name;
71  page_without_title = app_name;
72  about_pb_title = "Would you like to start Private Browsing?" + " - " + app_name;
73  pb_page_with_title = test_title + " - " + app_name + " (Private Browsing)";
74  pb_page_without_title = app_name + " (Private Browsing)";
75  pb_about_pb_title = "Private Browsing - " + app_name + " (Private Browsing)";
76  }
77 
78  function testTabTitle(url, insidePB, expected_title, funcNext) {
79  pb.privateBrowsingEnabled = insidePB;
80 
81  let tab = gBrowser.selectedTab = gBrowser.addTab();
82  let browser = gBrowser.selectedBrowser;
83  browser.stop();
84  // ensure that the test is run after the titlebar has been updated
85  browser.addEventListener("pageshow", function () {
86  browser.removeEventListener("pageshow", arguments.callee, false);
87  executeSoon(function () {
88  is(document.title, expected_title, "The window title for " + url +
89  " is correct (" + (insidePB ? "inside" : "outside") +
90  " private browsing mode)");
91 
92  let win = gBrowser.replaceTabWithWindow(tab);
93  win.addEventListener("load", function() {
94  win.removeEventListener("load", arguments.callee, false);
95 
96  // ensure that the test is run after delayedStartup
97  let _delayedStartup = win.delayedStartup;
98  win.delayedStartup = function() {
99  _delayedStartup.apply(win, arguments);
100  win.delayedStartup = _delayedStartup;
101 
102  is(win.document.title, expected_title, "The window title for " + url +
103  " detached tab is correct (" + (insidePB ? "inside" : "outside") +
104  " private browsing mode)");
105  win.close();
106 
107  setTimeout(funcNext, 0);
108  };
109  }, false);
110  });
111  }, false);
112 
113  browser.loadURI(url);
114  }
115 
116  function cleanup() {
117  pb.privateBrowsingEnabled = false;
118  gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
119  finish();
120  }
121 
122  testTabTitle("about:blank", false, page_without_title, function() {
123  testTabTitle(testPageURL, false, page_with_title, function() {
124  testTabTitle("about:privatebrowsing", false, about_pb_title, function() {
125  testTabTitle("about:blank", true, pb_page_without_title, function() {
126  testTabTitle(testPageURL, true, pb_page_with_title, function() {
127  testTabTitle("about:privatebrowsing", true, pb_about_pb_title, cleanup);
128  });
129  });
130  });
131  });
132  });
133  return;
134 }
const Cc
var tab
getService(Ci.sbIFaceplateManager)
waitForExplicitFinish()
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function cleanup()
return!aWindow arguments!aWindow arguments[0]
var gPrefService
Definition: overlay.js:34
function url(spec)
const Ci
var browser
Definition: openLocation.js:42