Bug 568816 - Switching out of privacy mode fails when privacy mode is enabled via the command line option 'privacy-toggle'; r=zpao,dolske sr=rstrong a=blocking-beta7+

--HG--
rename : browser/components/privatebrowsing/test/unit/test_0-privatebrowsing.js => browser/components/privatebrowsing/test/unit/do_test_0-privatebrowsing.js
rename : browser/components/privatebrowsing/test/unit/test_0-privatebrowsing.js => browser/components/privatebrowsing/test/unit/test_0-privatebrowsingwrapper.js
This commit is contained in:
Ehsan Akhgari 2010-10-02 11:53:37 -04:00
Родитель 0ce8b5f67c
Коммит 2dfddfcc1a
14 изменённых файлов: 411 добавлений и 233 удалений

Просмотреть файл

@ -531,8 +531,7 @@ nsBrowserContentHandler.prototype = {
}
if (cmdLine.handleFlag("silent", false))
cmdLine.preventDefault = true;
if (cmdLine.findFlag("private-toggle", false) >= 0 &&
cmdLine.state != cmdLine.STATE_INITIAL_LAUNCH)
if (cmdLine.findFlag("private-toggle", false) >= 0)
cmdLine.preventDefault = true;
var searchParam = cmdLine.handleFlagWithParam("search", false);

Просмотреть файл

