Bug 1766237 - [devtools] Get the WebExtensionPolicy from the ExtensionProcessScript global r=jdescottes,rpl,ochameau

The issue here is it seems like WebExtensionPolicy is not always available on the Cu global,
therefore failing when trying to get the extension policy name.
in this example when adding sources from the browser toolbox (i'm still not completely sure why)

The solution here is changing to using the ExtensionProcessScript which works for the web and browser
toolbox.
Also added a `console.warn` so we get some notification when this fails.

Differential Revision: https://phabricator.services.mozilla.com/D144787
This commit is contained in:
Hubert Boma Manilla 2022-05-18 08:56:13 +00:00
Родитель 2d642870a6
Коммит ffb083dccd
9 изменённых файлов: 114 добавлений и 30 удалений

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

@ -32,6 +32,7 @@ prefs =
[browser_dbg-features-breakable-lines.js]
[browser_dbg-features-breakable-positions.js]
[browser_dbg-features-source-tree.js]
skip-if = asan # Bug 1591064
[browser_dbg-features-source-text-content.js]
[browser_dbg-features-wasm.js]

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

@ -14,6 +14,14 @@
"use strict";
requestLongerTimeout(5);
/* import-globals-from ../../../framework/browser-toolbox/test/helpers-browser-toolbox.js */
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/framework/browser-toolbox/test/helpers-browser-toolbox.js",
this
);
const testServer = createVersionizedHttpTestServer(
"examples/sourcemaps-reload-uncompressed"
);
@ -131,6 +139,7 @@ add_task(async function testSimpleSourcesWithManualClickExpand() {
info("Assert that nested-source.js is still the selected source");
await assertNodeIsFocused(dbg, 5);
dbg.toolbox.closeToolbox();
});
/**
@ -237,6 +246,7 @@ add_task(async function testSimpleSourcesWithManualKeyShortcutsExpand() {
// Up Key at the top of the source tree
await pressKey(dbg, "Up");
await assertNodeIsFocused(dbg, 2);
dbg.toolbox.closeToolbox();
});
/**
@ -367,6 +377,7 @@ add_task(async function testSourceTreeOnTheIntegrationTestPage() {
}
return resultItem.innerText.includes("query.js?x=1");
}, "Results include the source with the query string");
dbg.toolbox.closeToolbox();
});
/**
@ -416,6 +427,80 @@ add_task(async function testSourceTreeWithWebExtensionContentScript() {
await extension.unload();
});
// Test that the Web extension name is shown in source tree rather than
// the extensions internal UUID. This checks both the web toolbox and the
// browser toolbox.
add_task(async function testSourceTreeNamesForWebExtensions() {
await pushPref("devtools.chrome.enabled", true);
const extension = await installAndStartContentScriptExtension();
const dbg = await initDebugger("doc-content-script-sources.html");
await waitForSourcesInSourceTree(dbg, [], {
noExpand: true,
});
is(
getLabel(dbg, 2),
"Test content script extension",
"Test content script extension is labeled properly"
);
is(getLabel(dbg, 3), "resource://gre", "resource://gre is labeled properly");
await dbg.toolbox.closeToolbox();
await extension.unload();
// Make sure the toolbox opens with the debugger selected.
await pushPref("devtools.browsertoolbox.panel", "jsdebugger");
const ToolboxTask = await initBrowserToolboxTask();
await ToolboxTask.importFunctions({
createDebuggerContext,
waitUntil,
findSourceNodeWithText,
findAllElements,
getSelector,
findAllElementsWithSelector,
assertSourceTreeNode,
});
// ToolboxTask.spawn pass input arguments by stringify them via string concatenation.
// This mean we have to stringify the input object, but don't have to parse it from the task.
await ToolboxTask.spawn(JSON.stringify(selectors), async _selectors => {
this.selectors = _selectors;
});
await ToolboxTask.spawn(null, async () => {
try {
/* global gToolbox */
// Wait for the debugger to finish loading.
await gToolbox.getPanelWhenReady("jsdebugger");
const dbgx = createDebuggerContext(gToolbox);
let rootNodeForExtensions = null;
await waitUntil(() => {
rootNodeForExtensions = findSourceNodeWithText(dbgx, "extension");
return !!rootNodeForExtensions;
});
// Find the root node for extensions and expand it if needed
if (
!!rootNodeForExtensions &&
!rootNodeForExtensions.querySelector(".arrow.expanded")
) {
rootNodeForExtensions.querySelector(".arrow").click();
}
// Assert that extensions are displayed in the source tree
// with their extension name.
await assertSourceTreeNode(dbgx, "Picture-In-Picture");
await assertSourceTreeNode(dbgx, "Form Autofill");
} catch (e) {
console.log("Caught exception in spawn", e);
throw e;
}
});
await ToolboxTask.destroy();
});
/**
* Return the text content for a given line in the Source Tree.
*
@ -432,6 +517,22 @@ function getLabel(dbg, index) {
);
}
/**
* Find and assert the source tree node with the specified text
* exists on the source tree.
*
* @param {Object} dbg
* @param {String} text The node text displayed
*/
async function assertSourceTreeNode(dbg, text) {
let node = null;
await waitUntil(() => {
node = findSourceNodeWithText(dbg, text);
return !!node;
});
ok(!!node, `Source tree node with text "${text}" exists`);
}
/**
* Assert the location displayed in the breakpoint list, in the right sidebar.
*

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

@ -115,6 +115,7 @@ async function installAndStartContentScriptExtension() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
name: "Test content script extension",
content_scripts: [
{
js: ["content_script.js"],

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

@ -23,10 +23,6 @@ const {
webExtensionInspectedWindowSpec,
} = require("devtools/shared/specs/addon/webextension-inspected-window");
const { WebExtensionPolicy } = Cu.getGlobalForObject(
require("resource://gre/modules/XPCOMUtils.jsm")
);
// A weak set of the documents for which a warning message has been
// already logged (so that we don't keep emitting the same warning if an
// extension keeps calling the devtools.inspectedWindow.eval API method

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

@ -12,7 +12,7 @@
// Enable logging all platform events this module listen to
const DEBUG_PLATFORM_EVENTS = false;
const { Cc, Ci, Cu } = require("chrome");
const { Cc, Ci } = require("chrome");
const Services = require("Services");
const ChromeUtils = require("ChromeUtils");
@ -55,11 +55,6 @@ loader.lazyRequireGetter(
"devtools/server/actors/network-monitor/network-response-listener",
true
);
loader.lazyGetter(
this,
"WebExtensionPolicy",
() => Cu.getGlobalForObject(Cu).WebExtensionPolicy
);
function logPlatformEvent(eventName, channel, message = "") {
if (!DEBUG_PLATFORM_EVENTS) {

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

@ -4,7 +4,7 @@
"use strict";
const { Cc, Ci, Cr, Cu, components: Components } = require("chrome");
const { Cc, Ci, Cr, components: Components } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const Services = require("Services");
@ -20,11 +20,6 @@ loader.lazyRequireGetter(
true
);
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
loader.lazyGetter(
this,
"WebExtensionPolicy",
() => Cu.getGlobalForObject(Cu).WebExtensionPolicy
);
// Network logging

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

@ -4,13 +4,10 @@
"use strict";
const { Cu } = require("chrome");
const {
setBreakpointAtEntryPoints,
} = require("devtools/server/actors/breakpoint");
const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const { assert } = DevToolsUtils;
const { sourceSpec } = require("devtools/shared/specs/source");
const {
resolveSourceURL,
@ -33,13 +30,14 @@ loader.lazyRequireGetter(
true
);
loader.lazyRequireGetter(this, "Services");
loader.lazyGetter(
loader.lazyRequireGetter(
this,
"WebExtensionPolicy",
() => Cu.getGlobalForObject(Cu).WebExtensionPolicy
"DevToolsUtils",
"devtools/shared/DevToolsUtils"
);
loader.lazyRequireGetter(this, "Services");
const windowsDrive = /^([a-zA-Z]:)/;
function getSourceURL(source, window) {
@ -153,7 +151,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
}
}
} catch (e) {
// Ignore
console.warn(`Failed to find extension name for ${this.url} : ${e}`);
}
}
}
@ -209,7 +207,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
if (this._isWasm) {
const wasm = this._source.binary;
const buffer = wasm.buffer;
assert(
DevToolsUtils.assert(
wasm.byteOffset === 0 && wasm.byteLength === buffer.byteLength,
"Typed array from wasm source binary must cover entire buffer"
);

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

@ -20,11 +20,6 @@ loader.lazyGetter(this, "ExtensionStorageIDB", () => {
return require("resource://gre/modules/ExtensionStorageIDB.jsm")
.ExtensionStorageIDB;
});
loader.lazyGetter(
this,
"WebExtensionPolicy",
() => Cu.getGlobalForObject(ExtensionProcessScript).WebExtensionPolicy
);
const EXTENSION_STORAGE_ENABLED_PREF =
"devtools.storage.extensionStorage.enabled";

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

@ -23,6 +23,7 @@ const systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
const {
CanonicalBrowsingContext,
BrowsingContext,
WebExtensionPolicy,
WindowGlobalParent,
WindowGlobalChild,
console,
@ -257,6 +258,7 @@ exports.globals = {
btoa,
CanonicalBrowsingContext,
BrowsingContext,
WebExtensionPolicy,
WindowGlobalParent,
WindowGlobalChild,
console,