Bug 1705697 - [devtools] Warning group messages shouldn't be repeatable. r=bomsy.

It could happen that 2 warning group messages could be added successively, before
the navigation message was emitted.
In the reducer, the second message would be seen the same as the first one, and
we'd try to increment the repeat count for the first one.
Unfortunately, the code was expecting a warning group to be created, and there
was an exception thrown as we couldn't retrieve it.
This is fixed by not allowing warning groups to be repeated.
A mocha test is added instead of a mochitest, as the issue would have been tricky
to trigger properly.

Differential Revision: https://phabricator.services.mozilla.com/D113276
This commit is contained in:
Nicolas Chevobbe 2021-04-28 08:10:13 +00:00
Родитель f673f5fd84
Коммит f10ee67c92
2 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -26,6 +26,9 @@ const {
stubPreparedMessages,
} = require("devtools/client/webconsole/test/node/fixtures/stubs/index");
const { MESSAGE_TYPE } = require("devtools/client/webconsole/constants");
const {
createWarningGroupMessage,
} = require("devtools/client/webconsole/utils/messages");
const expect = require("expect");
@ -246,6 +249,42 @@ describe("Message reducer:", () => {
expect(repeat[getLastMessage(getState()).id]).toBe(undefined);
});
it("does not increment repeat after adding similar warning group", () => {
const { dispatch, getState } = setupStore();
// Mocking a warning message that would create a warning group
const warningMessage = stubPreparedMessages.get(
"ReferenceError: asdf is not defined"
);
warningMessage.messageText =
"The resource at “https://evil.com” was blocked.";
warningMessage.category = "cookieBlockedPermission";
const type = MESSAGE_TYPE.CONTENT_BLOCKING_GROUP;
const firstMessageId = `${warningMessage.type}-${warningMessage.innerWindowID}`;
const message1 = createWarningGroupMessage(
firstMessageId,
type,
warningMessage
);
const secondMessageId = `${
warningMessage.type
}-${warningMessage.innerWindowID + 10}`;
const message2 = createWarningGroupMessage(
secondMessageId,
type,
warningMessage
);
dispatch(actions.messagesAdd([message1, message2]));
const messages = getAllMessagesById(getState());
expect(messages.size).toBe(2);
const repeat = getAllRepeatById(getState());
expect(Object.keys(repeat).length).toBe(0);
});
it("adds a message in response to console.clear()", () => {
const { dispatch, getState } = setupStore([]);

Просмотреть файл

@ -511,6 +511,7 @@ function isPacketPrivate(packet) {
function createWarningGroupMessage(id, type, firstMessage) {
return new ConsoleMessage({
id,
allowRepeating: false,
level: MESSAGE_LEVEL.WARN,
source: MESSAGE_SOURCE.CONSOLE_FRONTEND,
type,