browser_viewport_state_after_close.js (1475B)
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 after closing RDM the page goes back to its original state 7 8 const TEST_URL = 9 "data:text/html;charset=utf-8,<style>h1 {width: 200px;} @media (hover:none) { h1 {width: 400px;background: tomato;}</style><h1>Hello</h1>"; 10 11 add_task(async function () { 12 const tab = await addTab(TEST_URL); 13 14 reloadOnTouchChange(false); 15 reloadOnUAChange(false); 16 await pushPref("devtools.responsive.touchSimulation.enabled", true); 17 18 is(await getH1Width(), 200, "<h1> has expected initial width"); 19 20 for (let i = 0; i < 10; i++) { 21 info("Open responsive design mode"); 22 await openRDM(tab); 23 24 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 25 const mql = content.matchMedia("(hover:none)"); 26 if (mql.matches) { 27 return; 28 } 29 await new Promise(res => 30 mql.addEventListener("change", res, { once: true }) 31 ); 32 }); 33 34 is( 35 await getH1Width(), 36 400, 37 "<h1> has expected width when RDM and touch simulation are enabled" 38 ); 39 40 info("Close responsive design mode"); 41 await closeRDM(tab); 42 43 is(await getH1Width(), 200, "<h1> has expected width after closing RDM"); 44 } 45 }); 46 47 function getH1Width() { 48 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 49 return content.document.querySelector("h1").getBoundingClientRect().width; 50 }); 51 }