Bug 1660268 - Pass list of resources instead of unique resource from ResourceWatcher. r=nchevobbe
Here, I've tried to be especially careful about replacing `return` by `continue` in the added for..loops. Differential Revision: https://phabricator.services.mozilla.com/D87768
This commit is contained in:
@@ -79,7 +79,7 @@ class DebuggerPanel {
|
||||
const resourceWatcher = this.toolbox.resourceWatcher;
|
||||
await resourceWatcher.watchResources(
|
||||
[resourceWatcher.TYPES.ERROR_MESSAGE],
|
||||
{ onAvailable: actions.addExceptionFromResource }
|
||||
{ onAvailable: actions.addExceptionFromResources }
|
||||
);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -9,11 +9,12 @@ import { hasException } from "../selectors";
|
||||
import type { ThunkArgs } from "./types";
|
||||
import type { Exception } from "../types";
|
||||
|
||||
export function addExceptionFromResource({ resource }: Object) {
|
||||
export function addExceptionFromResources(resources: Array<Object>) {
|
||||
return async function({ dispatch }: ThunkArgs) {
|
||||
for (const resource of resources) {
|
||||
const { pageError } = resource;
|
||||
if (!pageError.error) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
const { columnNumber, lineNumber, sourceId, errorMessage } = pageError;
|
||||
const stacktrace = pageError.stacktrace || [];
|
||||
@@ -27,6 +28,7 @@ export function addExceptionFromResource({ resource }: Object) {
|
||||
};
|
||||
|
||||
dispatch(addException(exception));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -428,10 +428,12 @@ class SourceMapURLService {
|
||||
return;
|
||||
}
|
||||
|
||||
this._onResourceAvailable = async ({ resource }) => {
|
||||
this._onResourceAvailable = async resources => {
|
||||
if (this._sourcesLoading === sourcesLoading) {
|
||||
for (const resource of resources) {
|
||||
this._onNewStyleSheet(resource);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
|
||||
@@ -119,10 +119,11 @@ class ChangesView {
|
||||
);
|
||||
}
|
||||
|
||||
onResourceAvailable({ resource }) {
|
||||
onResourceAvailable(resources) {
|
||||
for (const resource of resources) {
|
||||
if (resource.resourceType === this.resourceWatcher.TYPES.CSS_CHANGE) {
|
||||
this.onAddChange(resource);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resource.name === "dom-loading" && resource.targetFront.isTopLevel) {
|
||||
@@ -135,6 +136,7 @@ class ChangesView {
|
||||
this.onClearChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the "Copy All Changes" button. Simple wrapper that just calls
|
||||
|
||||
@@ -256,7 +256,8 @@ class CompatibilityView {
|
||||
);
|
||||
}
|
||||
|
||||
_onResourceAvailable({ resource }) {
|
||||
_onResourceAvailable(resources) {
|
||||
for (const resource of resources) {
|
||||
// Style changes applied inline directly to
|
||||
// the element and its changes are monitored by
|
||||
// _onMarkupMutation via markupmutation events.
|
||||
@@ -265,6 +266,7 @@ class CompatibilityView {
|
||||
this._onChangeAdded(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_onTopLevelTargetChanged() {
|
||||
if (!this._isAvailable()) {
|
||||
|
||||
@@ -1300,7 +1300,8 @@ Inspector.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
onResourceAvailable: function({ resource }) {
|
||||
onResourceAvailable: function(resources) {
|
||||
for (const resource of resources) {
|
||||
if (
|
||||
resource.resourceType === this.toolbox.resourceWatcher.TYPES.ROOT_NODE
|
||||
) {
|
||||
@@ -1315,6 +1316,7 @@ Inspector.prototype = {
|
||||
this.emit("frame-root-available", resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -149,17 +149,18 @@ class FirefoxConnector {
|
||||
this.responsiveFront = await this.currentTarget.getFront("responsive");
|
||||
}
|
||||
|
||||
async onResourceAvailable({ resource }) {
|
||||
async onResourceAvailable(resources) {
|
||||
for (const resource of resources) {
|
||||
const { TYPES } = this.toolbox.resourceWatcher;
|
||||
|
||||
if (resource.resourceType === TYPES.DOCUMENT_EVENT) {
|
||||
this.onDocEvent(resource);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resource.resourceType === TYPES.NETWORK_EVENT) {
|
||||
this.dataProvider.onNetworkResourceAvailable(resource);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resource.resourceType === TYPES.WEBSOCKET) {
|
||||
@@ -192,20 +193,27 @@ class FirefoxConnector {
|
||||
break;
|
||||
}
|
||||
case "frameSent": {
|
||||
this.dataProvider.onFrameSent(resource.httpChannelId, resource.data);
|
||||
this.dataProvider.onFrameSent(
|
||||
resource.httpChannelId,
|
||||
resource.data
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async onResourceUpdated({ targetFront, resource }) {
|
||||
async onResourceUpdated(updates) {
|
||||
for (const { resource } of updates) {
|
||||
if (
|
||||
resource.resourceType === this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT
|
||||
resource.resourceType ===
|
||||
this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT
|
||||
) {
|
||||
this.dataProvider.onNetworkResourceUpdated(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async addListeners(ignoreExistingResources = false) {
|
||||
const targetResources = [this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT];
|
||||
|
||||
@@ -166,7 +166,8 @@ HarCollector.prototype = {
|
||||
|
||||
// Event Handlers
|
||||
|
||||
onResourceAvailable: function({ resource }) {
|
||||
onResourceAvailable: function(resources) {
|
||||
for (const resource of resources) {
|
||||
trace.log("HarCollector.onNetworkEvent; ", resource);
|
||||
|
||||
const {
|
||||
@@ -190,7 +191,7 @@ HarCollector.prototype = {
|
||||
console.error(
|
||||
"HarCollector.onNetworkEvent; ERROR " + "existing file conflict!"
|
||||
);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
file = {
|
||||
@@ -206,9 +207,11 @@ HarCollector.prototype = {
|
||||
|
||||
// Mimic the Net panel data structure
|
||||
this.items.push(file);
|
||||
}
|
||||
},
|
||||
|
||||
onResourceUpdated: function({ resource }) {
|
||||
onResourceUpdated: function(updates) {
|
||||
for (const { resource } of updates) {
|
||||
// Skip events from unknown actors (not in the list).
|
||||
// It can happen when there are zombie requests received after
|
||||
// the target is closed or multiple tabs are attached through
|
||||
@@ -296,6 +299,7 @@ HarCollector.prototype = {
|
||||
}
|
||||
|
||||
this.resetPageLoadTimeout();
|
||||
}
|
||||
},
|
||||
|
||||
getData: function(actor, method, callback) {
|
||||
|
||||
@@ -1187,8 +1187,8 @@ function getCurrentTestFilePath() {
|
||||
*/
|
||||
function waitForResourceOnce(resourceWatcher, resourceType) {
|
||||
return new Promise(resolve => {
|
||||
const onAvailable = ({ resource }) => {
|
||||
resolve({ resource });
|
||||
const onAvailable = resources => {
|
||||
resolve(resources[0]);
|
||||
resourceWatcher.unwatchResources([resourceType], { onAvailable });
|
||||
};
|
||||
resourceWatcher.watchResources([resourceType], {
|
||||
|
||||
@@ -1201,7 +1201,8 @@ StyleEditorUI.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
async _onResourceAvailable({ resource }) {
|
||||
async _onResourceAvailable(resources) {
|
||||
for (const resource of resources) {
|
||||
if (
|
||||
resource.resourceType === this._toolbox.resourceWatcher.TYPES.STYLESHEET
|
||||
) {
|
||||
@@ -1213,11 +1214,11 @@ StyleEditorUI.prototype = {
|
||||
}
|
||||
|
||||
await onStyleSheetHandled;
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!resource.targetFront.isTopLevel) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resource.name === "dom-loading") {
|
||||
@@ -1232,13 +1233,17 @@ StyleEditorUI.prototype = {
|
||||
} else if (resource.name === "dom-complete") {
|
||||
await this._waitForLoadingStyleSheets();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async _onResourceUpdated({ update }) {
|
||||
async _onResourceUpdated(updates) {
|
||||
for (const { update } of updates) {
|
||||
if (
|
||||
update.resourceType === this._toolbox.resourceWatcher.TYPES.STYLESHEET
|
||||
) {
|
||||
const editor = this.editors.find(e => e.resourceId === update.resourceId);
|
||||
const editor = this.editors.find(
|
||||
e => e.resourceId === update.resourceId
|
||||
);
|
||||
|
||||
switch (update.updateType) {
|
||||
case "style-applied": {
|
||||
@@ -1260,6 +1265,7 @@ StyleEditorUI.prototype = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
|
||||
@@ -70,8 +70,10 @@ async function generateConsoleApiStubs() {
|
||||
// resource to `handleConsoleMessage`, dynamically updated for each command.
|
||||
let handleConsoleMessage = function() {};
|
||||
|
||||
const onConsoleMessage = ({ resource }) => {
|
||||
const onConsoleMessage = resources => {
|
||||
for (const resource of resources) {
|
||||
handleConsoleMessage(resource);
|
||||
}
|
||||
};
|
||||
await resourceWatcher.watchResources(
|
||||
[resourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
|
||||
@@ -68,8 +68,10 @@ async function generateCssMessageStubs() {
|
||||
// resource to `handleErrorMessage`, dynamically updated for each command.
|
||||
let handleCSSMessage = function() {};
|
||||
|
||||
const onCSSMessageAvailable = ({ resource }) => {
|
||||
const onCSSMessageAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
handleCSSMessage(resource);
|
||||
}
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources([resourceWatcher.TYPES.CSS_MESSAGE], {
|
||||
|
||||
@@ -70,11 +70,15 @@ async function generateNetworkEventStubs() {
|
||||
let addNetworkStub = function() {};
|
||||
let addNetworkUpdateStub = function() {};
|
||||
|
||||
const onAvailable = resource => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
addNetworkStub(resource);
|
||||
}
|
||||
};
|
||||
const onUpdated = resource => {
|
||||
const onUpdated = updates => {
|
||||
for (const { resource } of updates) {
|
||||
addNetworkUpdateStub(resource);
|
||||
}
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources([resourceWatcher.TYPES.NETWORK_EVENT], {
|
||||
@@ -85,14 +89,14 @@ async function generateNetworkEventStubs() {
|
||||
for (const [key, code] of getCommands()) {
|
||||
const noExpectedUpdates = 7;
|
||||
const networkEventDone = new Promise(resolve => {
|
||||
addNetworkStub = ({ resource }) => {
|
||||
addNetworkStub = resource => {
|
||||
stubs.set(key, getCleanedPacket(key, getOrderedResource(resource)));
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
const networkEventUpdateDone = new Promise(resolve => {
|
||||
let updateCount = 0;
|
||||
addNetworkUpdateStub = ({ resource }) => {
|
||||
addNetworkUpdateStub = resource => {
|
||||
const updateKey = `${key} update`;
|
||||
// make sure all the updates have been happened
|
||||
if (updateCount >= noExpectedUpdates) {
|
||||
|
||||
@@ -72,8 +72,10 @@ async function generatePageErrorStubs() {
|
||||
// resource to `handleErrorMessage`, dynamically updated for each command.
|
||||
let handleErrorMessage = function() {};
|
||||
|
||||
const onErrorMessageAvailable = ({ resource }) => {
|
||||
const onErrorMessageAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
handleErrorMessage(resource);
|
||||
}
|
||||
};
|
||||
await resourceWatcher.watchResources([resourceWatcher.TYPES.ERROR_MESSAGE], {
|
||||
onAvailable: onErrorMessageAvailable,
|
||||
|
||||
@@ -80,8 +80,10 @@ async function generatePlatformMessagesStubs() {
|
||||
// resource to `handlePlatformMessage`, dynamically updated for each command.
|
||||
let handlePlatformMessage = function() {};
|
||||
|
||||
const onPlatformMessageAvailable = ({ resource }) => {
|
||||
const onPlatformMessageAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
handlePlatformMessage(resource);
|
||||
}
|
||||
};
|
||||
await resourceWatcher.watchResources(
|
||||
[resourceWatcher.TYPES.PLATFORM_MESSAGE],
|
||||
|
||||
@@ -998,7 +998,7 @@ async function openMessageInNetmonitor(toolbox, hud, url, urlInConsole) {
|
||||
await waitFor(() => {
|
||||
const selected = getSelectedRequest(store.getState());
|
||||
return selected && selected.url === url;
|
||||
}, "network entry for the URL wasn't found");
|
||||
}, `network entry for the URL "${url}" wasn't found`);
|
||||
|
||||
ok(true, "The attached url is correct.");
|
||||
|
||||
|
||||
@@ -353,10 +353,11 @@ class WebConsoleUI {
|
||||
});
|
||||
}
|
||||
|
||||
_onResourceAvailable({ resource }) {
|
||||
_onResourceAvailable(resources) {
|
||||
if (!this.hud) {
|
||||
return;
|
||||
}
|
||||
for (const resource of resources) {
|
||||
const { TYPES } = this.hud.resourceWatcher;
|
||||
// Ignore messages forwarded from content processes if we're in fission browser toolbox.
|
||||
if (
|
||||
@@ -367,16 +368,21 @@ class WebConsoleUI {
|
||||
(this.isBrowserToolboxConsole || this.isBrowserConsole) &&
|
||||
this.fissionSupport)
|
||||
) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
this.wrapper.dispatchMessageAdd(resource);
|
||||
}
|
||||
}
|
||||
|
||||
_onResourceUpdated({ resource }) {
|
||||
if (resource.resourceType == this.hud.resourceWatcher.TYPES.NETWORK_EVENT) {
|
||||
_onResourceUpdated(updates) {
|
||||
for (const { resource } of updates) {
|
||||
if (
|
||||
resource.resourceType == this.hud.resourceWatcher.TYPES.NETWORK_EVENT
|
||||
) {
|
||||
this.wrapper.dispatchMessageUpdate(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called any time a new target is available.
|
||||
|
||||
@@ -295,6 +295,8 @@ class ResourceWatcher {
|
||||
* which describes the resource.
|
||||
*/
|
||||
async _onResourceAvailable({ targetFront, watcherFront }, resources) {
|
||||
let currentType = null;
|
||||
let resourceBuffer = [];
|
||||
for (let resource of resources) {
|
||||
const { resourceType } = resource;
|
||||
|
||||
@@ -320,12 +322,24 @@ class ResourceWatcher {
|
||||
});
|
||||
}
|
||||
|
||||
this._availableListeners.emit(resourceType, {
|
||||
resource,
|
||||
});
|
||||
if (!currentType) {
|
||||
currentType = resourceType;
|
||||
}
|
||||
// Flush the current list of buffered resource if we switch to another type
|
||||
else if (currentType != resourceType) {
|
||||
this._availableListeners.emit(currentType, resourceBuffer);
|
||||
currentType = resourceType;
|
||||
resourceBuffer = [];
|
||||
}
|
||||
resourceBuffer.push(resource);
|
||||
|
||||
this._cache.push(resource);
|
||||
}
|
||||
|
||||
// Flush the buffered resources if there is any
|
||||
if (resourceBuffer.length > 0) {
|
||||
this._availableListeners.emit(currentType, resourceBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,6 +375,8 @@ class ResourceWatcher {
|
||||
* }
|
||||
*/
|
||||
async _onResourceUpdated({ targetFront, watcherFront }, updates) {
|
||||
let currentType = null;
|
||||
let resourceBuffer = [];
|
||||
for (const update of updates) {
|
||||
const { resourceType, resourceId, resourceUpdates } = update;
|
||||
|
||||
@@ -385,11 +401,25 @@ class ResourceWatcher {
|
||||
Object.assign(existingResource, resourceUpdates);
|
||||
}
|
||||
|
||||
this._updatedListeners.emit(resourceType, {
|
||||
if (!currentType) {
|
||||
currentType = resourceType;
|
||||
}
|
||||
// Flush the current list of buffered resource if we switch to another type
|
||||
if (currentType != resourceType) {
|
||||
this._updatedListeners.emit(currentType, resourceBuffer);
|
||||
currentType = resourceType;
|
||||
resourceBuffer = [];
|
||||
}
|
||||
resourceBuffer.push({
|
||||
resource: existingResource,
|
||||
update,
|
||||
});
|
||||
}
|
||||
|
||||
// Flush the buffered resources if there is any
|
||||
if (resourceBuffer.length > 0) {
|
||||
this._updatedListeners.emit(currentType, resourceBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,6 +427,8 @@ class ResourceWatcher {
|
||||
* See _onResourceAvailable for the argument description.
|
||||
*/
|
||||
async _onResourceDestroyed({ targetFront, watcherFront }, resources) {
|
||||
let currentType = null;
|
||||
let resourceBuffer = [];
|
||||
for (const resource of resources) {
|
||||
const { resourceType, resourceId } = resource;
|
||||
|
||||
@@ -425,9 +457,21 @@ class ResourceWatcher {
|
||||
);
|
||||
}
|
||||
|
||||
this._destroyedListeners.emit(resourceType, {
|
||||
resource,
|
||||
});
|
||||
if (!currentType) {
|
||||
currentType = resourceType;
|
||||
}
|
||||
// Flush the current list of buffered resource if we switch to another type
|
||||
if (currentType != resourceType) {
|
||||
this._destroyedListeners.emit(currentType, resourceBuffer);
|
||||
currentType = resourceType;
|
||||
resourceBuffer = [];
|
||||
}
|
||||
resourceBuffer.push(resource);
|
||||
}
|
||||
|
||||
// Flush the buffered resources if there is any
|
||||
if (resourceBuffer.length > 0) {
|
||||
this._destroyedListeners.emit(currentType, resourceBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,15 +552,11 @@ class ResourceWatcher {
|
||||
}
|
||||
|
||||
async _forwardCachedResources(resourceTypes, onAvailable) {
|
||||
for (const resource of this._cache) {
|
||||
if (resourceTypes.includes(resource.resourceType)) {
|
||||
await onAvailable({
|
||||
resourceType: resource.resourceType,
|
||||
targetFront: resource.targetFront,
|
||||
resource,
|
||||
});
|
||||
}
|
||||
}
|
||||
await onAvailable(
|
||||
this._cache.filter(resource =>
|
||||
resourceTypes.includes(resource.resourceType)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ add_task(async function() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources1.push(resource),
|
||||
onAvailable: resources => cachedResources1.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -40,7 +40,7 @@ add_task(async function() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources2.push(resource),
|
||||
onAvailable: resources => cachedResources2.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -73,7 +73,7 @@ add_task(async function() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -90,7 +90,7 @@ add_task(async function() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources.push(resource),
|
||||
onAvailable: resources => cachedResources.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -134,7 +134,7 @@ add_task(async function() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources.push(resource),
|
||||
onAvailable: resources => cachedResources.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -163,7 +163,7 @@ add_task(async function() {
|
||||
ResourceWatcher.TYPES.ERROR_MESSAGE,
|
||||
],
|
||||
{
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -194,7 +194,7 @@ add_task(async function() {
|
||||
ResourceWatcher.TYPES.ERROR_MESSAGE,
|
||||
],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources.push(resource),
|
||||
onAvailable: resources => cachedResources.push(...resources),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -228,7 +228,7 @@ async function testIgnoreExistingResources(isFirstListenerIgnoreExisting) {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources1.push(resource),
|
||||
onAvailable: resources => cachedResources1.push(...resources),
|
||||
ignoreExistingResources: isFirstListenerIgnoreExisting,
|
||||
}
|
||||
);
|
||||
@@ -238,7 +238,7 @@ async function testIgnoreExistingResources(isFirstListenerIgnoreExisting) {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => cachedResources2.push(resource),
|
||||
onAvailable: resources => cachedResources2.push(...resources),
|
||||
ignoreExistingResources: !isFirstListenerIgnoreExisting,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -35,7 +35,8 @@ async function testConsoleMessagesResources() {
|
||||
const expectedExistingCalls = [...expectedExistingConsoleCalls];
|
||||
const expectedRuntimeCalls = [...expectedRuntimeConsoleCalls];
|
||||
const onRuntimeDone = new Promise(resolve => (runtimeDoneResolve = resolve));
|
||||
const onAvailable = ({ resource }) => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
is(
|
||||
resource.resourceType,
|
||||
ResourceWatcher.TYPES.CONSOLE_MESSAGE,
|
||||
@@ -50,6 +51,7 @@ async function testConsoleMessagesResources() {
|
||||
if (expectedRuntimeCalls.length == 0) {
|
||||
runtimeDoneResolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources(
|
||||
@@ -101,7 +103,7 @@ async function testConsoleMessagesResourcesWithIgnoreExistingResources() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
ignoreExistingResources: true,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ add_task(async function() {
|
||||
|
||||
const availableResources = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.CSS_CHANGE], {
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
});
|
||||
assertResource(
|
||||
availableResources[0],
|
||||
@@ -83,7 +83,7 @@ add_task(async function() {
|
||||
info("Check whether ResourceWatcher sends all resources added in this test");
|
||||
const existingResources = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.CSS_CHANGE], {
|
||||
onAvailable: ({ resource }) => existingResources.push(resource),
|
||||
onAvailable: resources => existingResources.push(...resources),
|
||||
});
|
||||
await waitUntil(() => existingResources.length === 4);
|
||||
is(availableResources[0], existingResources[0], "1st resource is correct");
|
||||
|
||||
@@ -163,7 +163,8 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
|
||||
|
||||
let done;
|
||||
const onAllMessagesReceived = new Promise(resolve => (done = resolve));
|
||||
const onAvailable = ({ resource }) => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
const { pageError } = resource;
|
||||
|
||||
is(
|
||||
@@ -174,19 +175,22 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
|
||||
|
||||
if (!pageError.sourceName.includes("test_css_messages")) {
|
||||
info(`Ignore error from unknown source: "${pageError.sourceName}"`);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
const index = receivedMessages.length;
|
||||
receivedMessages.push(pageError);
|
||||
|
||||
info(`checking received css message #${index}: ${pageError.errorMessage}`);
|
||||
info(
|
||||
`checking received css message #${index}: ${pageError.errorMessage}`
|
||||
);
|
||||
ok(pageError, "The resource has a pageError attribute");
|
||||
checkObject(resource, expectedMessages[index]);
|
||||
|
||||
if (receivedMessages.length == expectedMessages.length) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
};
|
||||
return { onAvailable, onAllMessagesReceived };
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ async function testDocumentEventResourcesWithIgnoreExistingResources() {
|
||||
info("Check whether the existing document events will not be fired");
|
||||
const documentEvents = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.DOCUMENT_EVENT], {
|
||||
onAvailable: ({ resource }) => documentEvents.push(resource),
|
||||
onAvailable: resources => documentEvents.push(...resources),
|
||||
ignoreExistingResources: true,
|
||||
});
|
||||
is(documentEvents.length, 0, "Existing document events are not fired");
|
||||
@@ -129,13 +129,15 @@ function assertEvents(loadingEvent, interactiveEvent, completeEvent) {
|
||||
class ResourceListener {
|
||||
_listeners = new Map();
|
||||
|
||||
dispatch({ resource }) {
|
||||
dispatch(resources) {
|
||||
for (const resource of resources) {
|
||||
const resolve = this._listeners.get(resource.name);
|
||||
if (resolve) {
|
||||
resolve(resource);
|
||||
this._listeners.delete(resource.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
once(resourceName) {
|
||||
return new Promise(r => this._listeners.set(resourceName, r));
|
||||
|
||||
@@ -52,7 +52,8 @@ async function testErrorMessagesResources() {
|
||||
|
||||
let done;
|
||||
const onAllErrorReceived = new Promise(resolve => (done = resolve));
|
||||
const onAvailable = ({ resource }) => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
const { pageError } = resource;
|
||||
|
||||
is(
|
||||
@@ -63,7 +64,7 @@ async function testErrorMessagesResources() {
|
||||
|
||||
if (!pageError.sourceName.includes("test_page_errors")) {
|
||||
info(`Ignore error from unknown source: "${pageError.sourceName}"`);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
const index = receivedMessages.length;
|
||||
@@ -76,6 +77,7 @@ async function testErrorMessagesResources() {
|
||||
if (receivedMessages.length == expectedMessages.length) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGE], {
|
||||
@@ -117,7 +119,7 @@ async function testErrorMessagesResourcesWithIgnoreExistingResources() {
|
||||
|
||||
const availableResources = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGE], {
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
ignoreExistingResources: true,
|
||||
});
|
||||
is(
|
||||
|
||||
@@ -32,7 +32,7 @@ add_task(async function() {
|
||||
"Start to watch the available resources in order to compare with resources gotten from getAllResources"
|
||||
);
|
||||
const availableResources = [];
|
||||
const onAvailable = ({ resource }) => availableResources.push(resource);
|
||||
const onAvailable = resources => availableResources.push(...resources);
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
|
||||
{ onAvailable }
|
||||
|
||||
@@ -128,7 +128,8 @@ async function testNetworkEventResources(options) {
|
||||
const waitOnAllExpectedUpdatesForExistingRequests = new Promise(resolve => {
|
||||
const existingRequestUrl = `${EXAMPLE_DOMAIN}existing_post.html`;
|
||||
|
||||
onResourceAvailable = ({ resource }) => {
|
||||
onResourceAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
// A blocked request would only have two updates so lets also resolve here
|
||||
if (
|
||||
resource.request.url == existingRequestUrl &&
|
||||
@@ -137,15 +138,17 @@ async function testNetworkEventResources(options) {
|
||||
) {
|
||||
// Reset the updates expectation as the request is blocked
|
||||
if (options.expectedResourcesOnAvailable[resource.request.url]) {
|
||||
options.expectedResourcesOnAvailable[resource.request.url].updates = [
|
||||
...resource.updates,
|
||||
];
|
||||
options.expectedResourcesOnAvailable[
|
||||
resource.request.url
|
||||
].updates = [...resource.updates];
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onResourceUpdated = ({ resource }) => {
|
||||
onResourceUpdated = updates => {
|
||||
for (const { resource } of updates) {
|
||||
// Wait until all the update events have fired for the existing request.
|
||||
// Handle both blocked and unblocked requests
|
||||
if (
|
||||
@@ -155,12 +158,13 @@ async function testNetworkEventResources(options) {
|
||||
) {
|
||||
// Makes sure the expectation always correct (for either blocked or unblocked requests)
|
||||
if (options.expectedResourcesOnAvailable[resource.request.url]) {
|
||||
options.expectedResourcesOnAvailable[resource.request.url].updates = [
|
||||
...resource.updates,
|
||||
];
|
||||
options.expectedResourcesOnAvailable[
|
||||
resource.request.url
|
||||
].updates = [...resource.updates];
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
resourceWatcher
|
||||
@@ -190,7 +194,8 @@ async function testNetworkEventResources(options) {
|
||||
() => expectedOnUpdatedCounts == 0
|
||||
);
|
||||
|
||||
const onAvailable = ({ targetFront, resource }) => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
is(
|
||||
resource.resourceType,
|
||||
ResourceWatcher.TYPES.NETWORK_EVENT,
|
||||
@@ -203,9 +208,11 @@ async function testNetworkEventResources(options) {
|
||||
updates: [...resource.updates],
|
||||
};
|
||||
expectedOnAvailableCounts--;
|
||||
}
|
||||
};
|
||||
|
||||
const onUpdated = ({ targetFront, resource }) => {
|
||||
const onUpdated = updates => {
|
||||
for (const { resource } of updates) {
|
||||
is(
|
||||
resource.resourceType,
|
||||
ResourceWatcher.TYPES.NETWORK_EVENT,
|
||||
@@ -218,6 +225,7 @@ async function testNetworkEventResources(options) {
|
||||
updates: [...resource.updates],
|
||||
};
|
||||
expectedOnUpdatedCounts--;
|
||||
}
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.NETWORK_EVENT], {
|
||||
|
||||
@@ -42,9 +42,10 @@ async function testPlatformMessagesResources() {
|
||||
|
||||
let done;
|
||||
const onAllMessagesReceived = new Promise(resolve => (done = resolve));
|
||||
const onAvailable = ({ resource }) => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
if (!expectedMessages.includes(resource.message)) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
is(
|
||||
@@ -68,6 +69,7 @@ async function testPlatformMessagesResources() {
|
||||
if (receivedMessages.length == expectedMessages.length) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources(
|
||||
@@ -110,12 +112,14 @@ async function testPlatformMessagesResourcesWithIgnoreExistingResources() {
|
||||
await resourceWatcher.watchResources(
|
||||
[ResourceWatcher.TYPES.PLATFORM_MESSAGE],
|
||||
{
|
||||
onAvailable: ({ resource }) => {
|
||||
onAvailable: resources => {
|
||||
for (const resource of resources) {
|
||||
if (!expectedMessages.includes(resource.message)) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
availableResources.push(resource);
|
||||
}
|
||||
},
|
||||
ignoreExistingResources: true,
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ add_task(async function() {
|
||||
|
||||
info("Call watchResources([ROOT_NODE], ...)");
|
||||
let onAvailableCounter = 0;
|
||||
const onAvailable = () => onAvailableCounter++;
|
||||
const onAvailable = resources => (onAvailableCounter += resources.length);
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ROOT_NODE], {
|
||||
onAvailable,
|
||||
});
|
||||
@@ -91,13 +91,13 @@ add_task(async function testRootNodeFrontIsCorrect() {
|
||||
|
||||
let rootNodeResolve;
|
||||
let rootNodePromise = new Promise(r => (rootNodeResolve = r));
|
||||
const onAvailable = rootNodeFront => rootNodeResolve(rootNodeFront);
|
||||
const onAvailable = ([rootNodeFront]) => rootNodeResolve(rootNodeFront);
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ROOT_NODE], {
|
||||
onAvailable,
|
||||
});
|
||||
|
||||
info("Wait until onAvailable has been called");
|
||||
const { resource: root1 } = await rootNodePromise;
|
||||
const root1 = await rootNodePromise;
|
||||
ok(!!root1, "onAvailable has been called with a valid argument");
|
||||
is(
|
||||
root1.resourceType,
|
||||
@@ -113,7 +113,7 @@ add_task(async function testRootNodeFrontIsCorrect() {
|
||||
rootNodePromise = new Promise(r => (rootNodeResolve = r));
|
||||
browser.reload();
|
||||
|
||||
const { resource: root2 } = await rootNodePromise;
|
||||
const root2 = await rootNodePromise;
|
||||
ok(
|
||||
root1 !== root2,
|
||||
"onAvailable has been called with a different node front after reload"
|
||||
@@ -122,7 +122,7 @@ add_task(async function testRootNodeFrontIsCorrect() {
|
||||
info("Navigate to another URL");
|
||||
rootNodePromise = new Promise(r => (rootNodeResolve = r));
|
||||
BrowserTestUtils.loadURI(browser, `data:text/html,<div id=div3>`);
|
||||
const { resource: root3 } = await rootNodePromise;
|
||||
const root3 = await rootNodePromise;
|
||||
info("Check we can query an expected node under the retrieved root");
|
||||
const div3 = await root3.walkerFront.querySelector(root3, "div");
|
||||
is(div3.getAttribute("id"), "div3", "Correct root node retrieved");
|
||||
|
||||
@@ -32,10 +32,12 @@ add_task(async function() {
|
||||
// We are only interested in console messages as a resource, the ROOT_NODE one
|
||||
// is here to test the ResourceWatcher::unwatchResources API with several resources.
|
||||
const receivedMessages = [];
|
||||
const onAvailable = ({ resource }) => {
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
if (resource.resourceType === CONSOLE_MESSAGE) {
|
||||
receivedMessages.push(resource);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
info("Call watchResources([CONSOLE_MESSAGE, ROOT_NODE], ...)");
|
||||
|
||||
@@ -106,7 +106,7 @@ add_task(async function() {
|
||||
info("Check whether ResourceWatcher gets existing stylesheet");
|
||||
const availableResources = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.STYLESHEET], {
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
});
|
||||
|
||||
is(
|
||||
@@ -176,8 +176,8 @@ add_task(async function() {
|
||||
const availableResources = [];
|
||||
const updates = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.STYLESHEET], {
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onUpdated: ({ resource, update }) => updates.push({ resource, update }),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
onUpdated: newUpdates => updates.push(...newUpdates),
|
||||
});
|
||||
is(
|
||||
availableResources.length,
|
||||
|
||||
@@ -24,7 +24,7 @@ add_task(async function() {
|
||||
info("Check available resources at initial");
|
||||
const availableResources = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.WEBSOCKET], {
|
||||
onAvailable: ({ resource }) => availableResources.push(resource),
|
||||
onAvailable: resources => availableResources.push(...resources),
|
||||
});
|
||||
is(
|
||||
availableResources.length,
|
||||
@@ -101,7 +101,7 @@ add_task(async function() {
|
||||
info("Check existing resources");
|
||||
const existingResources = [];
|
||||
await resourceWatcher.watchResources([ResourceWatcher.TYPES.WEBSOCKET], {
|
||||
onAvailable: ({ resource }) => existingResources.push(resource),
|
||||
onAvailable: resources => existingResources.push(...resources),
|
||||
});
|
||||
is(
|
||||
availableResources.length,
|
||||
|
||||
@@ -742,7 +742,9 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
|
||||
await this._currentDevToolsTarget.attach();
|
||||
}
|
||||
|
||||
async _onResourceAvailable({ targetFront, resource }) {
|
||||
async _onResourceAvailable(resources) {
|
||||
for (const resource of resources) {
|
||||
const { targetFront } = resource;
|
||||
if (targetFront.isTopLevel && resource.name === "dom-complete") {
|
||||
const url = targetFront.localTab.linkedBrowser.currentURI.spec;
|
||||
for (const listener of this._onNavigatedListeners) {
|
||||
@@ -751,6 +753,7 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ParentAPIManager = {
|
||||
proxyContexts: new Map(),
|
||||
|
||||
Reference in New Issue
Block a user