Bug 856366 - Fix intermittent browser_privatebrowsing_zoomrestore.js failure, part 2. r=test

This commit is contained in:
Drew Willcoxon 2013-04-01 23:30:25 -07:00
parent 18e132b4d8
commit 33292355f9

View File

@ -11,68 +11,45 @@ function test() {
let windowsToClose = [];
let windowsToReset = [];
// These "debug" methods are for debugging random orange bug 856366. If the
// underlying problem there is fixed, these should be removed.
function debugLogCPS(aWindow, aCallback) {
let pb = { usePrivateBrowsing: true };
let queue = [
["getByDomainAndName", ["about:blank", aWindow.FullZoom.name, null]],
["getByDomainAndName", ["about:blank", aWindow.FullZoom.name, pb]],
["getGlobal", [aWindow.FullZoom.name, null]],
["getGlobal", [aWindow.FullZoom.name, pb]],
];
debugCallCPS(queue, aCallback);
}
function debugCallCPS(aQueue, aCallback) {
if (!aQueue.length) {
aCallback();
return;
}
let [methodName, args] = aQueue.shift();
let argsDup = args.slice();
argsDup.push({
handleResult: function debug_handleResult(pref) {
info("handleResult " + methodName + "(" + args.toSource() +
") pref=" + pref.value);
},
handleCompletion: function debug_handleCompletion() {
info("handleCompletion " + methodName + "(" + args.toSource() + ")");
debugCallCPS(aQueue, aCallback);
},
});
let cps = Cc["@mozilla.org/content-pref/service;1"].
getService(Ci.nsIContentPrefService2);
cps[methodName].apply(cps, argsDup);
function doTestWhenReady(aIsZoomedWindow, aWindow, aCallback) {
// Need to wait on two things, the ordering of which is not guaranteed:
// (1) the page load, and (2) FullZoom's update to the new page's zoom
// level. FullZoom broadcasts "browser-fullZoom:locationChange" when its
// update is done. (See bug 856366 for details.)
let n = 0;
let browser = aWindow.gBrowser.selectedBrowser;
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
if (++n == 2)
doTest(aIsZoomedWindow, aWindow, aCallback);
}, true);
let topic = "browser-fullZoom:locationChange";
Services.obs.addObserver(function onLocationChange() {
Services.obs.removeObserver(onLocationChange, topic);
if (++n == 2)
doTest(aIsZoomedWindow, aWindow, aCallback);
}, topic, false);
browser.loadURI("about:blank");
}
function doTest(aIsZoomedWindow, aWindow, aCallback) {
aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
if (aIsZoomedWindow) {
info("about:blank zoom level should be 1: " + aWindow.ZoomManager.zoom);
if (aWindow.ZoomManager.zoom != 1) {
// The zoom level should be 1 on the freshly loaded about:blank, but
// sometimes it's not. See bug 856366. Ensuring the initial zoom is
// 1 is not the point of this test, however, so don't randomly fail by
// assuming it's 1, and log some data to help debug the failure.
info("zoom level != 1, logging content prefs");
debugLogCPS(aWindow, aCallback);
return;
}
// change the zoom on the blank page
aWindow.FullZoom.enlarge(function () {
isnot(aWindow.ZoomManager.zoom, 1, "Zoom level for about:blank should be changed");
aCallback();
});
return;
}
// make sure the zoom level is set to 1
is(aWindow.ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
aCallback();
}, true);
aWindow.gBrowser.selectedBrowser.loadURI("about:blank");
if (aIsZoomedWindow) {
is(aWindow.ZoomManager.zoom, 1,
"Zoom level for freshly loaded about:blank should be 1");
// change the zoom on the blank page
aWindow.FullZoom.enlarge(function () {
isnot(aWindow.ZoomManager.zoom, 1, "Zoom level for about:blank should be changed");
aCallback();
});
return;
}
// make sure the zoom level is set to 1
is(aWindow.ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
aCallback();
}
function finishTest() {
@ -108,9 +85,9 @@ function test() {
});
testOnWindow({}, function(win) {
doTest(true, win, function() {
doTestWhenReady(true, win, function() {
testOnWindow({private: true}, function(win) {
doTest(false, win, finishTest);
doTestWhenReady(false, win, finishTest);
});
});
});