summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/test/browser/browser_menu_item_02.js
blob: d0dd755580e540f6ed6d1a13b1a0a6decca7aaf9 (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
52
53
54
55
56
57
58
59
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test RDM menu item is checked when expected, on multiple windows.

const TEST_URL = "data:text/html;charset=utf-8,";

const isMenuCheckedFor = ({ document }) => {
  const menu = document.getElementById("menu_responsiveUI");
  return menu.getAttribute("checked") === "true";
};

addRDMTask(
  null,
  async function () {
    const window1 = await BrowserTestUtils.openNewBrowserWindow();
    const { gBrowser } = window1;

    await BrowserTestUtils.withNewTab(
      { gBrowser, url: TEST_URL },
      async function (browser) {
        const tab = gBrowser.getTabForBrowser(browser);

        is(
          window1,
          Services.wm.getMostRecentWindow("navigator:browser"),
          "The new window is the active one"
        );

        ok(!isMenuCheckedFor(window1), "RDM menu item is unchecked by default");

        const { ui } = await openRDM(tab);
        await waitForDeviceAndViewportState(ui);

        ok(isMenuCheckedFor(window1), "RDM menu item is checked with RDM open");

        await closeRDM(tab);

        ok(
          !isMenuCheckedFor(window1),
          "RDM menu item is unchecked with RDM closed"
        );
      }
    );

    await BrowserTestUtils.closeWindow(window1);

    is(
      window,
      Services.wm.getMostRecentWindow("navigator:browser"),
      "The original window is the active one"
    );

    ok(!isMenuCheckedFor(window), "RDM menu item is unchecked");
  },
  { onlyPrefAndTask: true }
);