browser_window_sizing.js (3186B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that correct window sizing values are reported and unaffected by zoom. In 7 // particular, we want to ensure that the values for the window's outer and screen 8 // sizing values reflect the size of the viewport. 9 10 const TEST_URL = "data:text/html;charset=utf-8,"; 11 const WIDTH = 375; 12 const HEIGHT = 450; 13 const ZOOM_LEVELS = [0.3, 0.5, 0.9, 1, 1.5, 2, 2.4]; 14 15 addRDMTask( 16 null, 17 async function () { 18 const tab = await addTab(TEST_URL); 19 const browser = tab.linkedBrowser; 20 21 const { ui, manager } = await openRDM(tab); 22 await waitForDeviceAndViewportState(ui); 23 await setViewportSize(ui, manager, WIDTH, HEIGHT); 24 25 info("Ensure outer size values are unchanged at different zoom levels."); 26 for (let i = 0; i < ZOOM_LEVELS.length; i++) { 27 info(`Setting zoom level to ${ZOOM_LEVELS[i]}`); 28 await promiseRDMZoom(ui, browser, ZOOM_LEVELS[i]); 29 30 await checkWindowOuterSize(ui, ZOOM_LEVELS[i]); 31 await checkWindowScreenSize(ui, ZOOM_LEVELS[i]); 32 } 33 }, 34 { onlyPrefAndTask: true } 35 ); 36 37 async function checkWindowOuterSize(ui, zoom_level) { 38 return SpecialPowers.spawn( 39 ui.getViewportBrowser(), 40 [{ width: WIDTH, height: HEIGHT, zoom: zoom_level }], 41 async function ({ width, height, zoom }) { 42 // Approximate the outer size value returned on the window content with the expected 43 // value. We should expect, at the very most, a 2px difference between the two due 44 // to floating point rounding errors that occur when scaling from inner size CSS 45 // integer values to outer size CSS integer values. See Part 1 of Bug 1107456. 46 // Some of the drift is also due to full zoom scaling effects; see Bug 1577775. 47 Assert.lessOrEqual( 48 Math.abs(content.outerWidth - width), 49 2, 50 `window.outerWidth zoom ${zoom} should be ${width} and we got ${content.outerWidth}.` 51 ); 52 Assert.lessOrEqual( 53 Math.abs(content.outerHeight - height), 54 2, 55 `window.outerHeight zoom ${zoom} should be ${height} and we got ${content.outerHeight}.` 56 ); 57 } 58 ); 59 } 60 61 async function checkWindowScreenSize(ui, zoom_level) { 62 return SpecialPowers.spawn( 63 ui.getViewportBrowser(), 64 [{ width: WIDTH, height: HEIGHT, zoom: zoom_level }], 65 async function ({ width, height, zoom }) { 66 const { screen } = content; 67 68 Assert.lessOrEqual( 69 Math.abs(screen.availWidth - width), 70 2, 71 `screen.availWidth zoom ${zoom} should be ${width} and we got ${screen.availWidth}.` 72 ); 73 74 Assert.lessOrEqual( 75 Math.abs(screen.availHeight - height), 76 2, 77 `screen.availHeight zoom ${zoom} should be ${height} and we got ${screen.availHeight}.` 78 ); 79 80 Assert.lessOrEqual( 81 Math.abs(screen.width - width), 82 2, 83 `screen.width zoom " ${zoom} should be ${width} and we got ${screen.width}.` 84 ); 85 86 Assert.lessOrEqual( 87 Math.abs(screen.height - height), 88 2, 89 `screen.height zoom " ${zoom} should be ${height} and we got ${screen.height}.` 90 ); 91 } 92 ); 93 }