Bug 1653598 - Add a constant for CSS Parser message category. r=jdescottes.

Differential Revision: https://phabricator.services.mozilla.com/D84123
This commit is contained in:
Nicolas Chevobbe 2020-07-20 08:15:03 +00:00
parent 12c7ce039a
commit 7fa11883f2
10 changed files with 44 additions and 19 deletions

View File

@ -4,6 +4,7 @@
"use strict";
// Check that messages are logged and observed with the correct category. See Bug 595934.
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
const TEST_URI =
"data:text/html;charset=utf-8,Web Console test for " +
@ -56,7 +57,7 @@ const TESTS = [
{
// #6
file: "test-message-categories-css-parser.html",
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
matchString: "foobarCssParser",
},
{
@ -74,7 +75,7 @@ const TESTS = [
{
// #9
file: "test-message-categories-canvas-css.html",
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
matchString: "foobarCanvasCssParser",
},
{

View File

@ -16,6 +16,8 @@ const {
TYPES: { CSS_MESSAGE },
} = require("devtools/server/actors/resources/index");
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
class CSSMessageWatcher extends nsIConsoleListenerWatcher {
/**
* Start watching for all CSS messages related to a given Target Actor.
@ -50,7 +52,7 @@ class CSSMessageWatcher extends nsIConsoleListenerWatcher {
if (
// We only care about CSS Parser nsIScriptError
!(message instanceof Ci.nsIScriptError) ||
message.category !== "CSS Parser"
message.category !== MESSAGE_CATEGORY.CSS_PARSER
) {
return false;
}

View File

@ -20,6 +20,7 @@ const {
const {
TYPES: { ERROR_MESSAGE },
} = require("devtools/server/actors/resources/index");
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
const PLATFORM_SPECIFIC_CATEGORIES = [
"XPConnect JavaScript",
@ -69,7 +70,7 @@ class ErrorMessageWatcher extends nsIConsoleListenerWatcher {
*/
isCategoryAllowed(targetActor, category) {
// CSS Parser errors will be handled by the CSSMessageWatcher.
if (!category || category === "CSS Parser") {
if (!category || category === MESSAGE_CATEGORY.CSS_PARSER) {
return false;
}

View File

@ -101,6 +101,12 @@ loader.lazyRequireGetter(
true
);
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
loader.lazyRequireGetter(
this,
"MESSAGE_CATEGORY",
"devtools/shared/constants",
true
);
loader.lazyRequireGetter(
this,
"stringToCauseType",
@ -1709,7 +1715,7 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
columnNumber = stack[0].columnNumber;
}
const isCSSMessage = pageError.category === "CSS Parser";
const isCSSMessage = pageError.category === MESSAGE_CATEGORY.CSS_PARSER;
const result = {
errorMessage: this._createStringGrip(pageError.errorMessage),

View File

@ -105,9 +105,18 @@ const SIMULATION_TYPE = {
CONTRAST_LOSS: "CONTRAST_LOSS",
};
exports.accessibility = {
AUDIT_TYPE,
ISSUE_TYPE,
SCORES,
SIMULATION_TYPE,
/* WebConsole Panel ====================================================== */
const MESSAGE_CATEGORY = {
CSS_PARSER: "CSS Parser",
};
module.exports = {
accessibility: {
AUDIT_TYPE,
ISSUE_TYPE,
SCORES,
SIMULATION_TYPE,
},
MESSAGE_CATEGORY,
};

View File

@ -7,6 +7,7 @@
const {
ResourceWatcher,
} = require("devtools/shared/resources/resource-watcher");
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
module.exports = async function({
targetList,
@ -39,7 +40,7 @@ module.exports = async function({
const cachedMessages = [];
for (let message of messages) {
if (message.pageError?.category !== "CSS Parser") {
if (message.pageError?.category !== MESSAGE_CATEGORY.CSS_PARSER) {
continue;
}
@ -61,7 +62,7 @@ module.exports = async function({
// CSS Messages are emited fron the PageError listener, which also send regular errors
// that we need to filter out.
webConsoleFront.on("pageError", message => {
if (message.pageError.category !== "CSS Parser") {
if (message.pageError.category !== MESSAGE_CATEGORY.CSS_PARSER) {
return;
}

View File

@ -7,6 +7,7 @@
const {
ResourceWatcher,
} = require("devtools/shared/resources/resource-watcher");
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
module.exports = async function({
targetList,
@ -50,7 +51,7 @@ module.exports = async function({
(webConsoleFront.traits.newCacheStructure ||
!message._type ||
message._type == "PageError") &&
message.pageError.category !== "CSS Parser"
message.pageError.category !== MESSAGE_CATEGORY.CSS_PARSER
);
});
@ -72,7 +73,7 @@ module.exports = async function({
webConsoleFront.on("pageError", message => {
// On server < v79, we're getting CSS Messages that we need to filter out.
if (message.pageError.category === "CSS Parser") {
if (message.pageError.category === MESSAGE_CATEGORY.CSS_PARSER) {
return;
}

View File

@ -9,6 +9,7 @@
const {
ResourceWatcher,
} = require("devtools/shared/resources/resource-watcher");
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
// Create a simple server so we have a nice sourceName in the resources packets.
const httpServer = createTestHTTPServer();
@ -138,7 +139,7 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
pageError: {
errorMessage: /Expected color but found bloup/,
sourceName: /test_css_messages/,
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
timeStamp: /^\d+$/,
error: false,
warning: true,
@ -149,7 +150,7 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
pageError: {
errorMessage: /Error in parsing value for width/,
sourceName: /test_css_messages/,
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
timeStamp: /^\d+$/,
error: false,
warning: true,
@ -159,7 +160,7 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
pageError: {
errorMessage: /Error in parsing value for height/,
sourceName: /test_css_messages/,
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
timeStamp: /^\d+$/,
error: false,
warning: true,

View File

@ -14,6 +14,8 @@
<script class="testbody" type="application/javascript">
"use strict";
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
const previousEnabled = window.docShell.cssErrorReportingEnabled;
window.docShell.cssErrorReportingEnabled = true;
@ -33,7 +35,7 @@ function doPageErrors() {
{
errorMessage: /fooColor/,
sourceName: /.+/,
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
timeStamp: /^\d+$/,
error: false,
warning: true,

View File

@ -14,6 +14,7 @@
<script class="testbody" type="text/javascript">
"use strict";
const { MESSAGE_CATEGORY } = require("devtools/shared/constants");
SimpleTest.waitForExplicitFinish();
const previousEnabled = window.docShell.cssErrorReportingEnabled;
@ -32,7 +33,7 @@ function doPageErrors() {
"document.body.style.color = 'fooColor';": {
errorMessage: /fooColor/,
sourceName: /test_page_errors/,
category: "CSS Parser",
category: MESSAGE_CATEGORY.CSS_PARSER,
timeStamp: /^\d+$/,
error: false,
warning: true,