Bug 651643 - Private browsing service executes transition even when no mode switch required; r=ehsan,zpao

This commit is contained in:
Tim Taubert 2011-08-04 03:49:38 +02:00
parent 2defc58264
commit 2c846a49c3
5 changed files with 98 additions and 64 deletions

View File

@ -433,7 +433,8 @@ let UI = {
Utils.assert(item, "item must be given"); Utils.assert(item, "item must be given");
if (item.isATabItem) { if (item.isATabItem) {
GroupItems.setActiveGroupItem(item.parent); if (item.parent)
GroupItems.setActiveGroupItem(item.parent);
this._setActiveTab(item); this._setActiveTab(item);
} else { } else {
GroupItems.setActiveGroupItem(item); GroupItems.setActiveGroupItem(item);

View File

@ -103,6 +103,8 @@ function onTabViewHidden() {
// end game // end game
ok(!TabView.isVisible(), "we finish with Tab View not visible"); ok(!TabView.isVisible(), "we finish with Tab View not visible");
registerCleanupFunction(verifyCleanState); // verify after all cleanups registerCleanupFunction(verifyCleanState); // verify after all cleanups
gBrowser.selectedTab = gBrowser.tabs[0];
finish(); finish();
}); });
}); });

View File

@ -503,41 +503,43 @@ PrivateBrowsingService.prototype = {
if (this._currentStatus != STATE_IDLE) if (this._currentStatus != STATE_IDLE)
throw Cr.NS_ERROR_FAILURE; throw Cr.NS_ERROR_FAILURE;
if (val == this._inPrivateBrowsing)
return;
try { try {
if (val) {
if (!this._canEnterPrivateBrowsingMode())
return;
}
else {
if (!this._canLeavePrivateBrowsingMode())
return;
}
this._ensureCanCloseWindows();
// start the transition now that we know that we can
this._currentStatus = STATE_TRANSITION_STARTED; this._currentStatus = STATE_TRANSITION_STARTED;
if (val != this._inPrivateBrowsing) { this._autoStarted = this._prefs.getBoolPref("browser.privatebrowsing.autostart");
if (val) { this._inPrivateBrowsing = val != false;
if (!this._canEnterPrivateBrowsingMode())
return;
}
else {
if (!this._canLeavePrivateBrowsingMode())
return;
}
this._ensureCanCloseWindows(); let data = val ? "enter" : "exit";
this._autoStarted = this._prefs.getBoolPref("browser.privatebrowsing.autostart"); let quitting = Cc["@mozilla.org/supports-PRBool;1"].
this._inPrivateBrowsing = val != false; createInstance(Ci.nsISupportsPRBool);
quitting.data = this._quitting;
let data = val ? "enter" : "exit"; // notify observers of the pending private browsing mode change
this._obs.notifyObservers(quitting, "private-browsing-change-granted", data);
let quitting = Cc["@mozilla.org/supports-PRBool;1"]. // destroy the current session and start initial cleanup
createInstance(Ci.nsISupportsPRBool); this._onBeforePrivateBrowsingModeChange();
quitting.data = this._quitting;
// notify observers of the pending private browsing mode change this._obs.notifyObservers(quitting, "private-browsing", data);
this._obs.notifyObservers(quitting, "private-browsing-change-granted", data);
// destroy the current session and start initial cleanup // load the appropriate session
this._onBeforePrivateBrowsingModeChange(); this._onAfterPrivateBrowsingModeChange();
this._obs.notifyObservers(quitting, "private-browsing", data);
// load the appropriate session
this._onAfterPrivateBrowsingModeChange();
}
} catch (ex) { } catch (ex) {
// We aborted the transition to/from private browsing, we must restore the // We aborted the transition to/from private browsing, we must restore the
// beforeunload handling on all the windows for which we switched it off. // beforeunload handling on all the windows for which we switched it off.

View File

@ -7,19 +7,35 @@ function test() {
{entries: [{url: "about:robots"}], hidden: true} {entries: [{url: "about:robots"}], hidden: true}
] }] }; ] }] };
let finalState = { windows: [{ tabs: [
{entries: [{url: "about:blank"}]}
] }] };
waitForExplicitFinish(); waitForExplicitFinish();
waitForBrowserState(state, function () { newWindowWithState(state, function (win) {
is(gBrowser.tabs.length, 2, "two tabs were restored"); registerCleanupFunction(function () win.close());
is(gBrowser.visibleTabs.length, 1, "one tab is visible");
let tab = gBrowser.visibleTabs[0]; is(win.gBrowser.tabs.length, 2, "two tabs were restored");
is(win.gBrowser.visibleTabs.length, 1, "one tab is visible");
let tab = win.gBrowser.visibleTabs[0];
is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "visible tab is about:mozilla"); is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "visible tab is about:mozilla");
waitForBrowserState(finalState, finish); finish();
}); });
} }
function newWindowWithState(state, callback) {
let opts = "chrome,all,dialog=no,height=800,width=800";
let win = window.openDialog(getBrowserURL(), "_blank", opts);
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
executeSoon(function () {
win.addEventListener("SSWindowStateReady", function onReady() {
win.removeEventListener("SSWindowStateReady", onReady, false);
executeSoon(function () callback(win));
}, false);
ss.setWindowState(win, JSON.stringify(state), true);
});
}, false);
}

