зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1810687 - [messagehandler] Group SessionData initial updates by moduleName and category. r=webdriver-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D169312
This commit is contained in:
Родитель
498077e020
Коммит
231b3e98e0
|
@ -72,29 +72,51 @@ export class WindowGlobalMessageHandler extends MessageHandler {
|
|||
type: WindowGlobalMessageHandler.type,
|
||||
};
|
||||
|
||||
const sessionDataPromises = sessionDataItems.map(sessionDataItem => {
|
||||
const { moduleName, category, contextDescriptor } = sessionDataItem;
|
||||
// Create a Map with the structure moduleName -> category -> relevant session data items.
|
||||
const structuredUpdates = new Map();
|
||||
for (const sessionDataItem of sessionDataItems) {
|
||||
const { category, contextDescriptor, moduleName } = sessionDataItem;
|
||||
|
||||
if (!this.matchesContext(contextDescriptor)) {
|
||||
return Promise.resolve();
|
||||
continue;
|
||||
}
|
||||
if (!structuredUpdates.has(moduleName)) {
|
||||
// Skip session data item if the module is not present
|
||||
// for the destination.
|
||||
if (!this.moduleCache.hasModule(moduleName, destination)) {
|
||||
continue;
|
||||
}
|
||||
structuredUpdates.set(moduleName, new Map());
|
||||
}
|
||||
|
||||
// Don't apply session data if the module is not present
|
||||
// for the destination.
|
||||
if (!this.moduleCache.hasModule(moduleName, destination)) {
|
||||
return Promise.resolve();
|
||||
if (!structuredUpdates.get(moduleName).has(category)) {
|
||||
structuredUpdates.get(moduleName).set(category, new Set());
|
||||
}
|
||||
|
||||
return this.handleCommand({
|
||||
moduleName,
|
||||
commandName: "_applySessionData",
|
||||
params: {
|
||||
category,
|
||||
initial: true,
|
||||
sessionData: sessionDataItems,
|
||||
},
|
||||
destination,
|
||||
});
|
||||
});
|
||||
structuredUpdates
|
||||
.get(moduleName)
|
||||
.get(category)
|
||||
.add(sessionDataItem);
|
||||
}
|
||||
|
||||
const sessionDataPromises = [];
|
||||
|
||||
for (const [moduleName, categories] of structuredUpdates.entries()) {
|
||||
for (const [category, relevantSessionData] of categories.entries()) {
|
||||
sessionDataPromises.push(
|
||||
this.handleCommand({
|
||||
moduleName,
|
||||
commandName: "_applySessionData",
|
||||
params: {
|
||||
category,
|
||||
initial: true,
|
||||
sessionData: Array.from(relevantSessionData),
|
||||
},
|
||||
destination,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(sessionDataPromises);
|
||||
|
||||
|
|
|
@ -81,5 +81,14 @@ add_task(async function test_session_data_update_categories() {
|
|||
assertUpdate(processedUpdates.at(-2), ["value1-2", "value1-3"], "category1");
|
||||
assertUpdate(processedUpdates.at(-1), ["value2-1"], "category2");
|
||||
|
||||
info("Opening a new tab triggers an update for each category");
|
||||
const tab2 = await addTab(TEST_PAGE);
|
||||
const browsingContext2 = tab2.linkedBrowser.browsingContext;
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
is(processedUpdates.length, 2);
|
||||
assertUpdate(processedUpdates.at(-2), ["value1-2", "value1-3"], "category1");
|
||||
assertUpdate(processedUpdates.at(-1), ["value2-1"], "category2");
|
||||
|
||||
root.destroy();
|
||||
gBrowser.removeTab(tab2);
|
||||
});
|
||||
|
|
|
@ -42,10 +42,8 @@ add_task(async function test_session_data_update_contexts() {
|
|||
const tab2 = await addTab(TEST_PAGE);
|
||||
const browsingContext2 = tab2.linkedBrowser.browsingContext;
|
||||
|
||||
// TODO: We currently call applyInitialSessionDataItems too many times on
|
||||
// MessageHandler startup, once per value. See Bug 1810687.
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
todo_is(processedUpdates.length, 1);
|
||||
is(processedUpdates.length, 1);
|
||||
assertUpdate(
|
||||
processedUpdates.at(-1),
|
||||
["text-1", "text-2", "text-3"],
|
||||
|
@ -70,7 +68,7 @@ add_task(async function test_session_data_update_contexts() {
|
|||
);
|
||||
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
todo_is(processedUpdates.length, 2);
|
||||
is(processedUpdates.length, 2);
|
||||
assertUpdate(
|
||||
processedUpdates.at(-1),
|
||||
["text-1", "text-2", "text-3", "text-4", "text-5"],
|
||||
|
@ -95,7 +93,7 @@ add_task(async function test_session_data_update_contexts() {
|
|||
);
|
||||
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
todo_is(processedUpdates.length, 3);
|
||||
is(processedUpdates.length, 3);
|
||||
assertUpdate(
|
||||
processedUpdates.at(-1),
|
||||
["text-2", "text-3", "text-4"],
|
||||
|
@ -134,7 +132,7 @@ add_task(async function test_session_data_update_contexts() {
|
|||
);
|
||||
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
todo_is(processedUpdates.length, 4);
|
||||
is(processedUpdates.length, 4);
|
||||
assertUpdate(
|
||||
processedUpdates.at(-1),
|
||||
["text-2", "text-3", "text-4", "text-6"],
|
||||
|
@ -165,7 +163,7 @@ add_task(async function test_session_data_update_contexts() {
|
|||
);
|
||||
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
todo_is(processedUpdates.length, 5);
|
||||
is(processedUpdates.length, 5);
|
||||
assertUpdate(
|
||||
processedUpdates.at(-1),
|
||||
["text-2", "text-3", "text-4", "text-6", "text-7"],
|
||||
|
@ -186,7 +184,7 @@ add_task(async function test_session_data_update_contexts() {
|
|||
);
|
||||
|
||||
processedUpdates = await getUpdates(root, browsingContext2);
|
||||
todo_is(processedUpdates.length, 6);
|
||||
is(processedUpdates.length, 6);
|
||||
assertUpdate(
|
||||
processedUpdates.at(-1),
|
||||
["text-2", "text-3", "text-4", "text-6"],
|
||||
|
|
Загрузка…
Ссылка в новой задаче