mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 541779 - Make site-specific zoom check asynchronous. r=myk
This commit is contained in:
parent
b494194f2f
commit
98dd63c4e4
@ -274,7 +274,21 @@ var FullZoom = {
|
||||
onLocationChange: function FullZoom_onLocationChange(aURI, aIsTabSwitch, aBrowser) {
|
||||
if (!aURI || (aIsTabSwitch && !this.siteSpecific))
|
||||
return;
|
||||
this._applyPrefToSetting(this._cps.getPref(aURI, this.name), aBrowser);
|
||||
|
||||
// Avoid the cps roundtrip and apply the default/global pref.
|
||||
if (aURI.spec == "about:blank") {
|
||||
this._applyPrefToSetting();
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
this._cps.getPref(aURI, this.name, function(aResult) {
|
||||
// Check that we're still where we expect to be in case this took a while.
|
||||
let isSaneURI = (aBrowser && aBrowser.currentURI) ?
|
||||
aURI.equals(aBrowser.currentURI) : false;
|
||||
if (!aBrowser || isSaneURI)
|
||||
self._applyPrefToSetting(aResult, aBrowser);
|
||||
});
|
||||
},
|
||||
|
||||
// update state of zoom type menu item
|
||||
@ -331,7 +345,7 @@ var FullZoom = {
|
||||
gInPrintPreviewMode)
|
||||
return;
|
||||
|
||||
var browser = aBrowser || gBrowser.selectedBrowser;
|
||||
var browser = aBrowser || (gBrowser && gBrowser.selectedBrowser);
|
||||
try {
|
||||
if (browser.contentDocument instanceof Ci.nsIImageDocument ||
|
||||
this._inPrivateBrowsing)
|
||||
|
@ -41,87 +41,43 @@ function thirdPageLoaded() {
|
||||
zoomTest(gTab3, gLevel, "Tab 3 should have zoomed as it was loading in the background");
|
||||
|
||||
// Switching to tab 2 should update its zoom setting.
|
||||
afterZoom(function() {
|
||||
zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
|
||||
zoomTest(gTab2, gLevel, "Tab 2 should be zoomed now");
|
||||
zoomTest(gTab3, gLevel, "Tab 3 should still be zoomed");
|
||||
|
||||
load(gTab1, gTestImage, imageLoaded);
|
||||
});
|
||||
|
||||
gBrowser.selectedTab = gTab2;
|
||||
|
||||
zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
|
||||
zoomTest(gTab2, gLevel, "Tab 2 should be zoomed now");
|
||||
zoomTest(gTab3, gLevel, "Tab 3 should still be zoomed");
|
||||
|
||||
load(gTab1, gTestImage, imageLoaded);
|
||||
}
|
||||
|
||||
function imageLoaded() {
|
||||
zoomTest(gTab1, 1, "Zoom should be 1 when image was loaded in the background");
|
||||
gBrowser.selectedTab = gTab1;
|
||||
zoomTest(gTab1, 1, "Zoom should still be 1 when tab with image is selected");
|
||||
afterZoom(function() {
|
||||
zoomTest(gTab1, 1, "Zoom should still be 1 when tab with image is selected");
|
||||
|
||||
executeSoon(imageZoomSwitch);
|
||||
executeSoon(imageZoomSwitch);
|
||||
});
|
||||
gBrowser.selectedTab = gTab1;
|
||||
}
|
||||
|
||||
function imageZoomSwitch() {
|
||||
navigate(BACK, function () {
|
||||
navigate(FORWARD, function () {
|
||||
zoomTest(gTab1, 1, "Tab 1 should not be zoomed when an image loads");
|
||||
gBrowser.selectedTab = gTab2;
|
||||
zoomTest(gTab1, 1, "Tab 1 should still not be zoomed when deselected");
|
||||
|
||||
// Mac OS X does not support print preview, so skip those tests
|
||||
let isOSX = ("nsILocalFileMac" in Components.interfaces);
|
||||
if (isOSX)
|
||||
afterZoom(function() {
|
||||
zoomTest(gTab1, 1, "Tab 1 should still not be zoomed when deselected");
|
||||
finishTest();
|
||||
else
|
||||
runPrintPreviewTests();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runPrintPreviewTests() {
|
||||
// test print preview on image document
|
||||
testPrintPreview(gTab1, function() {
|
||||
// test print preview on HTML document
|
||||
testPrintPreview(gTab2, function() {
|
||||
// test print preview on image document with siteSpecific set to false
|
||||
gPrefService.setBoolPref("browser.zoom.siteSpecific", false);
|
||||
testPrintPreview(gTab1, function() {
|
||||
// test print preview of HTML document with siteSpecific set to false
|
||||
testPrintPreview(gTab2, function() {
|
||||
if (gPrefService.prefHasUserValue("browser.zoom.siteSpecific"))
|
||||
gPrefService.clearUserPref("browser.zoom.siteSpecific");
|
||||
finishTest();
|
||||
});
|
||||
});
|
||||
gBrowser.selectedTab = gTab2;
|
||||
|
||||
finishTest();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testPrintPreview(aTab, aCallback) {
|
||||
gBrowser.selectedTab = aTab;
|
||||
FullZoom.enlarge();
|
||||
let level = ZoomManager.zoom;
|
||||
|
||||
let onEnterOrig = PrintPreviewListener.onEnter;
|
||||
PrintPreviewListener.onEnter = function () {
|
||||
PrintPreviewListener.onEnter = onEnterOrig;
|
||||
PrintPreviewListener.onEnter.apply(PrintPreviewListener, arguments);
|
||||
PrintUtils.exitPrintPreview();
|
||||
};
|
||||
|
||||
let onExitOrig = PrintPreviewListener.onExit;
|
||||
PrintPreviewListener.onExit = function () {
|
||||
PrintPreviewListener.onExit = onExitOrig;
|
||||
PrintPreviewListener.onExit.apply(PrintPreviewListener, arguments);
|
||||
|
||||
zoomTest(aTab, level, "Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
};
|
||||
|
||||
executeSoon(function () {
|
||||
document.getElementById("cmd_printPreview").doCommand();
|
||||
});
|
||||
}
|
||||
|
||||
function finishTest() {
|
||||
gBrowser.selectedTab = gTab1;
|
||||
FullZoom.reset();
|
||||
@ -138,20 +94,51 @@ function zoomTest(tab, val, msg) {
|
||||
}
|
||||
|
||||
function load(tab, url, cb) {
|
||||
let didLoad = didZoom = false;
|
||||
tab.linkedBrowser.addEventListener("load", function (event) {
|
||||
event.currentTarget.removeEventListener("load", arguments.callee, true);
|
||||
cb();
|
||||
didLoad = true;
|
||||
if (didZoom)
|
||||
executeSoon(cb);
|
||||
}, true);
|
||||
|
||||
afterZoom(function() {
|
||||
didZoom = true;
|
||||
if (didLoad)
|
||||
executeSoon(cb);
|
||||
});
|
||||
|
||||
tab.linkedBrowser.loadURI(url);
|
||||
}
|
||||
|
||||
function navigate(direction, cb) {
|
||||
let didPs = didZoom = false;
|
||||
gBrowser.addEventListener("pageshow", function (event) {
|
||||
gBrowser.removeEventListener("pageshow", arguments.callee, true);
|
||||
executeSoon(cb);
|
||||
didPs = true;
|
||||
if (didZoom)
|
||||
executeSoon(cb);
|
||||
}, true);
|
||||
|
||||
afterZoom(function() {
|
||||
didZoom = true;
|
||||
if (didPs)
|
||||
executeSoon(cb);
|
||||
});
|
||||
|
||||
if (direction == BACK)
|
||||
gBrowser.goBack();
|
||||
else if (direction == FORWARD)
|
||||
gBrowser.goForward();
|
||||
}
|
||||
|
||||
function afterZoom(cb) {
|
||||
let oldAPTS = FullZoom._applyPrefToSetting;
|
||||
FullZoom._applyPrefToSetting = function(value, browser) {
|
||||
if (!value)
|
||||
value = undefined;
|
||||
oldAPTS.call(FullZoom, value, browser);
|
||||
FullZoom._applyPrefToSetting = oldAPTS;
|
||||
executeSoon(cb);
|
||||
};
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
var tabElm, zoomLevel;
|
||||
function start_test_prefNotSet() {
|
||||
tabElm.linkedBrowser.removeEventListener("load", start_test_prefNotSet, true);
|
||||
tabElm.linkedBrowser.addEventListener("load", continue_test_prefNotSet, true);
|
||||
|
||||
is(ZoomManager.zoom, 1, "initial zoom level should be 1");
|
||||
FullZoom.enlarge();
|
||||
|
||||
@ -10,23 +7,21 @@ function start_test_prefNotSet() {
|
||||
zoomLevel = ZoomManager.zoom;
|
||||
isnot(zoomLevel, 1, "zoom level should have changed");
|
||||
|
||||
afterZoomAndLoad(continue_test_prefNotSet);
|
||||
content.location =
|
||||
"http://mochi.test:8888/browser/browser/base/content/test/moz.png";
|
||||
}
|
||||
|
||||
function continue_test_prefNotSet () {
|
||||
tabElm.linkedBrowser.removeEventListener("load", continue_test_prefNotSet, true);
|
||||
tabElm.linkedBrowser.addEventListener("load", end_test_prefNotSet, true);
|
||||
|
||||
is(ZoomManager.zoom, 1, "zoom level pref should not apply to an image");
|
||||
FullZoom.reset();
|
||||
|
||||
afterZoomAndLoad(end_test_prefNotSet);
|
||||
content.location =
|
||||
"http://mochi.test:8888/browser/browser/base/content/test/zoom_test.html";
|
||||
}
|
||||
|
||||
function end_test_prefNotSet() {
|
||||
tabElm.linkedBrowser.removeEventListener("load", end_test_prefNotSet, true);
|
||||
is(ZoomManager.zoom, zoomLevel, "the zoom level should have persisted");
|
||||
|
||||
// Reset the zoom so that other tests have a fresh zoom level
|
||||
@ -41,9 +36,28 @@ function test() {
|
||||
|
||||
tabElm = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tabElm;
|
||||
tabElm.linkedBrowser.addEventListener("load", start_test_prefNotSet, true);
|
||||
|
||||
afterZoomAndLoad(start_test_prefNotSet);
|
||||
content.location =
|
||||
"http://mochi.test:8888/browser/browser/base/content/test/zoom_test.html";
|
||||
|
||||
}
|
||||
|
||||
function afterZoomAndLoad(cb) {
|
||||
let didLoad = didZoom = false;
|
||||
tabElm.linkedBrowser.addEventListener("load", function() {
|
||||
tabElm.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
||||
didLoad = true;
|
||||
if (didZoom)
|
||||
executeSoon(cb);
|
||||
}, true);
|
||||
let oldAPTS = FullZoom._applyPrefToSetting;
|
||||
FullZoom._applyPrefToSetting = function(value, browser) {
|
||||
if (!value)
|
||||
value = undefined;
|
||||
oldAPTS.call(FullZoom, value, browser);
|
||||
FullZoom._applyPrefToSetting = oldAPTS;
|
||||
didZoom = true;
|
||||
if (didLoad)
|
||||
executeSoon(cb);
|
||||
};
|
||||
}
|
||||
|
@ -12,24 +12,38 @@ function test() {
|
||||
|
||||
FullZoom.enlarge();
|
||||
let tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser);
|
||||
|
||||
afterZoom(function() {
|
||||
let tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser);
|
||||
is(tab2Zoom, tab1Zoom, "Zoom should affect background tabs");
|
||||
|
||||
gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", false);
|
||||
FullZoom.reset();
|
||||
gBrowser.selectedTab = tab1;
|
||||
tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser);
|
||||
tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser);
|
||||
isnot(tab1Zoom, tab2Zoom, "Zoom should not affect background tabs");
|
||||
|
||||
if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs"))
|
||||
gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs");
|
||||
gBrowser.removeTab(tab1);
|
||||
gBrowser.removeTab(tab2);
|
||||
finish();
|
||||
});
|
||||
gBrowser.selectedTab = tab2;
|
||||
let tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser);
|
||||
is(tab2Zoom, tab1Zoom, "Zoom should affect background tabs");
|
||||
|
||||
gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", false);
|
||||
FullZoom.reset();
|
||||
gBrowser.selectedTab = tab1;
|
||||
tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser);
|
||||
tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser);
|
||||
isnot(tab1Zoom, tab2Zoom, "Zoom should not affect background tabs");
|
||||
|
||||
if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs"))
|
||||
gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs");
|
||||
gBrowser.removeTab(tab1);
|
||||
gBrowser.removeTab(tab2);
|
||||
finish();
|
||||
}), true);
|
||||
tab2.linkedBrowser.loadURI(testPage);
|
||||
}), true);
|
||||
content.location = testPage;
|
||||
}
|
||||
|
||||
function afterZoom(cb) {
|
||||
let oldAPTS = FullZoom._applyPrefToSetting;
|
||||
FullZoom._applyPrefToSetting = function(value, browser) {
|
||||
if (!value)
|
||||
value = undefined;
|
||||
oldAPTS.call(FullZoom, value, browser);
|
||||
FullZoom._applyPrefToSetting = oldAPTS;
|
||||
executeSoon(cb);
|
||||
};
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ function test() {
|
||||
// initialization
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
let cps = Cc["@mozilla.org/content-pref/service;1"].
|
||||
getService(Ci.nsIContentPrefService);
|
||||
waitForExplicitFinish();
|
||||
|
||||
let tabBlank = gBrowser.selectedTab;
|
||||
@ -66,24 +64,7 @@ function test() {
|
||||
setTimeout(function() {
|
||||
// make sure the zoom level is set to 1
|
||||
is(ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
|
||||
|
||||
// Mac OS X does not support print preview, so skip those tests
|
||||
let isOSX = ("nsILocalFileMac" in Components.interfaces);
|
||||
if (isOSX) {
|
||||
finishTest();
|
||||
return;
|
||||
}
|
||||
|
||||
// test print preview on HTML document
|
||||
testPrintPreview(browserAboutPB, function() {
|
||||
browserAboutPB.addEventListener("load", function() {
|
||||
browserAboutPB.removeEventListener("load", arguments.callee, true);
|
||||
|
||||
// test print preview on image document
|
||||
testPrintPreview(browserAboutPB, finishTest);
|
||||
}, true);
|
||||
browserAboutPB.loadURI("about:logo");
|
||||
});
|
||||
finishTest();
|
||||
}, 0);
|
||||
}, true);
|
||||
}, true);
|
||||
@ -107,31 +88,3 @@ function finishTest() {
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
function testPrintPreview(aBrowser, aCallback) {
|
||||
FullZoom.enlarge();
|
||||
let level = ZoomManager.getZoomForBrowser(aBrowser);
|
||||
|
||||
let onEnterOrig = PrintPreviewListener.onEnter;
|
||||
PrintPreviewListener.onEnter = function () {
|
||||
PrintPreviewListener.onEnter = onEnterOrig;
|
||||
PrintPreviewListener.onEnter.apply(PrintPreviewListener, arguments);
|
||||
PrintUtils.exitPrintPreview();
|
||||
};
|
||||
|
||||
let onExitOrig = PrintPreviewListener.onExit;
|
||||
PrintPreviewListener.onExit = function () {
|
||||
PrintPreviewListener.onExit = onExitOrig;
|
||||
PrintPreviewListener.onExit.apply(PrintPreviewListener, arguments);
|
||||
|
||||
is(ZoomManager.getZoomForBrowser(aBrowser), level,
|
||||
"Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
};
|
||||
|
||||
let printPreview = new Function(document.getElementById("cmd_printPreview")
|
||||
.getAttribute("oncommand"));
|
||||
executeSoon(printPreview);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user