View File

@ -1,11 +1,7 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
let stateBackup = ss.getBrowserState();
function test() { function test() {
waitForExplicitFinish();
let oldState = { let oldState = {
windows: [{ windows: [{
tabs: [ tabs: [
@ -20,24 +16,26 @@ function test() {
}; };
let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; let state = { windows: [{ tabs: [{ entries: [pageData] }] }] };
// The form data will be restored before SSTabRestored, so we want to listen waitForExplicitFinish();
// for that on the currently selected tab (it will be reused)
gBrowser.selectedTab.addEventListener("SSTabRestored", onSSTabRestored, true);
ss.setBrowserState(JSON.stringify(state)); newWindowWithState(state, function (win) {
registerCleanupFunction(function () win.close());
is(gBrowser.tabs.length, 1, "The total number of tabs should be 1");
is(gBrowser.visibleTabs.length, 1, "The total number of visible tabs should be 1");
executeSoon(function () {
waitForFocus(function () {
middleClickTest(win);
finish();
}, win);
});
});
} }
function onSSTabRestored(aEvent) { function middleClickTest(win) {
gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true); let browser = win.gBrowser.selectedBrowser;
let tree = browser.contentDocument.getElementById("tabList");
is(gBrowser.tabs.length, 1, "The total number of tabs should be 1");
is(gBrowser.visibleTabs.length, 1, "The total number of visible tabs should be 1");
executeSoon(middleClickTest);
}
function middleClickTest() {
let tree = gBrowser.selectedBrowser.contentDocument.getElementById("tabList");
is(tree.view.rowCount, 3, "There should be three items"); is(tree.view.rowCount, 3, "There should be three items");
let x = {}, y = {}, width = {}, height = {}; let x = {}, y = {}, width = {}, height = {};
@ -45,21 +43,36 @@ function middleClickTest() {
// click on the first tab item // click on the first tab item
tree.treeBoxObject.getCoordsForCellItem(1, tree.columns[1], "text", x, y, width, height); tree.treeBoxObject.getCoordsForCellItem(1, tree.columns[1], "text", x, y, width, height);
EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 },
gBrowser.selectedBrowser.contentWindow); browser.contentWindow);
// click on the second tab item // click on the second tab item
tree.treeBoxObject.getCoordsForCellItem(2, tree.columns[1], "text", x, y, width, height); tree.treeBoxObject.getCoordsForCellItem(2, tree.columns[1], "text", x, y, width, height);
EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 },
gBrowser.selectedBrowser.contentWindow); browser.contentWindow);
is(gBrowser.tabs.length, 3, is(win.gBrowser.tabs.length, 3,
"The total number of tabs should be 3 after restoring 2 tabs by middle click."); "The total number of tabs should be 3 after restoring 2 tabs by middle click.");
is(gBrowser.visibleTabs.length, 3, is(win.gBrowser.visibleTabs.length, 3,
"The total number of visible tabs should be 3 after restoring 2 tabs by middle click"); "The total number of visible tabs should be 3 after restoring 2 tabs by middle click");
cleanup();
} }
function cleanup() { function newWindowWithState(state, callback) {
ss.setBrowserState(stateBackup); let opts = "chrome,all,dialog=no,height=800,width=800";
executeSoon(finish); let win = window.openDialog(getBrowserURL(), "_blank", opts);
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
let tab = win.gBrowser.selectedTab;
// The form data will be restored before SSTabRestored, so we want to listen
// for that on the currently selected tab (it will be reused)
tab.addEventListener("SSTabRestored", function onRestored() {
tab.removeEventListener("SSTabRestored", onRestored, true);
callback(win);
}, true);
executeSoon(function () {
ss.setWindowState(win, JSON.stringify(state), true);
});
}, false);
} }