Test case for bug 828780; r=jdm

This commit is contained in:
Ehsan Akhgari 2013-01-16 09:35:41 -05:00
parent be02bb7b57
commit e69be76f21

View File

@ -5,22 +5,45 @@
function test() {
// We need to open a new window for this so that its docshell would get destroyed
// when clearing the PB mode flag.
let newWin = OpenBrowserWindow({private: true});
function runTest(aCloseWindow, aCallback) {
let newWin = OpenBrowserWindow({private: true});
SimpleTest.waitForFocus(function() {
let expectedExiting = true;
let expectedExited = false;
let observerExiting = {
observe: function(aSubject, aTopic, aData) {
is(aTopic, "last-pb-context-exiting", "Correct topic should be dispatched (exiting)");
is(expectedExiting, true, "notification not expected yet (exiting)");
expectedExited = true;
Services.obs.removeObserver(observerExiting, "last-pb-context-exiting", false);
}
};
let observerExited = {
observe: function(aSubject, aTopic, aData) {
is(aTopic, "last-pb-context-exited", "Correct topic should be dispatched (exited)");
is(expectedExited, true, "notification not expected yet (exited)");
Services.obs.removeObserver(observerExited, "last-pb-context-exited", false);
aCallback();
}
};
Services.obs.addObserver(observerExiting, "last-pb-context-exiting", false);
Services.obs.addObserver(observerExited, "last-pb-context-exited", false);
expectedExiting = true;
aCloseWindow(newWin);
newWin = null;
SpecialPowers.forceGC();
}, newWin);
}
waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
let expected = false;
let observer = {
observe: function(aSubject, aTopic, aData) {
is(aTopic, "last-pb-context-exited", "Correct topic should be dispatched");
is(expected, true, "notification not expected yet");
Services.obs.removeObserver(observer, "last-pb-context-exited", false);
finish();
}
};
Services.obs.addObserver(observer, "last-pb-context-exited", false);
expected = true;
newWin.close(); // this will cause the docshells to leave PB mode
newWin = null;
SpecialPowers.forceGC();
}, newWin);
runTest(function(newWin) {
// Simulate pressing the window close button
newWin.document.getElementById("cmd_closeWindow").doCommand();
}, function () {
runTest(function(newWin) {
// Simulate closing the last tab
newWin.document.getElementById("cmd_close").doCommand();
}, finish);
});
}