summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_message_categories.js
blob: 248da4533b5c9290c70fc07fc22675229cc4fa65 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check that messages are logged and observed with the correct category. See Bug 595934.
const { MESSAGE_CATEGORY } = require("resource://devtools/shared/constants.js");

const TEST_URI =
  "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for " +
  "bug 595934 - message categories coverage.";
const TESTS_PATH =
  "https://example.com/browser/devtools/client/webconsole/test/browser/";
const TESTS = [
  {
    // #0
    file: "test-message-categories-css-loader.html",
    category: "CSS Loader",
    matchString: "text/css",
    typeSelector: ".error",
  },
  {
    // #1
    file: "test-message-categories-imagemap.html",
    category: "Layout: ImageMap",
    matchString: 'shape="rect"',
    typeSelector: ".warn",
  },
  {
    // #2
    file: "test-message-categories-html.html",
    category: "HTML",
    matchString: "multipart/form-data",
    typeSelector: ".warn",
    onload() {
      SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
        const form = content.document.querySelector("form");
        form.submit();
      });
    },
  },
  {
    // #3
    file: "test-message-categories-workers.html",
    category: "Web Worker",
    matchString: "fooBarWorker",
    typeSelector: ".error",
  },
  {
    // #4
    file: "test-message-categories-malformedxml.xhtml",
    category: "malformed-xml",
    matchString: "no root element found",
    typeSelector: ".error",
  },
  {
    // #5
    file: "test-message-categories-svg.xhtml",
    category: "SVG",
    matchString: "fooBarSVG",
    typeSelector: ".warn",
  },
  {
    // #6
    file: "test-message-categories-css-parser.html",
    category: MESSAGE_CATEGORY.CSS_PARSER,
    matchString: "foobarCssParser",
    typeSelector: ".warn",
  },
  {
    // #7
    file: "test-message-categories-malformedxml-external.html",
    category: "malformed-xml",
    matchString: "</html>",
    typeSelector: ".error",
  },
  {
    // #8
    file: "test-message-categories-empty-getelementbyid.html",
    category: "DOM",
    matchString: "getElementById",
    typeSelector: ".warn",
  },
  {
    // #9
    file: "test-message-categories-canvas-css.html",
    category: MESSAGE_CATEGORY.CSS_PARSER,
    matchString: "foobarCanvasCssParser",
    typeSelector: ".warn",
  },
  {
    // #10
    file: "test-message-categories-image.html",
    category: "Image",
    matchString: "corrupt",
    typeSelector: ".error",
  },
];

add_task(async function () {
  requestLongerTimeout(2);

  // Disable bfcache for Fission for now.
  // If Fission is disabled, the pref is no-op.
  await pushPref("fission.bfcacheInParent", false);
  await pushPref("devtools.webconsole.filter.css", true);
  await pushPref("devtools.webconsole.filter.net", true);

  const hud = await openNewTabAndConsole(TEST_URI);
  for (let i = 0; i < TESTS.length; i++) {
    const test = TESTS[i];
    info("Running test #" + i);
    await runTest(test, hud);
  }

  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
      resolve()
    );
  });
});

async function runTest(test, hud) {
  const { file, category, matchString, typeSelector, onload } = test;

  const onMessageLogged = waitForMessageByType(hud, matchString, typeSelector);

  const onMessageObserved = new Promise(resolve => {
    Services.console.registerListener(function listener(subject) {
      if (!(subject instanceof Ci.nsIScriptError)) {
        return;
      }

      if (subject.category != category) {
        return;
      }

      ok(true, "Expected category [" + category + "] received in observer");
      Services.console.unregisterListener(listener);
      resolve();
    });
  });

  info("Load test file " + file);
  await navigateTo(TESTS_PATH + file);

  // Call test specific callback if defined
  if (onload) {
    onload();
  }

  info("Wait for log message to be observed with the correct category");
  await onMessageObserved;

  info(`Wait for log message ("${matchString}") to be displayed in the hud`);
  await onMessageLogged;
  ok(true, `Message "${matchString}" displayed`);
}