summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_toolbar_overflow_button_visibility.js
blob: f26699110903bf2d335cee2f2deb7edf4ea52440 (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
63
64
65
66
67
68
69
70
71
72
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test for the toolbox tabs rearrangement when the visibility of toolbox buttons were changed.

const { Toolbox } = require("resource://devtools/client/framework/toolbox.js");

add_task(async function () {
  const tab = await addTab("about:blank");
  const toolbox = await openToolboxForTab(
    tab,
    "options",
    Toolbox.HostType.BOTTOM
  );
  const toolboxButtonPreferences = toolbox.toolbarButtons.map(
    button => button.visibilityswitch
  );

  const win = getWindow(toolbox);
  const { outerWidth: originalWindowWidth, outerHeight: originalWindowHeight } =
    win;
  registerCleanupFunction(() => {
    for (const preference of toolboxButtonPreferences) {
      Services.prefs.clearUserPref(preference);
    }

    win.resizeTo(originalWindowWidth, originalWindowHeight);
  });

  const optionsTool = toolbox.getCurrentPanel();
  const checkButtons = optionsTool.panelWin.document.querySelectorAll(
    "#enabled-toolbox-buttons-box input[type=checkbox]"
  );

  info(
    "Test the count of shown devtools tab after making all buttons to be visible"
  );
  await resizeWindow(toolbox, 800);
  // Once, make all toolbox button to be invisible.
  setToolboxButtonsVisibility(checkButtons, false);
  // Get count of shown devtools tab elements.
  const initialTabCount = toolbox.doc.querySelectorAll(".devtools-tab").length;
  // Make all toolbox button to be visible.
  setToolboxButtonsVisibility(checkButtons, true);
  Assert.less(
    toolbox.doc.querySelectorAll(".devtools-tab").length,
    initialTabCount,
    "Count of shown devtools tab should decreased"
  );

  info(
    "Test the count of shown devtools tab after making all buttons to be invisible"
  );
  setToolboxButtonsVisibility(checkButtons, false);
  is(
    toolbox.doc.querySelectorAll(".devtools-tab").length,
    initialTabCount,
    "Count of shown devtools tab should be same to 1st count"
  );
});

function setToolboxButtonsVisibility(checkButtons, doVisible) {
  for (const checkButton of checkButtons) {
    if (checkButton.checked === doVisible) {
      continue;
    }

    checkButton.click();
  }
}