Bug 1307928 - Add mocha tests for NewConsoleOutputWrapper queues; r=bgrins.

This required to add a couple new cases for require-hacker.

MozReview-Commit-ID: 9Qon1PNjdF7

--HG--
extra : rebase_source : 53808af32a325c1985443b9a26953b4065f7c835
This commit is contained in:
Nicolas Chevobbe 2018-03-06 16:53:05 +01:00
Родитель 91ccba1538
Коммит fafbf19092
4 изменённых файлов: 139 добавлений и 12 удалений

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

@ -0,0 +1,122 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Test utils.
const expect = require("expect");
const { stubPackets } =
require("devtools/client/webconsole/new-console-output/test/fixtures/stubs/index");
const {
getFirstMessage,
getLastMessage,
getMessageAt,
getPrivatePacket,
} = require("devtools/client/webconsole/new-console-output/test/helpers");
const NewConsoleOutputWrapper =
require("devtools/client/webconsole/new-console-output/new-console-output-wrapper");
const { messagesAdd } =
require("devtools/client/webconsole/new-console-output/actions/messages");
function getNewConsoleOutputWrapper() {
const jsterm = {
hud: {
proxy: {
releaseActor: () => {}
}
}
};
return new NewConsoleOutputWrapper(null, jsterm);
}
describe("NewConsoleOutputWrapper", () => {
it("clears queues when dispatchMessagesClear is called", () => {
const ncow = getNewConsoleOutputWrapper();
ncow.queuedMessageAdds.push({fakePacket: "message"});
ncow.queuedMessageUpdates.push({fakePacket: "message-update"});
ncow.queuedRequestUpdates.push({fakePacket: "request-update"});
ncow.dispatchMessagesClear();
expect(ncow.queuedMessageAdds.length).toBe(0);
expect(ncow.queuedMessageUpdates.length).toBe(0);
expect(ncow.queuedRequestUpdates.length).toBe(0);
});
it("removes private packets from message queue on dispatchPrivateMessagesClear", () => {
const ncow = getNewConsoleOutputWrapper();
const publicLog = stubPackets.get("console.log('mymap')");
ncow.queuedMessageAdds.push(
getPrivatePacket("console.trace()"),
publicLog,
getPrivatePacket("XHR POST request"),
);
ncow.dispatchPrivateMessagesClear();
expect(ncow.queuedMessageAdds).toEqual([publicLog]);
});
it("removes private packets from network update queue on dispatchPrivateMessagesClear",
() => {
const ncow = getNewConsoleOutputWrapper();
const postId = Symbol();
const getId = Symbol();
// Add messages in the store to make sure that update to private requests are
// removed from the queue.
ncow.getStore().dispatch(messagesAdd([
stubPackets.get("GET request"),
{...getPrivatePacket("XHR GET request"), actor: getId},
]));
// Add packet to the message queue to make sure that update to private requests are
// removed from the queue.
ncow.queuedMessageAdds.push(
{...getPrivatePacket("XHR POST request"), actor: postId},
);
const publicNetworkUpdate = stubPackets.get("GET request update");
ncow.queuedMessageUpdates.push(
publicNetworkUpdate,
{...getPrivatePacket("XHR GET request update"), networkInfo: {actor: getId}},
{...getPrivatePacket("XHR POST request update"), networkInfo: {actor: postId}},
);
ncow.dispatchPrivateMessagesClear();
expect(ncow.queuedMessageUpdates.length).toBe(1);
expect(ncow.queuedMessageUpdates).toEqual([publicNetworkUpdate]);
});
it("removes private packets from network request queue on dispatchPrivateMessagesClear",
() => {
const ncow = getNewConsoleOutputWrapper();
ncow.getStore().dispatch(messagesAdd([
stubPackets.get("GET request"),
getPrivatePacket("XHR GET request"),
getPrivatePacket("XHR POST request"),
]));
const state = ncow.getStore().getState();
const publicId = getFirstMessage(state).id;
const privateXhrGetId = getMessageAt(state, 1).id;
const privateXhrPostId = getLastMessage(state).id;
ncow.queuedRequestUpdates.push(
{id: publicId},
{id: privateXhrGetId},
{id: privateXhrPostId},
);
// ncow.queuedRequestUpdates.push({fakePacket: "request-update"});
ncow.dispatchPrivateMessagesClear();
expect(ncow.queuedRequestUpdates.length).toBe(1);
expect(ncow.queuedRequestUpdates).toEqual([{id: publicId}]);
});
});

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

@ -112,6 +112,17 @@ function clearPrefs() {
].forEach(prefsService.clearUserPref);
}
function getPrivatePacket(key) {
const packet = clonePacket(stubPackets.get(key));
if (packet.message) {
packet.message.private = true;
}
if (Object.getOwnPropertyNames(packet).includes("private")) {
packet.private = true;
}
return packet;
}
module.exports = {
clearPrefs,
clonePacket,
@ -119,6 +130,7 @@ module.exports = {
getFirstMessage,
getLastMessage,
getMessageAt,
getPrivatePacket,
prefsService,
setupActions,
setupStore,

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

@ -58,6 +58,10 @@ requireHacker.global_hook("default", (path, module) => {
return `() => {}`;
case "devtools/client/netmonitor/src/components/TabboxPanel":
return "{}";
case "devtools/client/webconsole/new-console-output/utils/context-menu":
return "{}";
case "devtools/shared/event-emitter":
return `module.exports = require("devtools-modules/src/utils/event-emitter")`;
}
// We need to rewrite all the modules assuming the root is mozilla-central and give them

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

@ -15,9 +15,9 @@ const {
getVisibleMessages,
} = require("devtools/client/webconsole/new-console-output/selectors/messages");
const {
clonePacket,
getFirstMessage,
getLastMessage,
getPrivatePacket,
setupActions,
setupStore,
} = require("devtools/client/webconsole/new-console-output/test/helpers");
@ -25,17 +25,6 @@ const { stubPackets } = require("devtools/client/webconsole/new-console-output/t
const expect = require("expect");
function getPrivatePacket(key) {
const packet = clonePacket(stubPackets.get(key));
if (packet.message) {
packet.message.private = true;
}
if (Object.getOwnPropertyNames(packet).includes("private")) {
packet.private = true;
}
return packet;
}
describe("private messages", () => {
let actions;
before(() => {