@ -165,6 +165,10 @@ BrowserGlue.prototype = {
case "final-ui-startup":
this._onProfileStartup();
break;
case "browser-delayed-startup-finished":
this._onFirstWindowLoaded();
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
break;
case "sessionstore-windows-restored":
this._onBrowserStartup();
break;
@ -260,6 +264,7 @@ BrowserGlue.prototype = {
os.addObserver(this, "xpcom-shutdown", false);
os.addObserver(this, "prefservice:after-app-defaults", false);
os.addObserver(this, "final-ui-startup", false);
os.addObserver(this, "browser-delayed-startup-finished", false);
os.addObserver(this, "sessionstore-windows-restored", false);
os.addObserver(this, "browser:purge-session-history", false);
os.addObserver(this, "quit-application-requested", false);
@ -347,6 +352,22 @@ BrowserGlue.prototype = {
Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
},
// the first browser window has finished initializing
_onFirstWindowLoaded: function BG__onFirstWindowLoaded() {
#ifdef XP_WIN
#ifndef WINCE
// For windows seven, initialize the jump list module.
const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
if (WINTASKBAR_CONTRACTID in Cc &&
Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
let temp = {};
Cu.import("resource://gre/modules/WindowsJumpLists.jsm", temp);
temp.WinTaskbarJumpList.startup();
}
#endif
#endif
},
// profile shutdown handler (contains profile cleanup routines)
_onProfileShutdown: function BG__onProfileShutdown() {
#ifdef MOZ_UPDATER
@ -408,19 +429,6 @@ BrowserGlue.prototype = {
// been warned about them yet, open the plugins update page.
if (Services.prefs.getBoolPref(PREF_PLUGINS_NOTIFYUSER))
this._showPluginUpdatePage();
#ifdef XP_WIN
#ifndef WINCE
// For windows seven, initialize the jump list module.
const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
if (WINTASKBAR_CONTRACTID in Cc &&
Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
let temp = {};
Cu.import("resource://gre/modules/WindowsJumpLists.jsm", temp);
temp.WinTaskbarJumpList.startup();
}
#endif
#endif
},
_onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {

Просмотреть файл

@ -129,6 +129,9 @@ PrivateBrowsingService.prototype = {
// List of nsIXULWindows we are going to be closing during the transition
_windowsToClose: [],
// Whether private browsing has been turned on from the command line
_lastChangedByCommandLine: false,
// XPCOM registration
classID: Components.ID("{c31f4883-839b-45f6-82ad-a6a9bc5ad599}"),
@ -231,6 +234,9 @@ PrivateBrowsingService.prototype = {
// to be restored, do it now
if (!this._inPrivateBrowsing) {
this._currentStatus = STATE_WAITING_FOR_RESTORE;
if (!this._getBrowserWindow()) {
ss.init(null);
}
ss.setBrowserState(this._savedBrowserState);
this._savedBrowserState = null;
@ -273,6 +279,9 @@ PrivateBrowsingService.prototype = {
};
// Transition into private browsing mode
this._currentStatus = STATE_WAITING_FOR_RESTORE;
if (!this._getBrowserWindow()) {
ss.init(null);
}
ss.setBrowserState(JSON.stringify(privateBrowsingState));
}
}
@ -439,6 +448,10 @@ PrivateBrowsingService.prototype = {
if (aSubject.findFlag("private", false) >= 0) {
this.privateBrowsingEnabled = true;
this._autoStarted = true;
this._lastChangedByCommandLine = true;
}
else if (aSubject.findFlag("private-toggle", false) >= 0) {
this._lastChangedByCommandLine = true;
}
break;
case "sessionstore-browser-state-restored":
@ -458,6 +471,7 @@ PrivateBrowsingService.prototype = {
else if (aCmdLine.handleFlag("private-toggle", false)) {
this.privateBrowsingEnabled = !this.privateBrowsingEnabled;
this._autoStarted = false;
this._lastChangedByCommandLine = true;
}
},
@ -534,6 +548,7 @@ PrivateBrowsingService.prototype = {
} finally {
this._windowsToClose = [];
this._notifyIfTransitionComplete();
this._lastChangedByCommandLine = false;
}
},
@ -544,6 +559,13 @@ PrivateBrowsingService.prototype = {
return this._inPrivateBrowsing && this._autoStarted;
},
/**
* Whether the latest transition was initiated from the command line.
*/
get lastChangedByCommandLine() {
return this._lastChangedByCommandLine;
},
removeDataFromDomain: function PBS_removeDataFromDomain(aDomain)
{

Просмотреть файл

@ -106,6 +106,15 @@ nsPrivateBrowsingServiceWrapper::GetAutoStarted(PRBool *aAutoStarted)
return mPBService->GetAutoStarted(aAutoStarted);
}
NS_IMETHODIMP
nsPrivateBrowsingServiceWrapper::GetLastChangedByCommandLine(PRBool *aReason)
{
if (!aReason)
return NS_ERROR_NULL_POINTER;
JSStackGuard guard;
return mPBService->GetLastChangedByCommandLine(aReason);
}
NS_IMETHODIMP
nsPrivateBrowsingServiceWrapper::RemoveDataFromDomain(const nsACString & aDomain)
{

Просмотреть файл

@ -128,6 +128,8 @@ function test() {
is(browser.contentWindow.location, "about:", "The correct page has been loaded");
simulatePrivateCommandLineArgument();
is(pb.lastChangedByCommandLine, true,
"The status change reason should reflect the PB mode being set from the command line");
tab = gBrowser.selectedTab;
browser = gBrowser.getBrowserForTab(tab);
browser.addEventListener("load", function() {
@ -137,6 +139,8 @@ function test() {
"about:privatebrowsing should now be loaded");
simulatePrivateCommandLineArgument();
is(pb.lastChangedByCommandLine, true,
"The status change reason should reflect the PB mode being set from the command line");
tab = gBrowser.selectedTab;
browser = gBrowser.getBrowserForTab(tab);
browser.addEventListener("load", function() {

Просмотреть файл

@ -0,0 +1,250 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Private Browsing Tests.
*
* The Initial Developer of the Original Code is
* Ehsan Akhgari.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// This tests the private browsing service to make sure it implements its
// documented interface correctly.
// This test should run before the rest of private browsing service unit tests,
// hence the naming used for this file.
function do_test() {
// initialization
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
// the contract ID should be available
do_check_true(PRIVATEBROWSING_CONTRACT_ID in Cc);
// the interface should be available
do_check_true("nsIPrivateBrowsingService" in Ci);
// it should be possible to initialize the component
try {
var pb = Cc[PRIVATEBROWSING_CONTRACT_ID].
getService(Ci.nsIPrivateBrowsingService);
} catch (ex) {
LOG("exception thrown when trying to get the service: " + ex);
do_throw("private browsing service could not be initialized");
}
// private browsing should be turned off initially
do_check_false(pb.privateBrowsingEnabled);
// private browsing not auto-started
do_check_false(pb.autoStarted);
// and the status should have never been changed
do_check_eq(pb.lastChangedByCommandLine, false);
// it should be possible to toggle its status
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled);
do_check_false(pb.autoStarted);
do_check_eq(pb.lastChangedByCommandLine, false);
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled);
do_check_false(pb.autoStarted);
do_check_eq(pb.lastChangedByCommandLine, false);
// test the private-browsing notification
var observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == kPrivateBrowsingNotification)
this.data = aData;
},
data: null
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_eq(observer.data, kEnter);
pb.privateBrowsingEnabled = false;
do_check_eq(observer.data, kExit);
os.removeObserver(observer, kPrivateBrowsingNotification);
// make sure that setting the private browsing mode from within an observer throws
observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == kPrivateBrowsingNotification) {
try {
pb.privateBrowsingEnabled = (aData == kEnter);
do_throw("Setting privateBrowsingEnabled inside the " + aData +
" notification should throw");
} catch (ex) {
if (!("result" in ex && ex.result == Cr.NS_ERROR_FAILURE))
do_throw("Unexpected exception caught: " + ex);
}
}
}
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled); // the exception should not interfere with the mode change
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled); // the exception should not interfere with the mode change
os.removeObserver(observer, kPrivateBrowsingNotification);
// make sure that getting the private browsing mode from within an observer doesn't throw
observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == kPrivateBrowsingNotification) {
try {
var dummy = pb.privateBrowsingEnabled;
if (aData == kEnter)
do_check_true(dummy);
else if (aData == kExit)
do_check_false(dummy);
} catch (ex) {
do_throw("Unexpected exception caught: " + ex);
}
}
}
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled); // just a sanity check
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled); // just a sanity check
os.removeObserver(observer, kPrivateBrowsingNotification);
// check that the private-browsing-cancel-vote notification is sent before the
// private-browsing notification
observer = {
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case kPrivateBrowsingCancelVoteNotification:
case kPrivateBrowsingNotification:
this.notifications.push(aTopic + " " + aData);
}
},
notifications: []
};
os.addObserver(observer, kPrivateBrowsingCancelVoteNotification, false);
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled); // just a sanity check
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled); // just a sanity check
os.removeObserver(observer, kPrivateBrowsingNotification);
os.removeObserver(observer, kPrivateBrowsingCancelVoteNotification);
var reference_order = [
kPrivateBrowsingCancelVoteNotification + " " + kEnter,
kPrivateBrowsingNotification + " " + kEnter,
kPrivateBrowsingCancelVoteNotification + " " + kExit,
kPrivateBrowsingNotification + " " + kExit
];
do_check_eq(observer.notifications.join(","), reference_order.join(","));
// make sure that the private-browsing-cancel-vote notification can be used
// to cancel the mode switch
observer = {
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case kPrivateBrowsingCancelVoteNotification:
do_check_neq(aSubject, null);
try {
aSubject.QueryInterface(Ci.nsISupportsPRBool);
} catch (ex) {
do_throw("aSubject in " + kPrivateBrowsingCancelVoteNotification +
" should implement nsISupportsPRBool");
}
do_check_false(aSubject.data);
aSubject.data = true; // cancel the mode switch
// fall through
case kPrivateBrowsingNotification:
this.notifications.push(aTopic + " " + aData);
}
},
nextPhase: function() {
this.notifications.push("enter phase " + (++this._phase));
},
notifications: [],
_phase: 0
};
os.addObserver(observer, kPrivateBrowsingCancelVoteNotification, false);
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_false(pb.privateBrowsingEnabled); // should have been canceled
// temporarily disable the observer
os.removeObserver(observer, kPrivateBrowsingCancelVoteNotification);
observer.nextPhase();
pb.privateBrowsingEnabled = true; // this time, should enter successfully
do_check_true(pb.privateBrowsingEnabled); // should have been canceled
// re-enable the observer
os.addObserver(observer, kPrivateBrowsingCancelVoteNotification, false);
pb.privateBrowsingEnabled = false;
do_check_true(pb.privateBrowsingEnabled); // should have been canceled
os.removeObserver(observer, kPrivateBrowsingCancelVoteNotification);
observer.nextPhase();
pb.privateBrowsingEnabled = false; // this time, should exit successfully
do_check_false(pb.privateBrowsingEnabled);
os.removeObserver(observer, kPrivateBrowsingNotification);
reference_order = [
kPrivateBrowsingCancelVoteNotification + " " + kEnter,
"enter phase 1",
kPrivateBrowsingNotification + " " + kEnter,
kPrivateBrowsingCancelVoteNotification + " " + kExit,
"enter phase 2",
kPrivateBrowsingNotification + " " + kExit,
];
do_check_eq(observer.notifications.join(","), reference_order.join(","));
// make sure that the private browsing transition complete notification is
// raised correctly.
observer = {
observe: function(aSubject, aTopic, aData) {
this.notifications.push(aTopic + " " + aData);
},
notifications: []
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
os.addObserver(observer, kPrivateBrowsingTransitionCompleteNotification, false);
pb.privateBrowsingEnabled = true;
pb.privateBrowsingEnabled = false;
os.removeObserver(observer, kPrivateBrowsingNotification);
os.removeObserver(observer, kPrivateBrowsingTransitionCompleteNotification);
reference_order = [
kPrivateBrowsingNotification + " " + kEnter,
kPrivateBrowsingTransitionCompleteNotification + " ",
kPrivateBrowsingNotification + " " + kExit,
kPrivateBrowsingTransitionCompleteNotification + " ",
];
do_check_eq(observer.notifications.join(","), reference_order.join(","));
}
// Support running tests on both the service itself and its wrapper
function run_test() {
run_test_on_all_services();
}

