browser_privatebrowsing_transition.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  * Nochum Sossonko.
18  * Portions created by the Initial Developer are Copyright (C) 2009
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Nochum Sossonko <nsossonko@hotmail.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 // Tests the order of events and notifications when entering/exiting private
39 // browsing mode. This ensures that all private data is removed on exit, e.g.
40 // a cookie set in on unload handler, see bug 476463.
41 let cookieManager = Cc["@mozilla.org/cookiemanager;1"].
42  getService(Ci.nsICookieManager2);
43 let pb = Cc["@mozilla.org/privatebrowsing;1"].
44  getService(Ci.nsIPrivateBrowsingService);
45 let _obs = Cc["@mozilla.org/observer-service;1"].
46  getService(Ci.nsIObserverService);
48 
49 let pbObserver = {
50  observe: function(aSubject, aTopic, aData) {
51  if (aTopic == "private-browsing") {
52  switch(aData) {
53  case "enter":
55  is(observerNotified, 1, "This should be the first notification");
56  is(firstUnloadFired, 1, "The first unload event should have been processed by now");
57  break;
58  case "exit":
59  _obs.removeObserver(this, "private-browsing");
61  is(observerNotified, 2, "This should be the second notification");
62  is(secondUnloadFired, 1, "The second unload event should have been processed by now");
63  break;
64  }
65  }
66  }
67 }
68 function test() {
70  _obs.addObserver(pbObserver, "private-browsing", false);
71  is(gBrowser.tabContainer.childNodes.length, 1, "There should only be one tab");
72  let testTab = gBrowser.addTab();
73  gBrowser.selectedTab = testTab;
74  testTab.linkedBrowser.addEventListener("unload", (function() {
75  testTab.linkedBrowser.removeEventListener("unload", arguments.callee, true);
77  is(observerNotified, 0, "The notification shouldn't have been sent yet");
78  }), true);
79 
80  pb.privateBrowsingEnabled = true;
81  let testTab = gBrowser.addTab();
82  gBrowser.selectedTab = testTab;
83  testTab.linkedBrowser.addEventListener("unload", (function() {
84  testTab.linkedBrowser.removeEventListener("unload", arguments.callee, true);
86  is(observerNotified, 1, "The notification shouldn't have been sent yet");
87  cookieManager.add("example.com", "test/", "PB", "1", false, false, false, 1000000000000);
88  }), true);
89 
90  pb.privateBrowsingEnabled = false;
91  gBrowser.tabContainer.lastChild.linkedBrowser.addEventListener("unload", (function() {
92  gBrowser.tabContainer.lastChild.linkedBrowser.removeEventListener("unload", arguments.callee, true);
93  let count = cookieManager.countCookiesFromHost("example.com");
94  is(count, 0, "There shouldn't be any cookies once pb mode has exited");
95  cookieManager.QueryInterface(Ci.nsICookieManager);
96  cookieManager.remove("example.com", "PB", "test/", false);
97  }), true);
98  gBrowser.removeCurrentTab();
99  finish();
100 }
const Cc
getService(Ci.sbIFaceplateManager)
var count
Definition: test_bug7406.js:32
waitForExplicitFinish()
return!aWindow arguments!aWindow arguments[0]
const Ci
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe