forked from mirrors/gecko-dev
We need it to live in BrowsingContext instead of WindowContext, because we need to preserve the zoom level across same-origin navigation. It'd be nice if it only lived in the top BC, but that's not possible at the moment because a lot of tests rely on zooming only iframes. Some of them can be adjusted for scaling the top instead, but not sure it's worth it's worth fixing them and moving the zoom to be top-only, as it'd be a bunch of effort, and the complexity and overhead of propagating the zoom is not so big. The print-preview-specific code in nsContentViewer is from before we did the document cloning setup, and it seems useless. I've tested print preview scaling before and after my patch and both behave the same. The rest is just various test changes to use the SpecialPowers APIs or BrowsingContext as needed instead of directly poking at the content viewer. I named the pres context hook RecomputeBrowsingContextDependentData, as more stuff should move there like overrideDPPX and other media emulation shenanigans. I also have some ideas to simplify or even remove ZoomChild and such, but that's followup work. Differential Revision: https://phabricator.services.mozilla.com/D71969
110 lines
3.9 KiB
JavaScript
110 lines
3.9 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* https://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
add_task(async function test_sitespecific_iframe_global_zoom() {
|
|
const TEST_PAGE_URL =
|
|
'data:text/html;charset=utf-8,<body>test_sitespecific_iframe_global_zoom<iframe src=""></iframe></body>';
|
|
const TEST_IFRAME_URL = "https://example.com/";
|
|
|
|
// Prepare the test tab
|
|
console.log("Creating tab");
|
|
let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
|
|
let tabBrowser = gBrowser.getBrowserForTab(tab);
|
|
console.log("Loading tab");
|
|
await FullZoomHelper.selectTabAndWaitForLocationChange(tab);
|
|
|
|
// 67% global zoom
|
|
console.log("Changing default zoom");
|
|
await FullZoomHelper.changeDefaultZoom(67);
|
|
let defaultZoom = await FullZoomHelper.getGlobalValue();
|
|
is(defaultZoom, 0.67, "Global zoom is at 67%");
|
|
await TestUtils.waitForCondition(() => {
|
|
console.log("Current zoom is: ", ZoomManager.getZoomForBrowser(tabBrowser));
|
|
return ZoomManager.getZoomForBrowser(tabBrowser) == 0.67;
|
|
});
|
|
|
|
let zoomLevel = ZoomManager.getZoomForBrowser(tabBrowser);
|
|
is(zoomLevel, 0.67, "tab zoom has been set to 67%");
|
|
|
|
let frameLoadedPromise = BrowserTestUtils.browserLoaded(
|
|
tabBrowser,
|
|
true,
|
|
TEST_IFRAME_URL
|
|
);
|
|
console.log("Spawinging iframe");
|
|
SpecialPowers.spawn(tabBrowser, [TEST_IFRAME_URL], url => {
|
|
content.document.querySelector("iframe").src = url;
|
|
});
|
|
console.log("Awaiting frame promise");
|
|
let loadedURL = await frameLoadedPromise;
|
|
is(loadedURL, TEST_IFRAME_URL, "got the load event for the iframe");
|
|
|
|
let frameZoom = await SpecialPowers.spawn(
|
|
gBrowser.selectedBrowser.browsingContext.children[0],
|
|
[],
|
|
async () => {
|
|
await ContentTaskUtils.waitForCondition(() => {
|
|
return content.docShell.browsingContext.fullZoom.toFixed(2) == 0.67;
|
|
});
|
|
return content.docShell.browsingContext.fullZoom.toFixed(2);
|
|
}
|
|
);
|
|
|
|
is(frameZoom, zoomLevel, "global zoom is reflected in iframe");
|
|
console.log("Removing tab");
|
|
await FullZoomHelper.removeTabAndWaitForLocationChange();
|
|
});
|
|
|
|
add_task(async function test_sitespecific_global_zoom_enlarge() {
|
|
const TEST_PAGE_URL =
|
|
'data:text/html;charset=utf-8,<body>test_sitespecific_global_zoom_enlarge<iframe src=""></iframe></body>';
|
|
const TEST_IFRAME_URL = "https://example.org/";
|
|
|
|
// Prepare the test tab
|
|
console.log("Adding tab");
|
|
let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
|
|
let tabBrowser = gBrowser.getBrowserForTab(tab);
|
|
console.log("Awaiting tab load");
|
|
await FullZoomHelper.selectTabAndWaitForLocationChange(tab);
|
|
|
|
// 67% global zoom persists from previous test
|
|
|
|
let frameLoadedPromise = BrowserTestUtils.browserLoaded(
|
|
tabBrowser,
|
|
true,
|
|
TEST_IFRAME_URL
|
|
);
|
|
console.log("Spawning iframe");
|
|
SpecialPowers.spawn(tabBrowser, [TEST_IFRAME_URL], url => {
|
|
content.document.querySelector("iframe").src = url;
|
|
});
|
|
console.log("Awaiting iframe load");
|
|
let loadedURL = await frameLoadedPromise;
|
|
is(loadedURL, TEST_IFRAME_URL, "got the load event for the iframe");
|
|
console.log("Enlarging tab");
|
|
await FullZoom.enlarge();
|
|
// 80% local zoom
|
|
await TestUtils.waitForCondition(() => {
|
|
console.log("Current zoom is: ", ZoomManager.getZoomForBrowser(tabBrowser));
|
|
return ZoomManager.getZoomForBrowser(tabBrowser) == 0.8;
|
|
});
|
|
|
|
is(ZoomManager.getZoomForBrowser(tabBrowser), 0.8, "Local zoom is increased");
|
|
|
|
let frameZoom = await SpecialPowers.spawn(
|
|
gBrowser.selectedBrowser.browsingContext.children[0],
|
|
[],
|
|
async () => {
|
|
await ContentTaskUtils.waitForCondition(() => {
|
|
return content.docShell.browsingContext.fullZoom.toFixed(2) == 0.8;
|
|
});
|
|
return content.docShell.browsingContext.fullZoom.toFixed(2);
|
|
}
|
|
);
|
|
|
|
is(frameZoom, 0.8, "(without fission) iframe zoom matches page zoom");
|
|
console.log("Removing tab");
|
|
await FullZoomHelper.removeTabAndWaitForLocationChange();
|
|
});
|