зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1712591 - [devtools] Expose hasNativeConsoleAPI via DOCUMENT_EVENT's dom-complete resource. r=nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D115824
This commit is contained in:
Родитель
85a74c965b
Коммит
29f76f8a11
|
@ -36,6 +36,8 @@ class DocumentEventWatcher {
|
|||
// This will be `true` when the user selected a document in the frame picker tool,
|
||||
// in the toolbox toolbar.
|
||||
isFrameSwitching,
|
||||
// This is only passed for dom-complete event
|
||||
hasNativeConsoleAPI,
|
||||
// This is only passed for will-navigate event
|
||||
newURI,
|
||||
} = {}
|
||||
|
@ -57,6 +59,10 @@ class DocumentEventWatcher {
|
|||
// only send `newURI` on will navigate so we don't make the payload bigger for
|
||||
// other events
|
||||
newURI: name === "will-navigate" ? newURI : null,
|
||||
// only send `hasNativeConsoleAPI` on dom complete so we don't make the payload bigger for
|
||||
// other events
|
||||
hasNativeConsoleAPI:
|
||||
name == "dom-complete" ? hasNativeConsoleAPI : null,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
* 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/. */
|
||||
|
||||
/* global XPCNativeWrapper */
|
||||
|
||||
"use strict";
|
||||
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
|
@ -153,7 +155,37 @@ DocumentEventsListener.prototype = {
|
|||
// 'complete' and the corresponding readystatechange event is thrown
|
||||
const window = event.target.defaultView;
|
||||
const time = window.performance.timing.domComplete;
|
||||
this.emit("dom-complete", { time, isFrameSwitching });
|
||||
this.emit("dom-complete", {
|
||||
time,
|
||||
isFrameSwitching,
|
||||
hasNativeConsoleAPI: this.hasNativeConsoleAPI(window),
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Tells if the window.console object is native or overwritten by script in
|
||||
* the page.
|
||||
*
|
||||
* @param nsIDOMWindow window
|
||||
* The window object you want to check.
|
||||
* @return boolean
|
||||
* True if the window.console object is native, or false otherwise.
|
||||
*/
|
||||
hasNativeConsoleAPI(window) {
|
||||
let isNative = false;
|
||||
try {
|
||||
// We are very explicitly examining the "console" property of
|
||||
// the non-Xrayed object here.
|
||||
const console = window.wrappedJSObject.console;
|
||||
// In xpcshell tests, console ends up being undefined and XPCNativeWrapper
|
||||
// crashes in debug builds.
|
||||
if (console) {
|
||||
isNative = new XPCNativeWrapper(console).IS_NATIVE_CONSOLE === true;
|
||||
}
|
||||
} catch (ex) {
|
||||
// ignore
|
||||
}
|
||||
return isNative;
|
||||
},
|
||||
|
||||
destroy() {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
add_task(async function() {
|
||||
await testDocumentEventResources();
|
||||
await testDocumentEventResourcesWithIgnoreExistingResources();
|
||||
await testDomCompleteWithOverloadedConsole();
|
||||
|
||||
// Enable server side target switching for next test
|
||||
// as the regression it tracks only occurs with server side target switching enabled
|
||||
|
@ -315,6 +316,36 @@ async function testCrossOriginNavigation() {
|
|||
await commands.destroy();
|
||||
}
|
||||
|
||||
async function testDomCompleteWithOverloadedConsole() {
|
||||
info("Test dom-complete with an overloaded console object");
|
||||
|
||||
const tab = await addTab(
|
||||
"data:text/html,<script>window.console = {};</script>"
|
||||
);
|
||||
|
||||
const { client, resourceCommand, targetCommand } = await initResourceCommand(
|
||||
tab
|
||||
);
|
||||
|
||||
info("Check that all DOCUMENT_EVENTS are fired for the already loaded page");
|
||||
const documentEvents = [];
|
||||
await resourceCommand.watchResources([resourceCommand.TYPES.DOCUMENT_EVENT], {
|
||||
onAvailable: resources => documentEvents.push(...resources),
|
||||
});
|
||||
is(documentEvents.length, 3, "Existing document events are fired");
|
||||
|
||||
const domComplete = documentEvents[2];
|
||||
is(domComplete.name, "dom-complete", "the last resource is the dom-complete");
|
||||
is(
|
||||
domComplete.hasNativeConsoleAPI,
|
||||
false,
|
||||
"the console object is reported to be overloaded"
|
||||
);
|
||||
|
||||
targetCommand.destroy();
|
||||
await client.close();
|
||||
}
|
||||
|
||||
async function assertPromises(
|
||||
commands,
|
||||
targetBeforeNavigation,
|
||||
|
@ -428,6 +459,12 @@ function assertEvents(
|
|||
currentTargetFront,
|
||||
"complete target is the current target"
|
||||
);
|
||||
|
||||
is(
|
||||
completeEvent.hasNativeConsoleAPI,
|
||||
true,
|
||||
"None of the tests (except the dedicated one) overload the console object"
|
||||
);
|
||||
}
|
||||
|
||||
class ResourceListener {
|
||||
|
|
Загрузка…
Ссылка в новой задаче