Bug 1441864 - Fix ContentProcessForward data handling; r=bgrins.

In ContentProcessForward, we listen for console-api-log-event in order
to pass data to the Browser console and Browser toolbox.
But the data is modified and properties are cherry-picked from the original
event, missing some properties probably introduced later like `counter`,
`prefix`, `private`, …
The fix consists in cloning the original event data and only overriding what
needs to be overridden.

MozReview-Commit-ID: 6jSfiRxcHQa

--HG--
extra : rebase_source : 3a4c61c0eb14ccdf584630c508dc439b7718ee45
extra : source : d266983f9cdeba0381f11e00bb6b271ccda561c1
This commit is contained in:
Nicolas Chevobbe 2018-03-01 10:23:58 +01:00
parent 34872b6d20
commit 90c41237b2
3 changed files with 60 additions and 5 deletions

View File

@ -178,6 +178,7 @@ skip-if = true # Bug 1437843
[browser_console_nsiconsolemessage.js]
[browser_console_open_or_focus.js]
[browser_console_restore.js]
[browser_console_webconsole_console_api_calls.js]
[browser_console_webconsole_ctrlw_close_tab.js]
[browser_console_webconsole_iframe_messages.js]
[browser_console_webconsole_private_browsing.js]

View File

@ -0,0 +1,55 @@
/* 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/. */
// Test that console API calls in the content page appear in the browser console.
"use strict";
const TEST_URI = `data:text/html,<meta charset=utf8>console API calls`
add_task(async function() {
await addTab(TEST_URI);
const hud = await HUDService.toggleBrowserConsole();
const contentArgs = {
log: "MyLog",
warn: "MyWarn",
error: "MyError",
info: "MyInfo",
debug: "MyDebug",
counterName: "MyCounter",
timerName: "MyTimer",
};
const expectedMessages = [
contentArgs.log,
contentArgs.warn,
contentArgs.error,
contentArgs.info,
contentArgs.debug,
`${contentArgs.counterName}: 1`,
`${contentArgs.timerName}:`,
`console.trace`,
`Assertion failed`,
];
const onAllMessages = Promise.all(expectedMessages.map(m => waitForMessage(hud, m)));
ContentTask.spawn(gBrowser.selectedBrowser, contentArgs, function (args) {
content.console.log(args.log);
content.console.warn(args.warn);
content.console.error(args.error);
content.console.info(args.info);
content.console.debug(args.debug);
content.console.count(args.counterName);
content.console.time(args.timerName);
content.console.timeEnd(args.timerName);
content.console.trace();
content.console.assert(false, "err");
});
await onAllMessages;
ok(true, "Expected messages are displayed in the browser console");
});

View File

@ -55,14 +55,13 @@ ContentProcessForward.prototype = {
let consoleMsg = subject.wrappedJSObject;
let msgData = {
level: consoleMsg.level,
...consoleMsg,
arguments: [],
filename: consoleMsg.filename.substring(0, MSG_MGR_CONSOLE_INFO_MAX),
lineNumber: consoleMsg.lineNumber,
functionName: consoleMsg.functionName &&
consoleMsg.functionName.substring(0, MSG_MGR_CONSOLE_INFO_MAX),
timeStamp: consoleMsg.timeStamp,
addonId: consoleMsg.addonId,
arguments: [],
// Prevents cyclic object error when using msgData in sendAsyncMessage
wrappedJSObject: null,
};
// We can't send objects over the message manager, so we sanitize