browser_viewport_zoom_resolution_invariant.js (2016B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that resolution is as expected for different types of meta viewport 7 // settings, as the RDM pane is zoomed to different values. 8 9 const RESOLUTION_FACTOR_MIN = 0.96; 10 const RESOLUTION_FACTOR_MAX = 1.04; 11 const ZOOM_LEVELS = [ 12 0.3, 0.5, 0.67, 0.8, 0.9, 1.0, 1.1, 1.2, 1.33, 1.5, 1.7, 2.0, 2.4, 3.0, 13 // TODO(emilio): These should pass. 14 // 0.3, 15 // 3.0, 16 ]; 17 18 info("--- Starting viewport test output ---"); 19 20 const WIDTH = 200; 21 const HEIGHT = 200; 22 const TESTS = [ 23 { content: "width=600", res_target: 0.333 }, 24 { content: "width=600, initial-scale=1.0", res_target: 1.0 }, 25 { content: "width=device-width", res_target: 1.0 }, 26 { content: "width=device-width, initial-scale=2.0", res_target: 2.0 }, 27 ]; 28 29 for (const { content, res_target } of TESTS) { 30 const TEST_URL = 31 `data:text/html;charset=utf-8,` + 32 `<html><head><meta name="viewport" content="${content}"></head>` + 33 `<body><div style="width:100%;background-color:green">${content}</div>` + 34 `</body></html>`; 35 36 addRDMTask(TEST_URL, async function ({ ui, manager, browser }) { 37 await setViewportSize(ui, manager, WIDTH, HEIGHT); 38 await setTouchAndMetaViewportSupport(ui, true); 39 40 // Ensure we've reflowed the page at least once so that MVM has chosen 41 // the initial scale. 42 await promiseContentReflow(ui); 43 44 for (const zoom of ZOOM_LEVELS.concat([...ZOOM_LEVELS].reverse())) { 45 info(`Set zoom to ${zoom}.`); 46 await promiseRDMZoom(ui, browser, zoom); 47 48 const resolution = await spawnViewportTask(ui, {}, () => { 49 return content.windowUtils.getResolution(); 50 }); 51 52 const res_min = res_target * RESOLUTION_FACTOR_MIN; 53 const res_max = res_target * RESOLUTION_FACTOR_MAX; 54 ok( 55 res_min <= resolution && res_max >= resolution, 56 `${content} zoom ${zoom} resolution should be near ${res_target}, and we got ${resolution}.` 57 ); 58 } 59 }); 60 }