Просмотреть файл

@ -118,4 +118,6 @@ function do_test() {
do_check_true(pb.privateBrowsingEnabled);
// and should appear as auto-started!
do_check_true(pb.autoStarted);
// and should be coming from the command line!
do_check_eq(pb.lastChangedByCommandLine, true);
}

Просмотреть файл

@ -38,209 +38,8 @@
// This tests the private browsing service to make sure it implements its
// documented interface correctly.
// This test should run before the rest of private browsing service unit tests,
// hence the naming used for this file.
function run_test_on_service() {
// initialization
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
// the contract ID should be available
do_check_true(PRIVATEBROWSING_CONTRACT_ID in Cc);
// the interface should be available
do_check_true("nsIPrivateBrowsingService" in Ci);
// it should be possible to initialize the component
try {
var pb = Cc[PRIVATEBROWSING_CONTRACT_ID].
getService(Ci.nsIPrivateBrowsingService);
} catch (ex) {
LOG("exception thrown when trying to get the service: " + ex);
do_throw("private browsing service could not be initialized");
}
// private browsing should be turned off initially
do_check_false(pb.privateBrowsingEnabled);
// private browsing not auto-started
do_check_false(pb.autoStarted);
// it should be possible to toggle its status
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled);
do_check_false(pb.autoStarted);
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled);
do_check_false(pb.autoStarted);
// test the private-browsing notification
var observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == kPrivateBrowsingNotification)
this.data = aData;
},
data: null
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_eq(observer.data, kEnter);
pb.privateBrowsingEnabled = false;
do_check_eq(observer.data, kExit);
os.removeObserver(observer, kPrivateBrowsingNotification);
// make sure that setting the private browsing mode from within an observer throws
observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == kPrivateBrowsingNotification) {
try {
pb.privateBrowsingEnabled = (aData == kEnter);
do_throw("Setting privateBrowsingEnabled inside the " + aData +
" notification should throw");
} catch (ex) {
if (!("result" in ex && ex.result == Cr.NS_ERROR_FAILURE))
do_throw("Unexpected exception caught: " + ex);
}
}
}
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled); // the exception should not interfere with the mode change
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled); // the exception should not interfere with the mode change
os.removeObserver(observer, kPrivateBrowsingNotification);
// make sure that getting the private browsing mode from within an observer doesn't throw
observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == kPrivateBrowsingNotification) {
try {
var dummy = pb.privateBrowsingEnabled;
if (aData == kEnter)
do_check_true(dummy);
else if (aData == kExit)
do_check_false(dummy);
} catch (ex) {
do_throw("Unexpected exception caught: " + ex);
}
}
}
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled); // just a sanity check
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled); // just a sanity check
os.removeObserver(observer, kPrivateBrowsingNotification);
// check that the private-browsing-cancel-vote notification is sent before the
// private-browsing notification
observer = {
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case kPrivateBrowsingCancelVoteNotification:
case kPrivateBrowsingNotification:
this.notifications.push(aTopic + " " + aData);
}
},
notifications: []
};
os.addObserver(observer, kPrivateBrowsingCancelVoteNotification, false);
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_true(pb.privateBrowsingEnabled); // just a sanity check
pb.privateBrowsingEnabled = false;
do_check_false(pb.privateBrowsingEnabled); // just a sanity check
os.removeObserver(observer, kPrivateBrowsingNotification);
os.removeObserver(observer, kPrivateBrowsingCancelVoteNotification);
var reference_order = [
kPrivateBrowsingCancelVoteNotification + " " + kEnter,
kPrivateBrowsingNotification + " " + kEnter,
kPrivateBrowsingCancelVoteNotification + " " + kExit,
kPrivateBrowsingNotification + " " + kExit
];
do_check_eq(observer.notifications.join(","), reference_order.join(","));
// make sure that the private-browsing-cancel-vote notification can be used
// to cancel the mode switch
observer = {
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case kPrivateBrowsingCancelVoteNotification:
do_check_neq(aSubject, null);
try {
aSubject.QueryInterface(Ci.nsISupportsPRBool);
} catch (ex) {
do_throw("aSubject in " + kPrivateBrowsingCancelVoteNotification +
" should implement nsISupportsPRBool");
}
do_check_false(aSubject.data);
aSubject.data = true; // cancel the mode switch
// fall through
case kPrivateBrowsingNotification:
this.notifications.push(aTopic + " " + aData);
}
},
nextPhase: function() {
this.notifications.push("enter phase " + (++this._phase));
},
notifications: [],
_phase: 0
};
os.addObserver(observer, kPrivateBrowsingCancelVoteNotification, false);
os.addObserver(observer, kPrivateBrowsingNotification, false);
pb.privateBrowsingEnabled = true;
do_check_false(pb.privateBrowsingEnabled); // should have been canceled
// temporarily disable the observer
os.removeObserver(observer, kPrivateBrowsingCancelVoteNotification);
observer.nextPhase();
pb.privateBrowsingEnabled = true; // this time, should enter successfully
do_check_true(pb.privateBrowsingEnabled); // should have been canceled
// re-enable the observer
os.addObserver(observer, kPrivateBrowsingCancelVoteNotification, false);
pb.privateBrowsingEnabled = false;
do_check_true(pb.privateBrowsingEnabled); // should have been canceled
os.removeObserver(observer, kPrivateBrowsingCancelVoteNotification);
observer.nextPhase();
pb.privateBrowsingEnabled = false; // this time, should exit successfully
do_check_false(pb.privateBrowsingEnabled);
os.removeObserver(observer, kPrivateBrowsingNotification);
reference_order = [
kPrivateBrowsingCancelVoteNotification + " " + kEnter,
"enter phase 1",
kPrivateBrowsingNotification + " " + kEnter,
kPrivateBrowsingCancelVoteNotification + " " + kExit,
"enter phase 2",
kPrivateBrowsingNotification + " " + kExit,
];
do_check_eq(observer.notifications.join(","), reference_order.join(","));
// make sure that the private browsing transition complete notification is
// raised correctly.
observer = {
observe: function(aSubject, aTopic, aData) {
this.notifications.push(aTopic + " " + aData);
},
notifications: []
};
os.addObserver(observer, kPrivateBrowsingNotification, false);
os.addObserver(observer, kPrivateBrowsingTransitionCompleteNotification, false);
pb.privateBrowsingEnabled = true;
pb.privateBrowsingEnabled = false;
os.removeObserver(observer, kPrivateBrowsingNotification);
os.removeObserver(observer, kPrivateBrowsingTransitionCompleteNotification);
reference_order = [
kPrivateBrowsingNotification + " " + kEnter,
kPrivateBrowsingTransitionCompleteNotification + " ",
kPrivateBrowsingNotification + " " + kExit,
kPrivateBrowsingTransitionCompleteNotification + " ",
];
do_check_eq(observer.notifications.join(","), reference_order.join(","));
}
// Support running tests on both the service itself and its wrapper
function run_test() {
run_test_on_all_services();
PRIVATEBROWSING_CONTRACT_ID = "@mozilla.org/privatebrowsing;1";
load("do_test_0-privatebrowsing.js");
do_test();
}

