summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive.html/test/browser/browser_menu_item_01.js
blob: 8e1c1c4cdb3c42444a9de20ea17d0560e570c035 (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
60
61
62
/* 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 tabs.

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

const tabUtils = require("sdk/tabs/utils");
const { startup } = require("sdk/window/helpers");

const activateTab = (tab) => new Promise(resolve => {
  let { tabContainer } = tabUtils.getOwnerWindow(tab).gBrowser;

  tabContainer.addEventListener("TabSelect", function listener({type}) {
    tabContainer.removeEventListener(type, listener);
    resolve();
  });

  tabUtils.activateTab(tab);
});

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

add_task(function* () {
  yield startup(window);

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

  const tab = yield addTab(TEST_URL);

  ok(!isMenuChecked(),
    "RDM menu item is unchecked for new tab");

  yield openRDM(tab);

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

  const tab2 = yield addTab(TEST_URL);

  ok(!isMenuChecked(),
    "RDM menu item is unchecked for new tab");

  yield activateTab(tab);

  ok(isMenuChecked(),
    "RDM menu item is checked for the tab where RDM is open");

  yield closeRDM(tab);

  ok(!isMenuChecked(),
    "RDM menu item is unchecked after RDM is closed");

  yield removeTab(tab);
  yield removeTab(tab2);
});