browser_test_resolution.js (2408B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /* import-globals-from ../../mochitest/layout.js */ 8 9 async function testScaledBounds(browser, accDoc, scale, id, type = "object") { 10 let acc = findAccessibleChildByID(accDoc, id); 11 12 // Get document offset 13 let [docX, docY] = getBounds(accDoc); 14 15 // Get the unscaled bounds of the accessible 16 let [x, y, width, height] = 17 type == "text" 18 ? getRangeExtents(acc, 0, -1, COORDTYPE_SCREEN_RELATIVE) 19 : getBounds(acc); 20 21 await invokeContentTask(browser, [scale], _scale => { 22 const { Layout } = ChromeUtils.importESModule( 23 "chrome://mochitests/content/browser/accessible/tests/browser/Layout.sys.mjs" 24 ); 25 Layout.setResolution(content.document, _scale); 26 }); 27 28 let [scaledX, scaledY, scaledWidth, scaledHeight] = 29 type == "text" 30 ? getRangeExtents(acc, 0, -1, COORDTYPE_SCREEN_RELATIVE) 31 : getBounds(acc); 32 33 let name = prettyName(acc); 34 isWithin(scaledWidth, width * scale, 2, "Wrong scaled width of " + name); 35 isWithin(scaledHeight, height * scale, 2, "Wrong scaled height of " + name); 36 isWithin(scaledX - docX, (x - docX) * scale, 2, "Wrong scaled x of " + name); 37 isWithin(scaledY - docY, (y - docY) * scale, 2, "Wrong scaled y of " + name); 38 39 await invokeContentTask(browser, [], () => { 40 const { Layout } = ChromeUtils.importESModule( 41 "chrome://mochitests/content/browser/accessible/tests/browser/Layout.sys.mjs" 42 ); 43 Layout.setResolution(content.document, 1.0); 44 }); 45 } 46 47 async function runTests(browser, accDoc) { 48 // The scrollbars get in the way of container bounds calculation. 49 await SpecialPowers.pushPrefEnv({ 50 set: [["ui.useOverlayScrollbars", 1]], 51 }); 52 53 await testScaledBounds(browser, accDoc, 2.0, "p1"); 54 await testScaledBounds(browser, accDoc, 0.5, "p2"); 55 await testScaledBounds(browser, accDoc, 3.5, "b1"); 56 57 await testScaledBounds(browser, accDoc, 2.0, "p1", "text"); 58 await testScaledBounds(browser, accDoc, 0.75, "p2", "text"); 59 } 60 61 /** 62 * Test accessible boundaries when page is zoomed 63 */ 64 addAccessibleTask( 65 ` 66 <p id='p1' style='font-family: monospace;'>Tilimilitryamdiya</p> 67 <p id="p2">para 2</p> 68 <button id="b1">Hello</button> 69 `, 70 runTests, 71 { iframe: true, remoteIframe: true } 72 );