Backed out 3 changesets (bug 1660268) for failures on browser_ext_devtools_network_targetSwitch.js. CLOSED TREE

Backed out changeset 749fda4e5eb1 (bug 1660268)
Backed out changeset 9d4c305f6b88 (bug 1660268)
Backed out changeset 7ec118209790 (bug 1660268)
This commit is contained in:
Csoregi Natalia
2020-09-07 21:24:26 +03:00
parent 87f8d629b1
commit 6ed1de381f
32 changed files with 499 additions and 601 deletions

View File

@@ -79,7 +79,7 @@ class DebuggerPanel {
const resourceWatcher = this.toolbox.resourceWatcher;
await resourceWatcher.watchResources(
[resourceWatcher.TYPES.ERROR_MESSAGE],
{ onAvailable: actions.addExceptionFromResources }
{ onAvailable: actions.addExceptionFromResource }
);
return this;

View File

@@ -9,12 +9,11 @@ import { hasException } from "../selectors";
import type { ThunkArgs } from "./types";
import type { Exception } from "../types";
export function addExceptionFromResources(resources: Array<Object>) {
export function addExceptionFromResource({ resource }: Object) {
return async function({ dispatch }: ThunkArgs) {
for (const resource of resources) {
const { pageError } = resource;
if (!pageError.error) {
continue;
return;
}
const { columnNumber, lineNumber, sourceId, errorMessage } = pageError;
const stacktrace = pageError.stacktrace || [];
@@ -28,7 +27,6 @@ export function addExceptionFromResources(resources: Array<Object>) {
};
dispatch(addException(exception));
}
};
}

View File

@@ -438,12 +438,10 @@ class SourceMapURLService {
return;
}
this._onResourceAvailable = async resources => {
this._onResourceAvailable = async ({ resource }) => {
if (this._sourcesLoading === sourcesLoading) {
for (const resource of resources) {
this._onNewStyleSheet(resource);
}
}
};
await Promise.all([

View File

@@ -119,11 +119,10 @@ class ChangesView {
);
}
onResourceAvailable(resources) {
for (const resource of resources) {
onResourceAvailable({ resource }) {
if (resource.resourceType === this.resourceWatcher.TYPES.CSS_CHANGE) {
this.onAddChange(resource);
continue;
return;
}
if (resource.name === "dom-loading" && resource.targetFront.isTopLevel) {
@@ -136,7 +135,6 @@ class ChangesView {
this.onClearChanges();
}
}
}
/**
* Handler for the "Copy All Changes" button. Simple wrapper that just calls

View File

@@ -256,8 +256,7 @@ class CompatibilityView {
);
}
_onResourceAvailable(resources) {
for (const resource of resources) {
_onResourceAvailable({ resource }) {
// Style changes applied inline directly to
// the element and its changes are monitored by
// _onMarkupMutation via markupmutation events.
@@ -266,7 +265,6 @@ class CompatibilityView {
this._onChangeAdded(resource);
}
}
}
_onTopLevelTargetChanged() {
if (!this._isAvailable()) {

View File

@@ -1300,12 +1300,9 @@ Inspector.prototype = {
}
},
onResourceAvailable: function(resources) {
for (const resource of resources) {
if (
resource.resourceType === this.toolbox.resourceWatcher.TYPES.ROOT_NODE
) {
const isTopLevelTarget = !!resource.targetFront.isTopLevel;
onResourceAvailable: function({ resourceType, targetFront, resource }) {
if (resourceType === this.toolbox.resourceWatcher.TYPES.ROOT_NODE) {
const isTopLevelTarget = !!targetFront.isTopLevel;
if (resource.isTopLevelDocument && isTopLevelTarget) {
// Note: the resource (ie the root node here) will be fetched from the
// walker later on in _getDefaultNodeForSelection.
@@ -1316,7 +1313,6 @@ Inspector.prototype = {
this.emit("frame-root-available", resource);
}
}
}
},
/**

View File

@@ -81,10 +81,13 @@ add_task(async function navigateFrameNotExpandedInMarkupView() {
//
// The iframe we are about to navigate is therefore hidden and we are not
// watching it - ie, it is not in the list of known NodeFronts/Actors.
const { resource } = await navigateIframeTo(inspector, EXAMPLE_COM_URI);
const { resource, targetFront } = await navigateIframeTo(
inspector,
EXAMPLE_COM_URI
);
is(
resource.resourceType,
resource?.resourceType,
resourceWatcher.TYPES.ROOT_NODE,
"A resource with resourceType ROOT_NODE was received when navigating"
);
@@ -105,7 +108,7 @@ add_task(async function navigateFrameNotExpandedInMarkupView() {
// This should be fixed when implementing the RootNode resource on the server
// in https://bugzilla.mozilla.org/show_bug.cgi?id=1644190
todo(
!resource.targetFront.getCachedFront("inspector"),
!targetFront.getCachedFront("inspector"),
"The inspector front for the new target should not be initialized"
);
});

View File

@@ -149,21 +149,20 @@ class FirefoxConnector {
this.responsiveFront = await this.currentTarget.getFront("responsive");
}
async onResourceAvailable(resources) {
for (const resource of resources) {
async onResourceAvailable({ resourceType, targetFront, resource }) {
const { TYPES } = this.toolbox.resourceWatcher;
if (resource.resourceType === TYPES.DOCUMENT_EVENT) {
this.onDocEvent(resource);
continue;
if (resourceType === TYPES.DOCUMENT_EVENT) {
this.onDocEvent(targetFront, resource);
return;
}
if (resource.resourceType === TYPES.NETWORK_EVENT) {
if (resourceType === TYPES.NETWORK_EVENT) {
this.dataProvider.onNetworkResourceAvailable(resource);
continue;
return;
}
if (resource.resourceType === TYPES.WEBSOCKET) {
if (resourceType === TYPES.WEBSOCKET) {
const { wsMessageType } = resource;
switch (wsMessageType) {
@@ -193,27 +192,18 @@ class FirefoxConnector {
break;
}
case "frameSent": {
this.dataProvider.onFrameSent(
resource.httpChannelId,
resource.data
);
this.dataProvider.onFrameSent(resource.httpChannelId, resource.data);
break;
}
}
}
}
}
async onResourceUpdated(updates) {
for (const { resource } of updates) {
if (
resource.resourceType ===
this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT
) {
async onResourceUpdated({ resourceType, targetFront, resource }) {
if (resourceType === this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT) {
this.dataProvider.onNetworkResourceUpdated(resource);
}
}
}
async addListeners(ignoreExistingResources = false) {
const targetResources = [this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT];
@@ -328,28 +318,29 @@ class FirefoxConnector {
/**
* The "DOMContentLoaded" and "Load" events sent by the console actor.
*
* @param {object} resource The DOCUMENT_EVENT resource
* @param {object} targetFront
* @param {object} event
*/
onDocEvent(resource) {
if (!resource.targetFront.isTopLevel) {
onDocEvent(targetFront, event) {
if (!targetFront.isTopLevel) {
// Only handle document events for the top level target.
return;
}
if (resource.name === "dom-loading") {
if (event.name === "dom-loading") {
// Netmonitor does not support dom-loading event yet.
return;
}
if (this.actions) {
this.actions.addTimingMarker(resource);
this.actions.addTimingMarker(event);
}
if (resource.name === "dom-complete") {
if (event.name === "dom-complete") {
this.navigate();
}
this.emitForTests(TEST_EVENTS.TIMELINE_EVENT, resource);
this.emitForTests(TEST_EVENTS.TIMELINE_EVENT, event);
}
/**

View File

@@ -166,8 +166,7 @@ HarCollector.prototype = {
// Event Handlers
onResourceAvailable: function(resources) {
for (const resource of resources) {
onResourceAvailable: function({ resourceType, targetFront, resource }) {
trace.log("HarCollector.onNetworkEvent; ", resource);
const {
@@ -191,7 +190,7 @@ HarCollector.prototype = {
console.error(
"HarCollector.onNetworkEvent; ERROR " + "existing file conflict!"
);
continue;
return;
}
file = {
@@ -207,11 +206,9 @@ HarCollector.prototype = {
// Mimic the Net panel data structure
this.items.push(file);
}
},
onResourceUpdated: function(updates) {
for (const { resource } of updates) {
onResourceUpdated: function({ resourceType, targetFront, resource }) {
// 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
@@ -299,7 +296,6 @@ HarCollector.prototype = {
}
this.resetPageLoadTimeout();
}
},
getData: function(actor, method, callback) {

View File

@@ -1187,8 +1187,8 @@ function getCurrentTestFilePath() {
*/
function waitForResourceOnce(resourceWatcher, resourceType) {
return new Promise(resolve => {
const onAvailable = resources => {
resolve(resources[0]);
const onAvailable = ({ targetFront, resource }) => {
resolve({ targetFront, resource });
resourceWatcher.unwatchResources([resourceType], { onAvailable });
};
resourceWatcher.watchResources([resourceType], {

View File

@@ -1200,8 +1200,7 @@ StyleEditorUI.prototype = {
}
},
async _onResourceAvailable(resources) {
for (const resource of resources) {
async _onResourceAvailable({ resource }) {
if (
resource.resourceType === this._toolbox.resourceWatcher.TYPES.STYLESHEET
) {
@@ -1213,11 +1212,11 @@ StyleEditorUI.prototype = {
}
await onStyleSheetHandled;
continue;
return;
}
if (!resource.targetFront.isTopLevel) {
continue;
return;
}
if (resource.name === "dom-loading") {
@@ -1232,17 +1231,13 @@ StyleEditorUI.prototype = {
} else if (resource.name === "dom-complete") {
await this._waitForLoadingStyleSheets();
}
}
},
async _onResourceUpdated(updates) {
for (const { update } of updates) {
async _onResourceUpdated({ update }) {
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": {
@@ -1264,7 +1259,6 @@ StyleEditorUI.prototype = {
}
}
}
}
},
async _onTargetAvailable({ targetFront }) {

View File

@@ -70,10 +70,8 @@ async function generateConsoleApiStubs() {
// resource to `handleConsoleMessage`, dynamically updated for each command.
let handleConsoleMessage = function() {};
const onConsoleMessage = resources => {
for (const resource of resources) {
const onConsoleMessage = ({ resource }) => {
handleConsoleMessage(resource);
}
};
await resourceWatcher.watchResources(
[resourceWatcher.TYPES.CONSOLE_MESSAGE],

View File

@@ -68,10 +68,8 @@ async function generateCssMessageStubs() {
// resource to `handleErrorMessage`, dynamically updated for each command.
let handleCSSMessage = function() {};
const onCSSMessageAvailable = resources => {
for (const resource of resources) {
const onCSSMessageAvailable = ({ resource }) => {
handleCSSMessage(resource);
}
};
await resourceWatcher.watchResources([resourceWatcher.TYPES.CSS_MESSAGE], {

View File

@@ -70,15 +70,11 @@ async function generateNetworkEventStubs() {
let addNetworkStub = function() {};
let addNetworkUpdateStub = function() {};
const onAvailable = resources => {
for (const resource of resources) {
const onAvailable = resource => {
addNetworkStub(resource);
}
};
const onUpdated = updates => {
for (const { resource } of updates) {
const onUpdated = resource => {
addNetworkUpdateStub(resource);
}
};
await resourceWatcher.watchResources([resourceWatcher.TYPES.NETWORK_EVENT], {
@@ -89,14 +85,14 @@ async function generateNetworkEventStubs() {
for (const [key, code] of getCommands()) {
const noExpectedUpdates = 7;
const networkEventDone = new Promise(resolve => {
addNetworkStub = resource => {
addNetworkStub = ({ resourceType, targetFront, resource }) => {
stubs.set(key, getCleanedPacket(key, getOrderedResource(resource)));
resolve();
};
});
const networkEventUpdateDone = new Promise(resolve => {
let updateCount = 0;
addNetworkUpdateStub = resource => {
addNetworkUpdateStub = ({ resourceType, targetFront, resource }) => {
const updateKey = `${key} update`;
// make sure all the updates have been happened
if (updateCount >= noExpectedUpdates) {

View File

@@ -72,10 +72,8 @@ async function generatePageErrorStubs() {
// resource to `handleErrorMessage`, dynamically updated for each command.
let handleErrorMessage = function() {};
const onErrorMessageAvailable = resources => {
for (const resource of resources) {
const onErrorMessageAvailable = ({ resource }) => {
handleErrorMessage(resource);
}
};
await resourceWatcher.watchResources([resourceWatcher.TYPES.ERROR_MESSAGE], {
onAvailable: onErrorMessageAvailable,

View File

@@ -80,10 +80,8 @@ async function generatePlatformMessagesStubs() {
// resource to `handlePlatformMessage`, dynamically updated for each command.
let handlePlatformMessage = function() {};
const onPlatformMessageAvailable = resources => {
for (const resource of resources) {
const onPlatformMessageAvailable = ({ resource }) => {
handlePlatformMessage(resource);
}
};
await resourceWatcher.watchResources(
[resourceWatcher.TYPES.PLATFORM_MESSAGE],

View File

@@ -1006,7 +1006,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 "${url}" wasn't found`);
}, "network entry for the URL wasn't found");
ok(true, "The attached url is correct.");

View File

@@ -353,36 +353,31 @@ class WebConsoleUI {
});
}
_onResourceAvailable(resources) {
_onResourceAvailable({ resourceType, targetFront, resource }) {
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 (
!this.wrapper ||
((resource.resourceType === TYPES.ERROR_MESSAGE ||
resource.resourceType === TYPES.CSS_MESSAGE) &&
((resourceType === TYPES.ERROR_MESSAGE ||
resourceType === TYPES.CSS_MESSAGE) &&
resource.pageError?.isForwardedFromContentProcess &&
(this.isBrowserToolboxConsole || this.isBrowserConsole) &&
this.fissionSupport)
) {
continue;
return;
}
this.wrapper.dispatchMessageAdd(resource);
}
}
_onResourceUpdated(updates) {
for (const { resource } of updates) {
if (
resource.resourceType == this.hud.resourceWatcher.TYPES.NETWORK_EVENT
) {
_onResourceUpdated({ resourceType, targetFront, resource }) {
if (resourceType == this.hud.resourceWatcher.TYPES.NETWORK_EVENT) {
this.wrapper.dispatchMessageUpdate(resource);
}
}
}
/**
* Called any time a new target is available.

View File

@@ -295,8 +295,6 @@ class ResourceWatcher {
* which describes the resource.
*/
async _onResourceAvailable({ targetFront, watcherFront }, resources) {
let currentType = null;
let resourceBuffer = [];
for (let resource of resources) {
const { resourceType } = resource;
@@ -322,24 +320,15 @@ class ResourceWatcher {
});
}
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._availableListeners.emit(resourceType, {
// XXX: We may want to read resource.resourceType instead of passing this resourceType argument?
resourceType,
targetFront,
resource,
});
this._cache.push(resource);
}
// Flush the buffered resources if there is any
if (resourceBuffer.length > 0) {
this._availableListeners.emit(currentType, resourceBuffer);
}
}
/**
@@ -375,8 +364,6 @@ class ResourceWatcher {
* }
*/
async _onResourceUpdated({ targetFront, watcherFront }, updates) {
let currentType = null;
let resourceBuffer = [];
for (const update of updates) {
const { resourceType, resourceId, resourceUpdates } = update;
@@ -401,25 +388,13 @@ class ResourceWatcher {
Object.assign(existingResource, resourceUpdates);
}
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({
this._updatedListeners.emit(resourceType, {
resourceType,
targetFront,
resource: existingResource,
update,
});
}
// Flush the buffered resources if there is any
if (resourceBuffer.length > 0) {
this._updatedListeners.emit(currentType, resourceBuffer);
}
}
/**
@@ -427,8 +402,6 @@ 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;
@@ -457,21 +430,11 @@ class ResourceWatcher {
);
}
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);
this._destroyedListeners.emit(resourceType, {
resourceType,
targetFront,
resource,
});
}
}
@@ -552,11 +515,15 @@ class ResourceWatcher {
}
async _forwardCachedResources(resourceTypes, onAvailable) {
await onAvailable(
this._cache.filter(resource =>
resourceTypes.includes(resource.resourceType)
)
);
for (const resource of this._cache) {
if (resourceTypes.includes(resource.resourceType)) {
await onAvailable({
resourceType: resource.resourceType,
targetFront: resource.targetFront,
resource,
});
}
}
}
/**

View File

@@ -31,7 +31,7 @@ add_task(async function() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => cachedResources1.push(...resources),
onAvailable: ({ resource }) => cachedResources1.push(resource),
}
);
@@ -40,7 +40,7 @@ add_task(async function() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => cachedResources2.push(...resources),
onAvailable: ({ resource }) => cachedResources2.push(resource),
}
);
@@ -73,7 +73,7 @@ add_task(async function() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
}
);
@@ -90,7 +90,7 @@ add_task(async function() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => cachedResources.push(...resources),
onAvailable: ({ resource }) => cachedResources.push(resource),
}
);
@@ -134,7 +134,7 @@ add_task(async function() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => cachedResources.push(...resources),
onAvailable: ({ resource }) => cachedResources.push(resource),
}
);
@@ -163,7 +163,7 @@ add_task(async function() {
ResourceWatcher.TYPES.ERROR_MESSAGE,
],
{
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
}
);
@@ -194,7 +194,7 @@ add_task(async function() {
ResourceWatcher.TYPES.ERROR_MESSAGE,
],
{
onAvailable: resources => cachedResources.push(...resources),
onAvailable: ({ resource }) => cachedResources.push(resource),
}
);
@@ -228,7 +228,7 @@ async function testIgnoreExistingResources(isFirstListenerIgnoreExisting) {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => cachedResources1.push(...resources),
onAvailable: ({ resource }) => cachedResources1.push(resource),
ignoreExistingResources: isFirstListenerIgnoreExisting,
}
);
@@ -238,7 +238,7 @@ async function testIgnoreExistingResources(isFirstListenerIgnoreExisting) {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => cachedResources2.push(...resources),
onAvailable: ({ resource }) => cachedResources2.push(resource),
ignoreExistingResources: !isFirstListenerIgnoreExisting,
}
);

View File

@@ -35,10 +35,9 @@ async function testConsoleMessagesResources() {
const expectedExistingCalls = [...expectedExistingConsoleCalls];
const expectedRuntimeCalls = [...expectedRuntimeConsoleCalls];
const onRuntimeDone = new Promise(resolve => (runtimeDoneResolve = resolve));
const onAvailable = resources => {
for (const resource of resources) {
const onAvailable = ({ resourceType, targetFront, resource }) => {
is(
resource.resourceType,
resourceType,
ResourceWatcher.TYPES.CONSOLE_MESSAGE,
"Received a message"
);
@@ -51,7 +50,6 @@ async function testConsoleMessagesResources() {
if (expectedRuntimeCalls.length == 0) {
runtimeDoneResolve();
}
}
};
await resourceWatcher.watchResources(
@@ -103,7 +101,7 @@ async function testConsoleMessagesResourcesWithIgnoreExistingResources() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
ignoreExistingResources: true,
}
);

View File

@@ -43,7 +43,7 @@ add_task(async function() {
const availableResources = [];
await resourceWatcher.watchResources([ResourceWatcher.TYPES.CSS_CHANGE], {
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
});
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: resources => existingResources.push(...resources),
onAvailable: ({ resource }) => existingResources.push(resource),
});
await waitUntil(() => existingResources.length === 4);
is(availableResources[0], existingResources[0], "1st resource is correct");

View File

@@ -163,8 +163,7 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
let done;
const onAllMessagesReceived = new Promise(resolve => (done = resolve));
const onAvailable = resources => {
for (const resource of resources) {
const onAvailable = ({ resourceType, targetFront, resource }) => {
const { pageError } = resource;
is(
@@ -175,22 +174,19 @@ function setupOnAvailableFunction(targetList, receivedMessages) {
if (!pageError.sourceName.includes("test_css_messages")) {
info(`Ignore error from unknown source: "${pageError.sourceName}"`);
continue;
return;
}
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 };
}

View File

@@ -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: resources => documentEvents.push(...resources),
onAvailable: ({ resource }) => documentEvents.push(resource),
ignoreExistingResources: true,
});
is(documentEvents.length, 0, "Existing document events are not fired");
@@ -129,15 +129,13 @@ function assertEvents(loadingEvent, interactiveEvent, completeEvent) {
class ResourceListener {
_listeners = new Map();
dispatch(resources) {
for (const resource of resources) {
dispatch({ resourceType, targetFront, resource }) {
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));

View File

@@ -52,8 +52,7 @@ async function testErrorMessagesResources() {
let done;
const onAllErrorReceived = new Promise(resolve => (done = resolve));
const onAvailable = resources => {
for (const resource of resources) {
const onAvailable = ({ resourceType, targetFront, resource }) => {
const { pageError } = resource;
is(
@@ -64,7 +63,7 @@ async function testErrorMessagesResources() {
if (!pageError.sourceName.includes("test_page_errors")) {
info(`Ignore error from unknown source: "${pageError.sourceName}"`);
continue;
return;
}
const index = receivedMessages.length;
@@ -77,7 +76,6 @@ async function testErrorMessagesResources() {
if (receivedMessages.length == expectedMessages.length) {
done();
}
}
};
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGE], {
@@ -119,7 +117,7 @@ async function testErrorMessagesResourcesWithIgnoreExistingResources() {
const availableResources = [];
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGE], {
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
ignoreExistingResources: true,
});
is(

View File

@@ -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 = resources => availableResources.push(...resources);
const onAvailable = ({ resource }) => availableResources.push(resource);
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.CONSOLE_MESSAGE],
{ onAvailable }

View File

@@ -128,8 +128,7 @@ async function testNetworkEventResources(options) {
const waitOnAllExpectedUpdatesForExistingRequests = new Promise(resolve => {
const existingRequestUrl = `${EXAMPLE_DOMAIN}existing_post.html`;
onResourceAvailable = resources => {
for (const resource of resources) {
onResourceAvailable = ({ resource }) => {
// A blocked request would only have two updates so lets also resolve here
if (
resource.request.url == existingRequestUrl &&
@@ -138,17 +137,15 @@ 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 = updates => {
for (const { resource } of updates) {
onResourceUpdated = ({ resource }) => {
// Wait until all the update events have fired for the existing request.
// Handle both blocked and unblocked requests
if (
@@ -158,13 +155,12 @@ 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
@@ -194,10 +190,9 @@ async function testNetworkEventResources(options) {
() => expectedOnUpdatedCounts == 0
);
const onAvailable = resources => {
for (const resource of resources) {
const onAvailable = ({ resourceType, targetFront, resource }) => {
is(
resource.resourceType,
resourceType,
ResourceWatcher.TYPES.NETWORK_EVENT,
"Received a network event resource"
);
@@ -208,13 +203,11 @@ async function testNetworkEventResources(options) {
updates: [...resource.updates],
};
expectedOnAvailableCounts--;
}
};
const onUpdated = updates => {
for (const { resource } of updates) {
const onUpdated = ({ resourceType, targetFront, resource }) => {
is(
resource.resourceType,
resourceType,
ResourceWatcher.TYPES.NETWORK_EVENT,
"Received a network update event resource"
);
@@ -225,7 +218,6 @@ async function testNetworkEventResources(options) {
updates: [...resource.updates],
};
expectedOnUpdatedCounts--;
}
};
await resourceWatcher.watchResources([ResourceWatcher.TYPES.NETWORK_EVENT], {

View File

@@ -42,10 +42,9 @@ async function testPlatformMessagesResources() {
let done;
const onAllMessagesReceived = new Promise(resolve => (done = resolve));
const onAvailable = resources => {
for (const resource of resources) {
const onAvailable = ({ resourceType, targetFront, resource }) => {
if (!expectedMessages.includes(resource.message)) {
continue;
return;
}
is(
@@ -69,7 +68,6 @@ async function testPlatformMessagesResources() {
if (receivedMessages.length == expectedMessages.length) {
done();
}
}
};
await resourceWatcher.watchResources(
@@ -112,14 +110,12 @@ async function testPlatformMessagesResourcesWithIgnoreExistingResources() {
await resourceWatcher.watchResources(
[ResourceWatcher.TYPES.PLATFORM_MESSAGE],
{
onAvailable: resources => {
for (const resource of resources) {
onAvailable: ({ resource }) => {
if (!expectedMessages.includes(resource.message)) {
continue;
return;
}
availableResources.push(resource);
}
},
ignoreExistingResources: true,
}

View File

@@ -34,7 +34,7 @@ add_task(async function() {
info("Call watchResources([ROOT_NODE], ...)");
let onAvailableCounter = 0;
const onAvailable = resources => (onAvailableCounter += resources.length);
const onAvailable = () => onAvailableCounter++;
await resourceWatcher.watchResources([ResourceWatcher.TYPES.ROOT_NODE], {
onAvailable,
});
@@ -91,16 +91,16 @@ 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 root1 = await rootNodePromise;
const { resource: root1, resourceType } = await rootNodePromise;
ok(!!root1, "onAvailable has been called with a valid argument");
is(
root1.resourceType,
resourceType,
ResourceWatcher.TYPES.ROOT_NODE,
"The resource has the expected type"
);
@@ -113,7 +113,7 @@ add_task(async function testRootNodeFrontIsCorrect() {
rootNodePromise = new Promise(r => (rootNodeResolve = r));
browser.reload();
const root2 = await rootNodePromise;
const { resource: 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 root3 = await rootNodePromise;
const { resource: 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");

View File

@@ -32,12 +32,10 @@ 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 = resources => {
for (const resource of resources) {
if (resource.resourceType === CONSOLE_MESSAGE) {
const onAvailable = ({ resource, resourceType }) => {
if (resourceType === CONSOLE_MESSAGE) {
receivedMessages.push(resource);
}
}
};
info("Call watchResources([CONSOLE_MESSAGE, ROOT_NODE], ...)");

View File

@@ -106,7 +106,7 @@ add_task(async function() {
info("Check whether ResourceWatcher gets existing stylesheet");
const availableResources = [];
await resourceWatcher.watchResources([ResourceWatcher.TYPES.STYLESHEET], {
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
});
is(
@@ -176,8 +176,8 @@ add_task(async function() {
const availableResources = [];
const updates = [];
await resourceWatcher.watchResources([ResourceWatcher.TYPES.STYLESHEET], {
onAvailable: resources => availableResources.push(...resources),
onUpdated: newUpdates => updates.push(...newUpdates),
onAvailable: ({ resource }) => availableResources.push(resource),
onUpdated: ({ resource, update }) => updates.push({ resource, update }),
});
is(
availableResources.length,

View File

@@ -24,7 +24,7 @@ add_task(async function() {
info("Check available resources at initial");
const availableResources = [];
await resourceWatcher.watchResources([ResourceWatcher.TYPES.WEBSOCKET], {
onAvailable: resources => availableResources.push(...resources),
onAvailable: ({ resource }) => availableResources.push(resource),
});
is(
availableResources.length,
@@ -101,7 +101,7 @@ add_task(async function() {
info("Check existing resources");
const existingResources = [];
await resourceWatcher.watchResources([ResourceWatcher.TYPES.WEBSOCKET], {
onAvailable: resources => existingResources.push(...resources),
onAvailable: ({ resource }) => existingResources.push(resource),
});
is(
availableResources.length,