Просмотреть файл

@ -0,0 +1,45 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Private Browsing Tests.
*
* The Initial Developer of the Original Code is
* Ehsan Akhgari.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// This tests the private browsing service to make sure it implements its
// documented interface correctly.
function run_test() {
PRIVATEBROWSING_CONTRACT_ID = "@mozilla.org/privatebrowsing-wrapper;1";
load("do_test_0-privatebrowsing.js");
do_test();
}

Просмотреть файл

@ -101,7 +101,7 @@ SessionStartup.prototype = {
// do not need to initialize anything in auto-started private browsing sessions
let pbs = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
if (pbs.autoStarted)
if (pbs.autoStarted || pbs.lastChangedByCommandLine)
return;
let prefBranch = Cc["@mozilla.org/preferences-service;1"].
@ -237,7 +237,12 @@ SessionStartup.prototype = {
aWindow.arguments[0] == defaultArgs)
aWindow.arguments[0] = null;
Services.obs.removeObserver(this, "domwindowopened");
try {
Services.obs.removeObserver(this, "domwindowopened");
} catch (e) {
// This might throw if we're removing the observer multiple times,
// but this is safe to ignore.
}
},
/* ........ Public API ................*/

Просмотреть файл

@ -214,6 +214,9 @@ SessionStoreService.prototype = {
// The state from the previous session (after restoring pinned tabs)
_lastSessionState: null,
// Whether we've been initialized
_initialized: false,
/* ........ Public Getters .............. */
get canRestoreLastSession() {
@ -233,15 +236,7 @@ SessionStoreService.prototype = {
/**
* Initialize the component
*/
init: function sss_init(aWindow) {
if (!aWindow || this._loadState == STATE_RUNNING) {
// make sure that all browser windows which try to initialize
// SessionStore are really tracked by it
if (aWindow && (!aWindow.__SSi || !this._windows[aWindow.__SSi]))
this.onLoad(aWindow);
return;
}
initService: function() {
this._prefBranch = Services.prefs.getBranch("browser.");
this._prefBranch.QueryInterface(Ci.nsIPrefBranch2);
@ -353,7 +348,35 @@ SessionStoreService.prototype = {
if (this._loadState != STATE_QUITTING &&
this._prefBranch.getBoolPref("sessionstore.resume_session_once"))
this._prefBranch.setBoolPref("sessionstore.resume_session_once", false);
this._initialized = true;
},
/**
* Start tracking a window.
* Important note: despite its name, this function doesn't initialize
* the component!
*/
init: function sss_init(aWindow) {
if (!aWindow || this._loadState == STATE_RUNNING) {
// make sure that all browser windows which try to initialize
// SessionStore are really tracked by it
if (aWindow && (!aWindow.__SSi || !this._windows[aWindow.__SSi]))
this.onLoad(aWindow);
// If init is being called with a null window, it's possible that we
// just want to tell sessionstore that a session is live (as is the case
// with starting Firefox with -private, for example; see bug 568816),
// so we should mark the load state as running to make sure that
// things like setBrowserState calls will succeed in restoring the session.
if (!aWindow && this._loadState == STATE_STOPPED)
this._loadState = STATE_RUNNING;
return;
}
// Initialize the service if needed.
if (!this._initialized)
this.initService();
// As this is called at delayedStartup, restoration must be initiated here
this.onLoad(aWindow);
},

Просмотреть файл

@ -150,7 +150,7 @@ var tasksCfg = [
close: false, // no point
},
// Privacy mode
// Toggle the Private Browsing mode
{
get title() {
if (_privateBrowsingSvc.privateBrowsingEnabled)
@ -205,6 +205,10 @@ var WinTaskbarJumpList =
// jump list refresh timer
this._initTimer();
// Do an immediate update
Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer)
.initWithCallback(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
},
update: function WTBJL_update() {

Просмотреть файл

@ -31,6 +31,8 @@ function run_test() {
// if private browsing is available
if (pb) {
prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
// enter private browsing mode
pb.privateBrowsingEnabled = true;
@ -44,6 +46,8 @@ function run_test() {
// add a test cookie
cs.setCookieString(uri, null, "foobaz=bar", null);
do_check_eq(cs.countCookiesFromHost("foo.bar"), 2);
prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
}
}

Просмотреть файл

@ -37,7 +37,7 @@
#include "nsISupports.idl"
[scriptable, uuid(49d6f133-80c0-48c7-876d-0b70bbfd0289)]
[scriptable, uuid(4b731983-9542-49f4-b16b-de68ad1c2068)]
interface nsIPrivateBrowsingService : nsISupports
{
// When read, determines whether the private browsing mode is currently
@ -52,6 +52,10 @@ interface nsIPrivateBrowsingService : nsISupports
// This value will never be true if privateBrowsingEnabled is false.
readonly attribute boolean autoStarted;
// Determine whether the last private browsing transition was performed through
// the command line (using either the -private or -private-toggle switches).
readonly attribute boolean lastChangedByCommandLine;
/**
* Removes all data stored for a given domain. This includes all data for
* subdomains of the given domain.