browser_viewport_resolution_restore.js (2213B)
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 restored to its pre-RDM value after closing RDM. 7 // Do this by using a chrome-only method to force resolution before opening 8 // RDM, then letting RDM set its own preferred resolution due to the meta 9 // viewport settings. When we close RDM and check resolution, we check for 10 // something close to what we initially set, bracketed by these scaling 11 // factors: 12 const RESOLUTION_FACTOR_MIN = 0.96; 13 const RESOLUTION_FACTOR_MAX = 1.04; 14 15 info("--- Starting viewport test output ---"); 16 17 const WIDTH = 200; 18 const HEIGHT = 200; 19 const TESTS = [ 20 { content: "width=600" }, 21 { content: "width=600, initial-scale=1.0", res_restore: 0.782 }, 22 { content: "width=device-width", res_restore: 3.4 }, 23 { content: "width=device-width, initial-scale=2.0", res_restore: 1.1 }, 24 ]; 25 26 for (const { content, res_restore } of TESTS) { 27 const TEST_URL = 28 `data:text/html;charset=utf-8,` + 29 `<html><head><meta name="viewport" content="${content}"></head>` + 30 `<body><div style="width:100%;background-color:green">${content}</div>` + 31 `</body></html>`; 32 33 addRDMTaskWithPreAndPost( 34 TEST_URL, 35 async function rdmPreTask({ browser }) { 36 if (res_restore) { 37 info(`Setting resolution to ${res_restore}.`); 38 browser.ownerGlobal.windowUtils.setResolutionAndScaleTo(res_restore); 39 } else { 40 info(`Not setting resolution.`); 41 } 42 }, 43 async function rdmTask({ ui, manager }) { 44 info(`Resizing viewport and ensuring that meta viewport is on.`); 45 await setViewportSize(ui, manager, WIDTH, HEIGHT); 46 await setTouchAndMetaViewportSupport(ui, true); 47 }, 48 async function rdmPostTask({ browser }) { 49 const resolution = browser.ownerGlobal.windowUtils.getResolution(); 50 const res_target = res_restore ? res_restore : 1.0; 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} resolution should be near ${res_target}, and we got ${resolution}.` 57 ); 58 } 59 ); 60 }