summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_error_count_reset_on_navigation.js
blob: ebf862be88b952240288551921e14f2d3f9db350 (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
73
74
75
76
77
78
79
80
81
82
83
84
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";
// Test for error count in toolbar when navigating and webconsole isn't enabled
const TEST_URI = `http://example.org/document-builder.sjs?html=<meta charset=utf8></meta>
<script>
  console.error("Cache Error1");
  console.exception(false, "Cache Exception");
  console.warn("Cache warning");
  console.assert(false, "Cache assert");
  cache.unknown.access
</script>`;

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

add_task(async function () {
  // Disable bfcache for Fission for now.
  // If Fission is disabled, the pref is no-op.
  await SpecialPowers.pushPrefEnv({
    set: [["fission.bfcacheInParent", false]],
  });

  // Make sure we start the test with the split console disabled.
  // ⚠️ In this test it's important to _not_ enable the console.
  await pushPref("devtools.toolbox.splitconsole.open", false);
  const tab = await addTab(TEST_URI);

  const toolbox = await openToolboxForTab(
    tab,
    "inspector",
    Toolbox.HostType.BOTTOM
  );

  info("Check for cached errors");
  // (console.error + console.exception + console.assert + error)
  const expectedErrorCount = 4;

  await waitFor(() => getErrorIcon(toolbox));
  is(
    getErrorIcon(toolbox).getAttribute("title"),
    "Show Split Console",
    "Icon has expected title"
  );
  is(
    getErrorIconCount(toolbox),
    expectedErrorCount,
    "Correct count is displayed"
  );

  info("Add another error so we have a different count");
  ContentTask.spawn(tab.linkedBrowser, null, function () {
    content.console.error("Live Error1");
  });

  const newExpectedErrorCount = expectedErrorCount + 1;
  await waitFor(() => getErrorIconCount(toolbox) === newExpectedErrorCount);

  info(
    "Reload the page and check that the error icon has the expected content"
  );
  await reloadBrowser();

  await waitFor(
    () => getErrorIconCount(toolbox) === expectedErrorCount,
    "Error count is cleared on navigation and then populated with the expected number of errors"
  );
  ok(true, "Correct count is displayed");

  info(
    "Navigate to an error-less page and check that the error icon is hidden"
  );
  await navigateTo(`data:text/html;charset=utf8,No errors`);
  await waitFor(
    () => !getErrorIcon(toolbox),
    "Error count is cleared on navigation"
  );
  ok(
    true,
    "The error icon was hidden when navigating to a new page without errors"
  );

  toolbox.destroy();
});