summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/test/browser/browser_viewport_state_after_close.js
blob: 3bac3b3e0180ca92a8f7ca36f4cafb4d5290a11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that after closing RDM the page goes back to its original state

const TEST_URL =
  "data:text/html;charset=utf-8,<style>h1 {width: 200px;} @media (hover:none) { h1 {width: 400px;background: tomato;}</style><h1>Hello</h1>";

add_task(async function () {
  const tab = await addTab(TEST_URL);

  reloadOnTouchChange(false);
  reloadOnUAChange(false);
  await pushPref("devtools.responsive.touchSimulation.enabled", true);

  is(await getH1Width(), 200, "<h1> has expected initial width");

  for (let i = 0; i < 10; i++) {
    info("Open responsive design mode");
    await openRDM(tab);

    await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
      const mql = content.matchMedia("(hover:none)");
      if (mql.matches) {
        return;
      }
      await new Promise(res =>
        mql.addEventListener("change", res, { once: true })
      );
    });

    is(
      await getH1Width(),
      400,
      "<h1> has expected width when RDM and touch simulation are enabled"
    );

    info("Close responsive design mode");
    await closeRDM(tab);

    is(await getH1Width(), 200, "<h1> has expected width after closing RDM");
  }
});

function getH1Width() {
  return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    return content.document.querySelector("h1").getBoundingClientRect().width;
  });
}