mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 14:25:49 +00:00
Backed out 2 changesets (bug 1725111) for causing failures on browser_session_data_broadcast.js. CLOSED TREE
Backed out changeset 5a48f5832e72 (bug 1725111) Backed out changeset 9055935bf63f (bug 1725111)
This commit is contained in:
parent
883da7e971
commit
e694b076ce
@ -36,16 +36,16 @@ XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
|
||||
* @property {String} type
|
||||
* The type of context, one of CONTEXT_DESCRIPTOR_TYPES
|
||||
* @property {String=} id
|
||||
* Unique id of a given context for the provided type.
|
||||
* For CONTEXT_DESCRIPTOR_TYPES.ALL, id can be ommitted.
|
||||
* For CONTEXT_DESCRIPTOR_TYPES.TOP_BROWSING_CONTEXT, the id should be a
|
||||
* browserId.
|
||||
* Unique id of a given context for the provided type. Optional for
|
||||
* CONTEXT_DESCRIPTOR_TYPES.ALL, since there is only one context
|
||||
*/
|
||||
|
||||
// Enum of ContextDescriptor types.
|
||||
// TODO: At the moment we only support the type "all", but additional context
|
||||
// types will be added. See comment for the Context type definition.
|
||||
//
|
||||
const CONTEXT_DESCRIPTOR_TYPES = {
|
||||
ALL: "all",
|
||||
TOP_BROWSING_CONTEXT: "top-browsing-context",
|
||||
};
|
||||
|
||||
/**
|
||||
@ -169,14 +169,9 @@ class MessageHandler extends EventEmitter {
|
||||
* @typedef {Object} CommandDestination
|
||||
* @property {String} type
|
||||
* One of MessageHandler.type.
|
||||
* @property {String=} id
|
||||
* @property {String} id
|
||||
* Unique context identifier. The format depends on the type.
|
||||
* For WINDOW_GLOBAL destinations, this is a browsing context id.
|
||||
* Optional, should only be provided if `contextDescriptor` is missing.
|
||||
* @property {ContextDescriptor=} contextDescriptor
|
||||
* Descriptor used to match several contexts, which will all receive the
|
||||
* command.
|
||||
* Optional, should only be provided if `id` is missing.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -9,7 +9,6 @@ support-files =
|
||||
prefs =
|
||||
remote.messagehandler.modulecache.useBrowserTestRoot=true
|
||||
|
||||
[browser_filter_top_browsing_context.js]
|
||||
[browser_only_content_process.js]
|
||||
[browser_two_tabs.js]
|
||||
[browser_two_tabs_with_params.js]
|
||||
|
@ -1,83 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const COM_TEST_PAGE = "https://example.com/document-builder.sjs?html=COM";
|
||||
const FRAME_TEST_PAGE = createTestMarkupWithFrames();
|
||||
|
||||
add_task(async function test_broadcasting_filter_top_browsing_context() {
|
||||
info("Navigate the initial tab to the COM test URL");
|
||||
const tab1 = gBrowser.selectedTab;
|
||||
await loadURL(tab1.linkedBrowser, COM_TEST_PAGE);
|
||||
const browsingContext1 = tab1.linkedBrowser.browsingContext;
|
||||
|
||||
info("Open a second tab on the frame test URL");
|
||||
const tab2 = await addTab(FRAME_TEST_PAGE);
|
||||
const browsingContext2 = tab2.linkedBrowser.browsingContext;
|
||||
|
||||
const contextsForTab2 = tab2.linkedBrowser.browsingContext.getAllBrowsingContextsInSubtree();
|
||||
is(
|
||||
contextsForTab2.length,
|
||||
4,
|
||||
"Frame test tab has 3 children contexts (4 in total)"
|
||||
);
|
||||
|
||||
const rootMessageHandler = createRootMessageHandler(
|
||||
"session-id-broadcasting_filter_top_browsing_context"
|
||||
);
|
||||
|
||||
const broadcastValue1 = await sendBroadcastForTopBrowsingContext(
|
||||
browsingContext1,
|
||||
rootMessageHandler
|
||||
);
|
||||
|
||||
ok(
|
||||
Array.isArray(broadcastValue1),
|
||||
"The broadcast returned an array of values"
|
||||
);
|
||||
|
||||
is(broadcastValue1.length, 1, "The broadcast returned one value as expected");
|
||||
|
||||
ok(
|
||||
broadcastValue1.includes("broadcast-" + browsingContext1.id),
|
||||
"The broadcast returned the expected value from tab1"
|
||||
);
|
||||
|
||||
const broadcastValue2 = await sendBroadcastForTopBrowsingContext(
|
||||
browsingContext2,
|
||||
rootMessageHandler
|
||||
);
|
||||
|
||||
ok(
|
||||
Array.isArray(broadcastValue2),
|
||||
"The broadcast returned an array of values"
|
||||
);
|
||||
|
||||
is(broadcastValue2.length, 4, "The broadcast returned 4 values as expected");
|
||||
|
||||
for (const context of contextsForTab2) {
|
||||
ok(
|
||||
broadcastValue2.includes("broadcast-" + context.id),
|
||||
"The broadcast contains the value for browsing context " + context.id
|
||||
);
|
||||
}
|
||||
|
||||
rootMessageHandler.destroy();
|
||||
});
|
||||
|
||||
function sendBroadcastForTopBrowsingContext(
|
||||
topBrowsingContext,
|
||||
rootMessageHandler
|
||||
) {
|
||||
return sendTestBroadcastCommand(
|
||||
"commandwindowglobalonly",
|
||||
"testBroadcast",
|
||||
{},
|
||||
{
|
||||
type: CONTEXT_DESCRIPTOR_TYPES.TOP_BROWSING_CONTEXT,
|
||||
id: topBrowsingContext.browserId,
|
||||
},
|
||||
rootMessageHandler
|
||||
);
|
||||
}
|
@ -27,7 +27,6 @@ add_task(async function test_broadcasting_only_content_process() {
|
||||
"commandwindowglobalonly",
|
||||
"testBroadcast",
|
||||
{},
|
||||
contextDescriptorAll,
|
||||
rootMessageHandler
|
||||
);
|
||||
|
||||
|
@ -23,7 +23,6 @@ add_task(async function test_broadcasting_two_tabs_command() {
|
||||
"commandwindowglobalonly",
|
||||
"testBroadcast",
|
||||
{},
|
||||
contextDescriptorAll,
|
||||
rootMessageHandler
|
||||
);
|
||||
|
||||
|
@ -25,7 +25,6 @@ add_task(async function test_broadcasting_two_tabs_with_params_command() {
|
||||
{
|
||||
value: "some-value",
|
||||
},
|
||||
contextDescriptorAll,
|
||||
rootMessageHandler
|
||||
);
|
||||
ok(
|
||||
|
@ -24,7 +24,6 @@ add_task(async function test_broadcasting_two_windows_command() {
|
||||
"commandwindowglobalonly",
|
||||
"testBroadcast",
|
||||
{},
|
||||
contextDescriptorAll,
|
||||
rootMessageHandler
|
||||
);
|
||||
|
||||
|
@ -18,7 +18,6 @@ add_task(async function test_broadcasting_with_frames() {
|
||||
"commandwindowglobalonly",
|
||||
"testBroadcast",
|
||||
{},
|
||||
contextDescriptorAll,
|
||||
rootMessageHandler
|
||||
);
|
||||
|
||||
|
@ -10,17 +10,9 @@ Services.scriptloader.loadSubScript(
|
||||
this
|
||||
);
|
||||
|
||||
var { CONTEXT_DESCRIPTOR_TYPES } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm"
|
||||
);
|
||||
|
||||
var contextDescriptorAll = {
|
||||
type: CONTEXT_DESCRIPTOR_TYPES.ALL,
|
||||
};
|
||||
|
||||
/**
|
||||
* Broadcast the provided method to WindowGlobal contexts on a MessageHandler
|
||||
* network.
|
||||
* Broadcast the provided method to all WindowGlobal contexts on a
|
||||
* MessageHandler network.
|
||||
* Returns a promise which will resolve the result of the command broadcast.
|
||||
*
|
||||
* @param {String} module
|
||||
@ -29,21 +21,13 @@ var contextDescriptorAll = {
|
||||
* The name of the command to broadcast.
|
||||
* @param {Object} params
|
||||
* The parameters for the command.
|
||||
* @param {ContextDescriptor} contextDescriptor
|
||||
* The context descriptor to use for this broadcast
|
||||
* @param {RootMessageHandler} rootMessageHandler
|
||||
* The root of the MessageHandler network.
|
||||
* @return {Promise.<Array>}
|
||||
* Promise which resolves an array where each item is the result of the
|
||||
* command handled by an individual context.
|
||||
*/
|
||||
function sendTestBroadcastCommand(
|
||||
module,
|
||||
command,
|
||||
params,
|
||||
contextDescriptor,
|
||||
rootMessageHandler
|
||||
) {
|
||||
function sendTestBroadcastCommand(module, command, params, rootMessageHandler) {
|
||||
const { WindowGlobalMessageHandler } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/messagehandler/WindowGlobalMessageHandler.jsm"
|
||||
);
|
||||
@ -54,8 +38,8 @@ function sendTestBroadcastCommand(
|
||||
commandName: command,
|
||||
params,
|
||||
destination: {
|
||||
contextDescriptor,
|
||||
type: WindowGlobalMessageHandler.type,
|
||||
broadcast: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
|
||||
CONTEXT_DESCRIPTOR_TYPES:
|
||||
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
|
||||
MessageHandlerFrameActor:
|
||||
"chrome://remote/content/shared/messagehandler/transports/js-window-actors/MessageHandlerFrameActor.jsm",
|
||||
});
|
||||
@ -48,9 +46,9 @@ class FrameTransport {
|
||||
* being processed by WINDOW_GLOBAL MessageHandlers.
|
||||
*/
|
||||
forwardCommand(command) {
|
||||
if (command.destination.id && command.destination.contextDescriptor) {
|
||||
if (command.destination.id && command.destination.broadcast) {
|
||||
throw new Error(
|
||||
"Invalid command destination with both 'id' and 'contextDescriptor' properties"
|
||||
"Invalid command destination with both 'id' and 'broadcast' properties"
|
||||
);
|
||||
}
|
||||
|
||||
@ -65,21 +63,18 @@ class FrameTransport {
|
||||
return this._sendCommandToBrowsingContext(command, browsingContext);
|
||||
}
|
||||
|
||||
// ... otherwise broadcast to destinations matching the contextDescriptor.
|
||||
if (command.destination.contextDescriptor) {
|
||||
// ... otherwise broadcast to all registered destinations.
|
||||
if (command.destination.broadcast) {
|
||||
return this._broadcastCommand(command);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Unrecognized command destination, missing 'id' or 'contextDescriptor' properties"
|
||||
"Unrecognized command destination, missing 'id' or 'broadcast' properties"
|
||||
);
|
||||
}
|
||||
|
||||
_broadcastCommand(command) {
|
||||
const { contextDescriptor } = command.destination;
|
||||
const browsingContexts = this._getBrowsingContextsForDescriptor(
|
||||
contextDescriptor
|
||||
);
|
||||
const browsingContexts = this._getAllBrowsingContexts();
|
||||
|
||||
return Promise.all(
|
||||
browsingContexts.map(async browsingContext => {
|
||||
@ -109,35 +104,7 @@ class FrameTransport {
|
||||
return `[object ${this.constructor.name} ${this._messageHandler.name}]`;
|
||||
}
|
||||
|
||||
_getBrowsingContextsForDescriptor(contextDescriptor) {
|
||||
const { id, type } = contextDescriptor;
|
||||
if (type === CONTEXT_DESCRIPTOR_TYPES.ALL) {
|
||||
return this._getBrowsingContexts();
|
||||
}
|
||||
|
||||
if (type === CONTEXT_DESCRIPTOR_TYPES.TOP_BROWSING_CONTEXT) {
|
||||
return this._getBrowsingContexts({ browserId: id });
|
||||
}
|
||||
|
||||
// TODO: Handle other types of context descriptors.
|
||||
throw new Error(
|
||||
`Unsupported contextDescriptor type for broadcasting: ${type}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all browsing contexts, optionally matching the provided options.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {String=} options.browserId
|
||||
* The id of the browser to filter the browsing contexts by (optional).
|
||||
* @return {Array<BrowsingContext>}
|
||||
* The browsing contexts matching the provided options or all browsing contexts
|
||||
* if no options are provided.
|
||||
*/
|
||||
_getBrowsingContexts(options = {}) {
|
||||
// extract browserId from options
|
||||
const { browserId } = options;
|
||||
_getAllBrowsingContexts() {
|
||||
let browsingContexts = [];
|
||||
// Fetch all top level window's browsing contexts
|
||||
// Note that getWindowEnumerator works from all processes, including the content process.
|
||||
@ -166,15 +133,6 @@ class FrameTransport {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If a browserId was provided, skip browsing contexts which are not
|
||||
// associated with this browserId.
|
||||
if (
|
||||
typeof browserId !== "undefined" &&
|
||||
browsingContext.browserId !== browserId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
browsingContexts = browsingContexts.concat(
|
||||
browsingContext.getAllBrowsingContextsInSubtree()
|
||||
);
|
||||
|
@ -11,8 +11,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
CONTEXT_DESCRIPTOR_TYPES:
|
||||
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
|
||||
Module: "chrome://remote/content/shared/messagehandler/Module.jsm",
|
||||
});
|
||||
|
||||
@ -32,7 +30,7 @@ class Log extends Module {
|
||||
moduleName: "log",
|
||||
category: "event",
|
||||
contextDescriptor: {
|
||||
type: CONTEXT_DESCRIPTOR_TYPES.ALL,
|
||||
type: "all",
|
||||
},
|
||||
values: ["log.entryAdded"],
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user