summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_filters_persist.js
blob: a67f8f53ed0afefaf23a478f6db659483f1ec85d (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/ */

// Tests all filters persist.

"use strict";

const TEST_URI =
  "http://example.com/browser/devtools/client/webconsole/" +
  "test/browser/test-console-filters.html";

add_task(async function () {
  let hud = await openNewTabAndConsole(TEST_URI);

  let filterButtons = await getFilterButtons(hud);
  info("Disable all filters");
  filterButtons.forEach(filterButton => {
    if (filterIsEnabled(filterButton)) {
      filterButton.click();
    }
  });

  info("Close and re-open the console");
  await closeTabAndToolbox();
  hud = await openNewTabAndConsole(TEST_URI);

  info("Check that all filters are disabled, and enable them");
  filterButtons = await getFilterButtons(hud);
  filterButtons.forEach(filterButton => {
    ok(!filterIsEnabled(filterButton), "filter is disabled");
    filterButton.click();
  });

  // Wait for the CSS warning to be displayed so we don't have a pending promise.
  await waitFor(() =>
    findWarningMessage(hud, "Expected color but found ‘blouge’")
  );

  info("Close and re-open the console");
  await closeTabAndToolbox();
  hud = await openNewTabAndConsole(TEST_URI);

  info("Check that all filters are enabled");
  filterButtons = await getFilterButtons(hud);
  filterButtons.forEach(filterButton => {
    ok(filterIsEnabled(filterButton), "filter is enabled");
  });

  // Wait for the CSS warning to be displayed so we don't have a pending promise.
  await waitFor(() =>
    findWarningMessage(hud, "Expected color but found ‘blouge’")
  );

  // Check that the ui settings were persisted.
  await closeTabAndToolbox();
});

async function getFilterButtons(hud) {
  const outputNode = hud.ui.outputNode;

  info("Wait for console filterbar to appear");
  const filterBar = await waitFor(() => {
    return outputNode.querySelector(".webconsole-filterbar-secondary");
  });
  ok(filterBar, "Filter bar is shown when filter icon is clicked.");

  return filterBar.querySelectorAll(".devtools-togglebutton");
}

function filterIsEnabled(button) {
  return button.getAttribute("aria-pressed") === "true";
}