зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1125205
- Display console API messages from Shared or Service Workers to the webconsole, r=past
This commit is contained in:
Родитель
0a5868faff
Коммит
2c3fcd702a
|
@ -1530,6 +1530,9 @@ pref("devtools.webconsole.filter.info", true);
|
|||
pref("devtools.webconsole.filter.log", true);
|
||||
pref("devtools.webconsole.filter.secerror", true);
|
||||
pref("devtools.webconsole.filter.secwarn", true);
|
||||
pref("devtools.webconsole.filter.serviceworkers", false);
|
||||
pref("devtools.webconsole.filter.sharedworkers", false);
|
||||
pref("devtools.webconsole.filter.windowlessworkers", false);
|
||||
|
||||
// Remember the Browser Console filters
|
||||
pref("devtools.browserconsole.filter.network", true);
|
||||
|
@ -1548,6 +1551,9 @@ pref("devtools.browserconsole.filter.info", true);
|
|||
pref("devtools.browserconsole.filter.log", true);
|
||||
pref("devtools.browserconsole.filter.secerror", true);
|
||||
pref("devtools.browserconsole.filter.secwarn", true);
|
||||
pref("devtools.browserconsole.filter.serviceworkers", true);
|
||||
pref("devtools.browserconsole.filter.sharedworkers", true);
|
||||
pref("devtools.browserconsole.filter.windowlessworkers", true);
|
||||
|
||||
// Text size in the Web Console. Use 0 for the system default size.
|
||||
pref("devtools.webconsole.fontSize", 0);
|
||||
|
|
|
@ -76,6 +76,7 @@ support-files =
|
|||
test-console-extras.html
|
||||
test-console-replaced-api.html
|
||||
test-console.html
|
||||
test-console-workers.html
|
||||
test-console-table.html
|
||||
test-console-output-02.html
|
||||
test-console-output-03.html
|
||||
|
@ -317,6 +318,7 @@ skip-if = e10s # Bug 1042253 - webconsole tests disabled with e10s
|
|||
[browser_webconsole_completion.js]
|
||||
[browser_webconsole_console_extras.js]
|
||||
[browser_webconsole_console_logging_api.js]
|
||||
[browser_webconsole_console_logging_workers_api.js]
|
||||
[browser_webconsole_count.js]
|
||||
[browser_webconsole_dont_navigate_on_doubleclick.js]
|
||||
[browser_webconsole_execution_scope.js]
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Tests that the basic console.log()-style APIs and filtering work for sharedWorkers
|
||||
|
||||
"use strict";
|
||||
|
||||
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-workers.html";
|
||||
|
||||
function pushPrefEnv()
|
||||
{
|
||||
let deferred = promise.defer();
|
||||
let options = {'set': [["dom.workers.sharedWorkers.enabled", true]]};
|
||||
SpecialPowers.pushPrefEnv(options, deferred.resolve);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
yield pushPrefEnv();
|
||||
yield loadTab(TEST_URI);
|
||||
|
||||
let hud = yield openConsole();
|
||||
let outputNode = hud.outputNode;
|
||||
|
||||
yield waitForMessages({
|
||||
webconsole: hud,
|
||||
messages: [{
|
||||
text: "foo-bar-shared-worker"
|
||||
}],
|
||||
});
|
||||
|
||||
hud.setFilterState('sharedworkers', false);
|
||||
|
||||
is(outputNode.querySelectorAll(".filtered-by-type").length, 1,
|
||||
"1 message hidden for sharedworkers (logging turned off)")
|
||||
|
||||
hud.setFilterState('sharedworkers', true);
|
||||
|
||||
is(outputNode.querySelectorAll(".filtered-by-type").length, 0,
|
||||
"1 message shown for sharedworkers (logging turned off)")
|
||||
});
|
|
@ -0,0 +1,13 @@
|
|||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!DOCTYPE HTML>
|
||||
<html dir="ltr" xml:lang="en-US" lang="en-US"><head>
|
||||
<meta charset="utf-8">
|
||||
<title>Console test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
var sw = new SharedWorker('data:application/javascript,console.log("foo-bar-shared-worker");');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
const {Cc, Ci, Cu} = require("chrome");
|
||||
|
||||
let WebConsoleUtils = require("devtools/toolkit/webconsole/utils").Utils;
|
||||
const {Utils: WebConsoleUtils, CONSOLE_WORKER_IDS} = require("devtools/toolkit/webconsole/utils");
|
||||
|
||||
loader.lazyServiceGetter(this, "clipboardHelper",
|
||||
"@mozilla.org/widget/clipboardhelper;1",
|
||||
|
@ -138,6 +138,10 @@ const LEVELS = {
|
|||
count: SEVERITY_LOG
|
||||
};
|
||||
|
||||
// This array contains the prefKey for the workers and it must keep them in the
|
||||
// same order as CONSOLE_WORKER_IDS
|
||||
const WORKERTYPES_PREFKEYS = [ 'sharedworkers', 'serviceworkers', 'windowlessworkers' ];
|
||||
|
||||
// The lowest HTTP response code (inclusive) that is considered an error.
|
||||
const MIN_HTTP_ERROR_CODE = 400;
|
||||
// The highest HTTP response code (inclusive) that is considered an error.
|
||||
|
@ -649,7 +653,8 @@ WebConsoleFrame.prototype = {
|
|||
{
|
||||
let prefs = ["network", "networkinfo", "csserror", "cssparser", "csslog",
|
||||
"exception", "jswarn", "jslog", "error", "info", "warn", "log",
|
||||
"secerror", "secwarn", "netwarn", "netxhr"];
|
||||
"secerror", "secwarn", "netwarn", "netxhr", "sharedworkers",
|
||||
"serviceworkers", "windowlessworkers"];
|
||||
for (let pref of prefs) {
|
||||
this.filterPrefs[pref] = Services.prefs
|
||||
.getBoolPref(this._filterPrefsPrefix + pref);
|
||||
|
@ -1026,8 +1031,11 @@ WebConsoleFrame.prototype = {
|
|||
// (filter="error", filter="cssparser", etc.) and add or remove the
|
||||
// "filtered-by-type" class, which turns on or off the display.
|
||||
|
||||
let attribute = WORKERTYPES_PREFKEYS.indexOf(aPrefKey) == -1
|
||||
? 'filter' : 'workerType';
|
||||
|
||||
let xpath = ".//*[contains(@class, 'message') and " +
|
||||
"@filter='" + aPrefKey + "']";
|
||||
"@" + attribute + "='" + aPrefKey + "']";
|
||||
let result = doc.evaluate(xpath, outputNode, null,
|
||||
Ci.nsIDOMXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
for (let i = 0; i < result.snapshotLength; i++) {
|
||||
|
@ -1088,6 +1096,12 @@ WebConsoleFrame.prototype = {
|
|||
isFiltered = true;
|
||||
}
|
||||
|
||||
// Filter by worker type
|
||||
if ("workerType" in aNode && !this.getFilterState(aNode.workerType)) {
|
||||
aNode.classList.add("filtered-by-type");
|
||||
isFiltered = true;
|
||||
}
|
||||
|
||||
// Filter on the search string.
|
||||
let search = this.filterBox.value;
|
||||
let text = aNode.clipboardText;
|
||||
|
@ -1365,6 +1379,12 @@ WebConsoleFrame.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
let workerTypeID = CONSOLE_WORKER_IDS.indexOf(aMessage.workerType);
|
||||
if (workerTypeID != -1) {
|
||||
node.workerType = WORKERTYPES_PREFKEYS[workerTypeID];
|
||||
node.setAttribute('workerType', WORKERTYPES_PREFKEYS[workerTypeID]);
|
||||
}
|
||||
|
||||
return node;
|
||||
},
|
||||
|
||||
|
|
|
@ -161,6 +161,13 @@ function goUpdateConsoleCommands() {
|
|||
prefKey="info"/>
|
||||
<menuitem label="&btnConsoleLog;" type="checkbox" autocheck="false"
|
||||
prefKey="log"/>
|
||||
<menuseparator />
|
||||
<menuitem label="&btnConsoleSharedWorkers;" type="checkbox"
|
||||
autocheck="false" prefKey="sharedworkers"/>
|
||||
<menuitem label="&btnConsoleServiceWorkers;" type="checkbox"
|
||||
autocheck="false" prefKey="serviceworkers"/>
|
||||
<menuitem label="&btnConsoleWindowlessWorkers;" type="checkbox"
|
||||
autocheck="false" prefKey="windowlessworkers"/>
|
||||
</menupopup>
|
||||
</toolbarbutton>
|
||||
</hbox>
|
||||
|
|
|
@ -76,6 +76,16 @@
|
|||
<!ENTITY btnConsoleXhr "XHR">
|
||||
<!ENTITY btnConsoleReflows "Reflows">
|
||||
|
||||
<!-- LOCALIZATION NODE (btnConsoleSharedWorkers) the term "Shared Workers"
|
||||
- should not be translated. -->
|
||||
<!ENTITY btnConsoleSharedWorkers "Shared Workers">
|
||||
<!-- LOCALIZATION NODE (btnConsoleServiceWorkers) the term "Service Workers"
|
||||
- should not be translated. -->
|
||||
<!ENTITY btnConsoleServiceWorkers "Service Workers">
|
||||
<!-- LOCALIZATION NODE (btnConsoleWindowlessWorkers) the term "Workers"
|
||||
- should not be translated. -->
|
||||
<!ENTITY btnConsoleWindowlessWorkers "Add-on or Chrome Workers">
|
||||
|
||||
<!ENTITY filterOutput.placeholder "Filter output">
|
||||
<!ENTITY btnClear.label "Clear">
|
||||
<!ENTITY btnClear.tooltip "Clear the Web Console output">
|
||||
|
|
|
@ -526,7 +526,7 @@ private:
|
|||
id = NS_LITERAL_STRING("Worker");
|
||||
}
|
||||
|
||||
mCallData->SetIDs(id, frame.mFilename);
|
||||
mCallData->SetIDs(frame.mFilename, id);
|
||||
}
|
||||
|
||||
// Now we could have the correct window (if we are not window-less).
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
if (aTopic == "console-api-log-event") {
|
||||
var obj = aSubject.wrappedJSObject;
|
||||
is (obj.arguments[0], "Hello world from a SharedWorker!", "A message from a SharedWorker \\o/");
|
||||
is (aData, "SharedWorker", "The ID is SharedWorker");
|
||||
is (obj.ID, "http://mochi.test:8888/tests/dom/workers/test/sharedWorker_console.js", "The ID is SharedWorker");
|
||||
is (obj.innerID, "SharedWorker", "The ID is SharedWorker");
|
||||
is (order++, 1, "Then a log message.");
|
||||
|
||||
SpecialPowers.removeObserver(this, "console-api-log-event");
|
||||
|
|
|
@ -33,7 +33,7 @@ XPCOMUtils.defineLazyGetter(this, "events", () => {
|
|||
|
||||
for (let name of ["WebConsoleUtils", "ConsoleServiceListener",
|
||||
"ConsoleAPIListener", "addWebConsoleCommands", "JSPropertyProvider",
|
||||
"ConsoleReflowListener"]) {
|
||||
"ConsoleReflowListener", "CONSOLE_WORKER_IDS"]) {
|
||||
Object.defineProperty(this, name, {
|
||||
get: function(prop) {
|
||||
if (prop == "WebConsoleUtils") {
|
||||
|
@ -1432,6 +1432,10 @@ WebConsoleActor.prototype =
|
|||
function WCA_prepareConsoleMessageForRemote(aMessage)
|
||||
{
|
||||
let result = WebConsoleUtils.cloneObject(aMessage);
|
||||
|
||||
result.workerType = CONSOLE_WORKER_IDS.indexOf(result.innerID) == -1
|
||||
? 'none' : result.innerID;
|
||||
|
||||
delete result.wrappedJSObject;
|
||||
delete result.ID;
|
||||
delete result.innerID;
|
||||
|
|
|
@ -39,6 +39,8 @@ const CONSOLE_ENTRY_THRESHOLD = 5;
|
|||
// with numeric values that wouldn't be tallied towards MAX_AUTOCOMPLETIONS.
|
||||
const MAX_AUTOCOMPLETE_ATTEMPTS = exports.MAX_AUTOCOMPLETE_ATTEMPTS = 100000;
|
||||
|
||||
const CONSOLE_WORKER_IDS = exports.CONSOLE_WORKER_IDS = [ 'SharedWorker', 'ServiceWorker', 'Worker' ];
|
||||
|
||||
// Prevent iterating over too many properties during autocomplete suggestions.
|
||||
const MAX_AUTOCOMPLETIONS = exports.MAX_AUTOCOMPLETIONS = 1500;
|
||||
|
||||
|
@ -1446,7 +1448,7 @@ ConsoleAPIListener.prototype =
|
|||
}
|
||||
|
||||
let apiMessage = aMessage.wrappedJSObject;
|
||||
if (this.window) {
|
||||
if (this.window && CONSOLE_WORKER_IDS.indexOf(apiMessage.innerID) == -1) {
|
||||
let msgWindow = Services.wm.getCurrentInnerWindowWithId(apiMessage.innerID);
|
||||
if (!msgWindow || !this.layoutHelpers.isIncludedInTopLevelWindow(msgWindow)) {
|
||||
// Not the same window!
|
||||
|
@ -1486,10 +1488,21 @@ ConsoleAPIListener.prototype =
|
|||
});
|
||||
}
|
||||
|
||||
CONSOLE_WORKER_IDS.forEach((id) => {
|
||||
messages = messages.concat(ConsoleAPIStorage.getEvents(id));
|
||||
});
|
||||
|
||||
if (this.consoleID) {
|
||||
messages = messages.filter((m) => m.consoleID == this.consoleID);
|
||||
}
|
||||
|
||||
// ConsoleAPIStorage gives up messages sorted, but we ask for different
|
||||
// blocks of events and we must sort them again in order to show them in the
|
||||
// proper order.
|
||||
messages = messages.sort(function(a, b) {
|
||||
return a.timeStamp - b.timeStamp;
|
||||
});
|
||||
|
||||
if (aIncludePrivate) {
|
||||
return messages;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче