Bug 558321 - Tab Matches are not honoured in Private Browsing mode. r=mak77, a=blocking-betaN

This commit is contained in:
Blair McBride 2011-01-12 13:40:36 +13:00
Родитель b4ce8fce8b
Коммит 8b74bf0a75
2 изменённых файлов: 85 добавлений и 44 удалений

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

@ -137,6 +137,64 @@ var gTestSteps = [
}, true);
tab.linkedBrowser.loadURI('about:robots');
},
function() {
info("Running step 9 - enter private browsing mode, without keeping session");
let ps = Services.prefs;
ps.setBoolPref("browser.privatebrowsing.keep_current_session", false);
ps.setBoolPref("browser.tabs.warnOnClose", false);
Services.obs.addObserver(function(aSubject, aTopic, aData) {
Services.obs.removeObserver(arguments.callee, "private-browsing-transition-complete");
for (let i = 0; i < gBrowser.tabs.length; i++)
waitForRestoredTab(gBrowser.tabs[i]);
}, "private-browsing-transition-complete", false);
gPrivateBrowsing.privateBrowsingEnabled = true;
},
function() {
info("Running step 10 - open tabs in private browsing mode");
for (let i = 0; i < 3; i++) {
let tab = gBrowser.addTab();
loadTab(tab, TEST_URL_BASES[0] + (++gTabCounter));
}
},
function() {
info("Running step 11 - close tabs in private browsing mode");
gBrowser.removeCurrentTab();
ensure_opentabs_match_db(nextStep);
},
function() {
info("Running step 12 - leave private browsing mode");
Services.obs.addObserver(function(aSubject, aTopic, aData) {
Services.obs.removeObserver(arguments.callee, "private-browsing-transition-complete");
let ps = Services.prefs;
try {
ps.clearUserPref("browser.privatebrowsing.keep_current_session");
} catch (ex) {}
try {
ps.clearUserPref("browser.tabs.warnOnClose");
} catch (ex) {}
for (let i = 1; i < gBrowser.tabs.length; i++)
waitForRestoredTab(gBrowser.tabs[i]);
}, "private-browsing-transition-complete", false);
gPrivateBrowsing.privateBrowsingEnabled = false;
},
function() {
info("Running step 13 - close all tabs");
gBrowser.addTab("about:blank", {skipAnimation: true});
while (gBrowser.tabs.length > 1) {
info("Removing tab: " + gBrowser.tabs[0].linkedBrowser.currentURI.spec);
gBrowser.selectTabAtIndex(0);
gBrowser.removeCurrentTab();
}
ensure_opentabs_match_db(nextStep);
}
];
@ -148,7 +206,7 @@ function test() {
function loadTab(tab, url) {
// Because adding visits is async, we will not be notified immediately.
let visited = false;
let visited = gPrivateBrowsing.privateBrowsingEnabled;
let loaded = false;
function maybeCheckResults() {
@ -163,22 +221,37 @@ function loadTab(tab, url) {
maybeCheckResults();
}, true);
Services.obs.addObserver(
function (aSubject, aTopic, aData) {
if (url != aSubject.QueryInterface(Ci.nsIURI).spec)
return;
Services.obs.removeObserver(arguments.callee, aTopic);
visited = true;
maybeCheckResults();
},
"uri-visit-saved",
false
);
if (!visited) {
Services.obs.addObserver(
function (aSubject, aTopic, aData) {
if (url != aSubject.QueryInterface(Ci.nsIURI).spec)
return;
Services.obs.removeObserver(arguments.callee, aTopic);
visited = true;
maybeCheckResults();
},
"uri-visit-saved",
false
);
}
gTabWaitCount++;
info("Loading page: " + url);
tab.linkedBrowser.loadURI(url);
}
function waitForRestoredTab(tab) {
gTabWaitCount++;
tab.linkedBrowser.addEventListener("load", function () {
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
if (--gTabWaitCount == 0) {
ensure_opentabs_match_db(nextStep);
}
}, true);
}
function nextStep() {
if (gTestSteps.length == 0) {
while (gBrowser.tabs.length > 1) {

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

@ -106,12 +106,6 @@ const kTitleTagsSeparator = " \u2013 ";
const kBrowserUrlbarBranch = "browser.urlbar.";
////////////////////////////////////////////////////////////////////////////////
//// Globals and Lazy Getters
XPCOMUtils.defineLazyServiceGetter(this, "pb",
"@mozilla.org/privatebrowsing;1",
"nsIPrivateBrowsingService");
////////////////////////////////////////////////////////////////////////////////
//// Helpers
@ -153,18 +147,6 @@ function initTempTable(aDatabase)
stmt.finalize();
}
/**
* @return true if private browsing is active, false otherwise.
*/
function inPrivateBrowsingMode()
{
try {
return pb.privateBrowsingEnabled;
}
catch (ex) {
return false;
}
}
////////////////////////////////////////////////////////////////////////////////
//// AutoCompleteStatementCallbackWrapper class
@ -537,13 +519,6 @@ nsPlacesAutoComplete.prototype = {
registerOpenPage: function PAC_registerOpenPage(aURI)
{
// Don't add any pages while in Private Browsing mode, so as to avoid
// leaking information about other windows that might otherwise stay hidden
// and private.
if (inPrivateBrowsingMode()) {
return;
}
let stmt = this._registerOpenPageQuery;
stmt.params.page_url = aURI.spec;
@ -552,13 +527,6 @@ nsPlacesAutoComplete.prototype = {
unregisterOpenPage: function PAC_unregisterOpenPage(aURI)
{
// Entering Private Browsing mode will unregister all open pages, therefore
// there should not be anything in the moz_openpages_temp table. As a
// result, we can stop now without doing any unnecessary work.
if (inPrivateBrowsingMode()) {
return;
}
let stmt = this._unregisterOpenPageQuery;
stmt.params.page_url = aURI.spec;