browser_privatebrowsing_popupmode.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) 2009
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 URL bar is enabled after entering the private
39 // browsing mode, even if it's disabled before that (see bug 495495).
40 
41 function test() {
42  // initialization
43  let pb = Cc["@mozilla.org/privatebrowsing;1"].
44  getService(Ci.nsIPrivateBrowsingService);
45  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
46  getService(Ci.nsISessionStore);
47 
48  // backup our state
49  let stateBackup = ss.getWindowState(window);
50 
51  function pretendToBeAPopup(whatToPretend) {
52  let state = whatToPretend ?
53  '{"windows":[{"tabs":[{"entries":[],"attributes":{}}],"isPopup":true,"hidden":"toolbar"}]}' :
54  '{"windows":[{"tabs":[{"entries":[],"attributes":{}}],"isPopup":false}]}';
55  ss.setWindowState(window, state, true);
56  if (whatToPretend) {
57  ok(gURLBar.readOnly, "pretendToBeAPopup correctly made the URL bar read-only");
58  is(gURLBar.getAttribute("enablehistory"), "false",
59  "pretendToBeAPopup correctly disabled autocomplete on the URL bar");
60  }
61  else {
62  ok(!gURLBar.readOnly, "pretendToBeAPopup correctly made the URL bar read-write");
63  is(gURLBar.getAttribute("enablehistory"), "true",
64  "pretendToBeAPopup correctly enabled autocomplete on the URL bar");
65  }
66  }
67 
68  // first, test the case of entering the PB mode when a popup window is active
69 
70  // pretend we're a popup window
71  pretendToBeAPopup(true);
72 
73  // enter private browsing mode
74  pb.privateBrowsingEnabled = true;
75 
76  // make sure that the url bar status is correctly restored
77  ok(!gURLBar.readOnly,
78  "URL bar should not be read-only after entering the private browsing mode");
79  is(gURLBar.getAttribute("enablehistory"), "true",
80  "URL bar autocomplete should be enabled after entering the private browsing mode");
81 
82  // leave private browsing mode
83  pb.privateBrowsingEnabled = false;
84 
85  // we're no longer a popup window
86  pretendToBeAPopup(false);
87 
88  // then, test the case of leaving the PB mode when a popup window is active
89 
90  // start from within the private browsing mode
91  pb.privateBrowsingEnabled = true;
92 
93  // pretend we're a popup window
94  pretendToBeAPopup(true);
95 
96  // leave private browsing mode
97  pb.privateBrowsingEnabled = false;
98 
99  // make sure that the url bar status is correctly restored
100  ok(!gURLBar.readOnly,
101  "URL bar should not be read-only after leaving the private browsing mode");
102  is(gURLBar.getAttribute("enablehistory"), "true",
103  "URL bar autocomplete should be enabled after leaving the private browsing mode");
104 
105  // cleanup
106  ss.setWindowState(window, stateBackup, true);
107 }
const Cc
getService(Ci.sbIFaceplateManager)
let window
const Ci