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

// Tests the DEVTOOLS_JAVASCRIPT_ERROR_DISPLAYED telemetry event.

"use strict";

const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>document()</script>`;

add_task(async function () {
  startTelemetry();

  const hud = await openNewTabAndConsole(TEST_URI);

  info(
    "Check that the error message is logged in telemetry with the expected key"
  );
  await waitFor(() => findErrorMessage(hud, "is not a function"));
  checkErrorDisplayedTelemetry("JSMSG_NOT_FUNCTION", 1);

  await reloadBrowser();

  info("Reloading the page (and having the same error) increments the sum");
  await waitFor(() => findErrorMessage(hud, "is not a function"));
  checkErrorDisplayedTelemetry("JSMSG_NOT_FUNCTION", 2);

  info(
    "Evaluating an expression resulting in the same error increments the sum"
  );
  await executeAndWaitForErrorMessage(
    hud,
    "window()",
    "window is not a function"
  );
  checkErrorDisplayedTelemetry("JSMSG_NOT_FUNCTION", 3);

  info(
    "Evaluating an expression resulting in another error is logged in telemetry"
  );
  await executeAndWaitForErrorMessage(
    hud,
    `"a".repeat(-1)`,
    "repeat count must be non-negative"
  );
  checkErrorDisplayedTelemetry("JSMSG_NEGATIVE_REPETITION_COUNT", 1);

  await executeAndWaitForErrorMessage(
    hud,
    `"b".repeat(-1)`,
    "repeat count must be non-negative"
  );
  checkErrorDisplayedTelemetry("JSMSG_NEGATIVE_REPETITION_COUNT", 2);
});

function checkErrorDisplayedTelemetry(key, count) {
  checkTelemetry(
    "DEVTOOLS_JAVASCRIPT_ERROR_DISPLAYED",
    key,
    { 0: 0, 1: count, 2: 0 },
    "array"
  );
}