Bug 1694140 - [devtools] Rename TargetFactory to TabTargetFactory and update filename r=ochameau

Depends on D106032

Differential Revision: https://phabricator.services.mozilla.com/D106037
This commit is contained in:
Julian Descottes 2021-02-25 12:58:16 +00:00
parent 86d04516e5
commit 13d48a2ee6
44 changed files with 87 additions and 73 deletions

View File

@ -13,7 +13,6 @@ module.exports = {
gDevTools: true,
once: true,
synthesizeKeyFromKeyTag: true,
TargetFactory: true,
waitForTick: true,
waitUntilState: true,
},

View File

@ -802,7 +802,7 @@ function addA11yPanelTestsTask(tests, uri, msg, options) {
* Resolves when the toolbox and tab have been destroyed and closed.
*/
async function closeTabToolboxAccessibility(tab = gBrowser.selectedTab) {
if (TargetFactory.isKnownTab(tab)) {
if (TabTargetFactory.isKnownTab(tab)) {
await gDevTools.closeToolboxForTab(tab);
}

View File

@ -13,8 +13,8 @@ const {
loader.lazyRequireGetter(
this,
"TargetFactory",
"devtools/client/framework/target",
"TabTargetFactory",
"devtools/client/framework/tab-target-factory",
true
);
loader.lazyRequireGetter(
@ -560,7 +560,7 @@ DevTools.prototype = {
tab,
{ toolId, hostType, startTime, raise, reason, hostOptions } = {}
) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
return this.showToolbox(
target,
toolId,
@ -699,12 +699,12 @@ DevTools.prototype = {
* Returns null otherwise.
*/
async getToolboxForTab(tab) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
return this._toolboxes.get(target);
},
async closeToolboxForTab(tab) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
return this.closeToolbox(target);
},
@ -716,7 +716,7 @@ DevTools.prototype = {
* cached instances managed by DevTools target factory.
*/
createDescriptorForTab: function(tab) {
return TargetFactory.createDescriptorForTab(tab);
return TabTargetFactory.createDescriptorForTab(tab);
},
/**

View File

@ -36,8 +36,8 @@ DevToolsModules(
"source-map-url-service.js",
"store-provider.js",
"store.js",
"tab-target-factory.js",
"target-from-url.js",
"target.js",
"toolbox-context-menu.js",
"toolbox-host-manager.js",
"toolbox-hosts.js",

View File

@ -20,9 +20,9 @@ loader.lazyRequireGetter(
const targets = new WeakMap();
/**
* Functions for creating Targets
* Functions for creating (local) Tab Targets
*/
exports.TargetFactory = {
exports.TabTargetFactory = {
/**
* Construct a Target. The target will be cached for each Tab so that we create only
* one per tab.

View File

@ -22,7 +22,9 @@ SimpleTest.requestCompleteLog();
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
async function doGC() {
// In order to get stable results, we really have to do 3 GC attempts
@ -46,7 +48,7 @@ async function addTab(url) {
}
async function testScript(tab) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout

View File

@ -9,7 +9,7 @@ const TEST_URL = `data:text/html;charset=utf-8,<div id="test"></div>`;
add_task(async function() {
const tab = await addTab(TEST_URL);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const inspectorFront = await target.getFront("inspector");

View File

@ -5,7 +5,7 @@ add_task(async function() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(gBrowser.selectedTab);
await target.attach();
info("Cached front when getFront has not been called");

View File

@ -5,7 +5,7 @@ add_task(async function() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(gBrowser.selectedTab);
await target.attach();
is(target.localTab, gBrowser.selectedTab, "Target linked to the right tab.");

View File

@ -3,11 +3,11 @@
add_task(async function() {
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const tab2 = await addTab("about:blank");
const target2 = await TargetFactory.forTab(tab2);
const target2 = await TabTargetFactory.forTab(tab2);
await target2.attach();
info("Test the targetFront attribute for the root");
@ -94,7 +94,7 @@ add_task(async function() {
async function testDestroy() {
// initialize a clean target
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
// do not wait for the front to finish loading

View File

@ -5,7 +5,7 @@ add_task(async function() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(gBrowser.selectedTab);
await target.attach();
info("Test applying watchFronts to a front that will be created");

View File

@ -36,7 +36,7 @@ async function testChromeTab() {
Services.obs.addObserver(observe, "devtools-thread-ready");
});
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const threadFront = await target.attachThread();

View File

@ -196,7 +196,7 @@ class TabDescriptorFront extends FrontClassWithSpec(tabDescriptorSpec) {
// When the toolbox is in a Window Host, it won't be removed from the
// DOM when the tab is closed.
const toolbox = gDevTools.getToolbox(this._targetFront);
// A few tests are using TargetFactory.forTab, but aren't spawning any
// A few tests are using TabTargetFactory.forTab, but aren't spawning any
// toolbox. In this case, the toobox won't destroy the target, so we
// do it from here. But ultimately, the target should destroy itself
// from the actor side anyway.

View File

@ -20,7 +20,6 @@ registerCleanupFunction(() => {
var { OS } = require("resource://gre/modules/osfile.jsm");
var { FileUtils } = require("resource://gre/modules/FileUtils.jsm");
var { TargetFactory } = require("devtools/client/framework/target");
var promise = require("promise");
var { expectState } = require("devtools/server/actors/common");
var HeapSnapshotFileUtils = require("devtools/shared/heapsnapshot/HeapSnapshotFileUtils");

View File

@ -35,8 +35,8 @@ loader.lazyRequireGetter(
);
loader.lazyRequireGetter(
this,
"TargetFactory",
"devtools/client/framework/target",
"TabTargetFactory",
"devtools/client/framework/tab-target-factory",
true
);
loader.lazyRequireGetter(
@ -129,7 +129,7 @@ exports.menuitems = [
l10nKey: "eyedropper",
async oncommand(event) {
const window = event.target.ownerDocument.defaultView;
const target = await TargetFactory.forTab(window.gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(window.gBrowser.selectedTab);
await target.attach();
const inspectorFront = await target.getFront("inspector");

View File

@ -4,7 +4,7 @@
"use strict";
/* global window, document, SimpleTest, requestAnimationFrame, is, ok */
/* exported Cc, Ci, Cu, Cr, Assert, Task, TargetFactory, Toolbox, browserRequire,
/* exported Cc, Ci, Cu, Cr, Assert, Task, Toolbox, browserRequire,
forceRender, setProps, dumpn, checkOptimizationHeader, checkOptimizationTree */
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
let { Assert } = require("resource://testing-common/Assert.jsm");
@ -12,7 +12,6 @@ const { BrowserLoader } = ChromeUtils.import(
"resource://devtools/client/shared/browser-loader.js"
);
const flags = require("devtools/shared/flags");
let { TargetFactory } = require("devtools/client/framework/target");
let { Toolbox } = require("devtools/client/framework/toolbox");
let { require: browserRequire } = BrowserLoader({

View File

@ -28,8 +28,8 @@ loader.lazyRequireGetter(
);
loader.lazyRequireGetter(
this,
"TargetFactory",
"devtools/client/framework/target",
"TabTargetFactory",
"devtools/client/framework/tab-target-factory",
true
);
loader.lazyRequireGetter(
@ -141,7 +141,7 @@ class ResponsiveUIManager {
*/
async recordTelemetryOpen(window, tab, options) {
// Track whether a toolbox was opened before RDM was opened.
const isKnownTab = TargetFactory.isKnownTab(tab);
const isKnownTab = TabTargetFactory.isKnownTab(tab);
let toolbox;
if (isKnownTab) {
toolbox = await gDevTools.getToolboxForTab(tab);
@ -211,7 +211,7 @@ class ResponsiveUIManager {
}
async recordTelemetryClose(window, tab) {
const isKnownTab = TargetFactory.isKnownTab(tab);
const isKnownTab = TabTargetFactory.isKnownTab(tab);
let toolbox;
if (isKnownTab) {
toolbox = await gDevTools.getToolboxForTab(tab);

View File

@ -18,7 +18,6 @@ var Services = require("Services");
var { DevToolsServer } = require("devtools/server/devtools-server");
var { DevToolsClient } = require("devtools/client/devtools-client");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { TargetFactory } = require("devtools/client/framework/target");
var { Toolbox } = require("devtools/client/framework/toolbox");
var { require: browserRequire } = BrowserLoader({

View File

@ -6,7 +6,9 @@
const Services = require("Services");
const { gDevTools } = require("devtools/client/framework/devtools");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
/**
* Retrieve the most recent chrome window.
@ -61,7 +63,7 @@ exports.openContentLink = async function(url, options = {}) {
}
if (!options.triggeringPrincipal && top.gBrowser) {
const tab = top.gBrowser.selectedTab;
if (TargetFactory.isKnownTab(tab)) {
if (TabTargetFactory.isKnownTab(tab)) {
options.triggeringPrincipal = tab.linkedBrowser.contentPrincipal;
options.csp = tab.linkedBrowser.csp;
}

View File

@ -90,7 +90,7 @@ add_task(async function test() {
});
async function runTests() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(gBrowser.selectedTab);
await target.attach();
inspector = await target.getFront("inspector");
const walker = inspector.walker;

View File

@ -13,7 +13,7 @@ add_task(async function() {
});
async function runTests() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(gBrowser.selectedTab);
await target.attach();
const inspector = await target.getFront("inspector");
const walker = inspector.walker;

View File

@ -25,7 +25,7 @@ add_task(async function() {
SpecialPowers.setIntPref(MAX_TOTAL_VIEWERS, 10);
const tab = await addTab(TAB1_URL);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
await listWorkers(target);

View File

@ -22,7 +22,7 @@ var WORKER2_URL = "code_listworkers-worker2.js";
add_task(async function test() {
const tab = await addTab(TAB_URL);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
let { workers } = await listWorkers(target);

View File

@ -13,7 +13,7 @@ const TAB2_URL = EXAMPLE_URL + TAB2_FILE;
add_task(async () => {
const tab = await addTab(TAB1_URL);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
await testNavigate(target);

View File

@ -19,7 +19,7 @@ add_task(async function test() {
type: { target: true },
});
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const { client } = target;
const form = target.targetForm;

View File

@ -19,7 +19,7 @@ add_task(async function() {
type: { target: true },
});
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const { client } = target;
const form = target.targetForm;

View File

@ -15,7 +15,7 @@ const WORKER_URL = "code_WorkerTargetActor.attachThread-worker.js";
add_task(async function() {
const tab = await addTab(TAB_URL);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
await listWorkers(target);

View File

@ -4,6 +4,7 @@
"use strict";
/* import-globals-from ../../shared/test/shared-head.js */
/* import-globals-from ../../debugger/test/mochitest/helpers.js */
/* import-globals-from ../../debugger/test/mochitest/helpers/context.js */
Services.scriptloader.loadSubScript(
@ -169,7 +170,7 @@ function executeAndWaitForMessage(
async function initWorkerDebugger(TAB_URL, WORKER_URL) {
const tab = await addTab(TAB_URL);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const { client } = target;

View File

@ -48,7 +48,9 @@ const { loader, require } = ChromeUtils.import(
);
const { gDevTools } = require("devtools/client/framework/devtools");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
// This is overridden in files that load shared-head via loadSubScript.
@ -851,7 +853,7 @@ var openNewTabAndToolbox = async function(url, toolId, hostType) {
* closed.
*/
var closeTabAndToolbox = async function(tab = gBrowser.selectedTab) {
if (TargetFactory.isKnownTab(tab)) {
if (TabTargetFactory.isKnownTab(tab)) {
await gDevTools.closeToolboxForTab(tab);
}

View File

@ -23,7 +23,7 @@ const { Toolbox } = require("devtools/client/framework/toolbox");
/**
* Initialize and connect a DevToolsServer and DevToolsClient. Note: This test
* does not use TargetFactory, so it has to set up the DevToolsServer and
* does not use TabTargetFactory, so it has to set up the DevToolsServer and
* DevToolsClient on its own.
* @return {Promise} Resolves with an instance of the DevToolsClient class
*/

View File

@ -151,7 +151,7 @@ async function openTabAndSetupStorage(url, options = {}) {
var openStoragePanel = async function({ tab, target, hostType } = {}) {
info("Opening the storage inspector");
if (!target) {
target = await TargetFactory.forTab(tab || gBrowser.selectedTab);
target = await TabTargetFactory.forTab(tab || gBrowser.selectedTab);
}
let storage, toolbox;

View File

@ -15,8 +15,10 @@ const STUBS_FOLDER = "devtools/client/webconsole/test/node/fixtures/stubs/";
const STUBS_UPDATE_ENV = "WEBCONSOLE_STUBS_UPDATE";
async function createResourceWatcherForTab(tab) {
const { TargetFactory } = require("devtools/client/framework/target");
const target = await TargetFactory.forTab(tab);
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
const target = await TabTargetFactory.forTab(tab);
const resourceWatcher = await createResourceWatcherForDescriptor(
target.descriptorFront
);

View File

@ -30,16 +30,16 @@ async function testDevToolsServerInitialized() {
"By default, the DevToolsServer isn't initialized not in content process"
);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
ok(
DevToolsServer.initialized,
"TargetFactory.forTab will initialize the DevToolsServer in parent process"
"TabTargetFactory.forTab will initialize the DevToolsServer in parent process"
);
await assertServerInitialized(
browser,
true,
"TargetFactory.forTab will initialize the DevToolsServer in content process"
"TabTargetFactory.forTab will initialize the DevToolsServer in content process"
);
await target.destroy();
@ -72,7 +72,7 @@ async function testDevToolsServerKeepAlive() {
"Server not started in content process"
);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await assertServerInitialized(
browser,
true,
@ -95,7 +95,7 @@ async function testDevToolsServerKeepAlive() {
await setContentServerKeepAlive(browser, false);
info("Create and destroy a target again");
const newTarget = await TargetFactory.forTab(tab);
const newTarget = await TabTargetFactory.forTab(tab);
await newTarget.destroy();
await assertServerInitialized(

View File

@ -118,7 +118,7 @@ function onMessage({ data }) {
}
async function connectAndAttachTab(tab) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const actorID = target.actorID;
target.on("tabNavigated", function(packet) {

View File

@ -19,7 +19,7 @@ add_task(async function() {
});
const tab = gBrowser.getTabForBrowser(browser);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const { client } = target;
const form = target.targetForm;

View File

@ -23,7 +23,7 @@ add_task(async function() {
});
const tab = gBrowser.getTabForBrowser(browser);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const { client } = target;
const form = target.targetForm;

View File

@ -59,7 +59,7 @@ async function addTabTarget(url) {
}
async function getTargetForTab(tab) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
info("Attaching to the active tab.");
await target.attach();
return target;

View File

@ -1,7 +1,9 @@
/* exported getTargetForSelectedTab, waitFor, plotFPS */
"use strict";
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
const Services = require("Services");
// Always log packets when running tests.
@ -20,7 +22,7 @@ SimpleTest.waitForExplicitFinish();
function getTargetForSelectedTab() {
// Get the target and get the necessary front
const { gBrowser } = Services.wm.getMostRecentWindow("navigator:browser");
return TargetFactory.forTab(gBrowser.selectedTab);
return TabTargetFactory.forTab(gBrowser.selectedTab);
}
function waitFor(time) {

View File

@ -6,7 +6,9 @@
"use strict";
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
const { DevToolsServer } = require("devtools/server/devtools-server");
const {
BrowserTestUtils,
@ -53,7 +55,7 @@ SimpleTest.registerCleanupFunction(function() {
async function getTargetForSelectedTab(gBrowser) {
const selectedTab = gBrowser.selectedTab;
await BrowserTestUtils.browserLoaded(selectedTab.linkedBrowser);
return TargetFactory.forTab(selectedTab);
return TabTargetFactory.forTab(selectedTab);
}
/**

View File

@ -4,7 +4,9 @@
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const Services = require("Services");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
// Always log packets when running tests.
Services.prefs.setBoolPref("devtools.debugger.log", true);
@ -22,7 +24,9 @@ SimpleTest.registerCleanupFunction(function() {
async function getTargetForSelectedTab() {
const browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
const target = await TargetFactory.forTab(browserWindow.gBrowser.selectedTab);
const target = await TabTargetFactory.forTab(
browserWindow.gBrowser.selectedTab
);
return target;
}

View File

@ -3,7 +3,9 @@
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const { DevToolsServer } = require("devtools/server/devtools-server");
const { TargetFactory } = require("devtools/client/framework/target");
const {
TabTargetFactory,
} = require("devtools/client/framework/tab-target-factory");
const Services = require("Services");
@ -36,7 +38,7 @@ if (!DevToolsServer.initialized) {
*/
async function attachURL(url) {
const tab = await addTab(url);
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
await target.attach();
const webConsoleFront = await target.getFront("console");
return {

View File

@ -45,7 +45,6 @@ const { DevToolsServer: WorkerDevToolsServer } = worker.require(
const { DevToolsClient } = require("devtools/client/devtools-client");
const { ObjectFront } = require("devtools/client/fronts/object");
const { LongStringFront } = require("devtools/client/fronts/string");
const { TargetFactory } = require("devtools/client/framework/target");
const { addDebuggerToGlobal } = ChromeUtils.import(
"resource://gre/modules/jsdebugger.jsm"

View File

@ -25,8 +25,8 @@ const {
// eslint-disable-next-line mozilla/reject-some-requires
loader.lazyRequireGetter(
this,
"TargetFactory",
"devtools/client/framework/target",
"TabTargetFactory",
"devtools/client/framework/tab-target-factory",
true
);
@ -544,11 +544,11 @@ class TargetList extends EventEmitter {
// the same client.
targetFront.shouldCloseClient = false;
// Wait for the target to be destroyed so that TargetFactory clears its memoized target for this tab
// Wait for the target to be destroyed so that TabTargetFactory clears its memoized target for this tab
await targetFront.once("target-destroyed");
// Fetch the new target from the existing client so that the new target uses the same client.
const newTarget = await TargetFactory.forTab(localTab, client);
const newTarget = await TabTargetFactory.forTab(localTab, client);
this.switchToTarget(newTarget);
}

View File

@ -12,7 +12,7 @@ Services.scriptloader.loadSubScript(
);
async function getTargetForTab(tab) {
const target = await TargetFactory.forTab(tab);
const target = await TabTargetFactory.forTab(tab);
info("Attaching to the active tab.");
await target.attach();
return target;