Bug 1525634 - Preserve lazyness of the old tab when adopted by another window. r=jaws

Differential Revision: https://phabricator.services.mozilla.com/D18982

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Oriol Brufau 2019-02-14 19:48:58 +00:00
Родитель 93d45e85e9
Коммит c3577f0fc0
2 изменённых файлов: 35 добавлений и 25 удалений

Просмотреть файл

@ -47,58 +47,67 @@ add_task(async function test() {
add_task(async function testLazyTabs() {
let params = {createLazyBrowser: true};
let tabs = [];
let oldTabs = [];
let numTabs = 4;
for (let i = 0; i < numTabs; ++i) {
tabs.push(BrowserTestUtils.addTab(gBrowser, `http://example.com/?${i}`, params));
oldTabs.push(BrowserTestUtils.addTab(gBrowser, `http://example.com/?${i}`, params));
}
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await BrowserTestUtils.switchTab(gBrowser, oldTabs[0]);
for (let i = 1; i < numTabs; ++i) {
await triggerClickOn(tabs[i], { ctrlKey: true });
await triggerClickOn(oldTabs[i], { ctrlKey: true });
}
isnot(tabs[0].linkedPanel, "", `Tab 0 shouldn't be lazy`);
isnot(oldTabs[0].linkedPanel, "", `Old tab 0 shouldn't be lazy`);
for (let i = 1; i < numTabs; ++i) {
is(tabs[i].linkedPanel, "", `Tab ${i} should be lazy`);
is(oldTabs[i].linkedPanel, "", `Old tab ${i} should be lazy`);
}
is(gBrowser.multiSelectedTabsCount, numTabs, `${numTabs} multiselected tabs`);
for (let i = 0; i < numTabs; ++i) {
ok(tabs[i].multiselected, `Tab ${i} should be multiselected`);
ok(oldTabs[i].multiselected, `Old tab ${i} should be multiselected`);
}
let tabsMoved = new Promise(resolve => {
// Tab tabs in the new window will be about:blank before swapping the docshells.
// The "EndSwapDocShells" event is not dispatched for lazy tabs, so listen for
// "TabClose" instead and await a tick.
let i = 0;
window.addEventListener("TabClose", async function listener() {
let numTabsMoved = 0;
window.addEventListener("TabClose", async function listener(event) {
let tab = event.target;
let i = oldTabs.indexOf(tab);
if (i == 0) {
isnot(tab.linkedPanel, "", `Old tab ${i} should continue not being lazy`);
} else if (i > 0) {
is(tab.linkedPanel, "", `Old tab ${i} should continue being lazy`);
} else {
return;
}
await Promise.resolve();
if (++i == numTabs) {
if (++numTabsMoved == numTabs) {
window.removeEventListener("TabClose", listener);
resolve();
}
});
});
let newWindow = gBrowser.replaceTabsWithWindow(tabs[0]);
let newWindow = gBrowser.replaceTabsWithWindow(oldTabs[0]);
await tabsMoved;
tabs = newWindow.gBrowser.tabs;
let newTabs = newWindow.gBrowser.tabs;
isnot(tabs[0].linkedPanel, "", `Tab 0 should continue not being lazy`);
isnot(newTabs[0].linkedPanel, "", `New tab 0 should continue not being lazy`);
// FIXME: bug 1521923 - First inactive tab to be moved into another window loses laziness
todo_is(tabs[1].linkedPanel, "", `Tab 1 should continue being lazy`);
todo_is(newTabs[1].linkedPanel, "", `New tab 1 should continue being lazy`);
for (let i = 2; i < numTabs; ++i) {
is(tabs[i].linkedPanel, "", `Tab ${i} should continue being lazy`);
is(newTabs[i].linkedPanel, "", `New tab ${i} should continue being lazy`);
}
is(tabs[0].linkedBrowser.currentURI.spec, `http://example.com/?0`,
`Tab 0 should have the right URL`);
todo_is(SessionStore.getLazyTabValue(tabs[1], "url"), `http://example.com/?1`,
`Tab 1 should have the right lazy URL`);
is(newTabs[0].linkedBrowser.currentURI.spec, `http://example.com/?0`,
`New tab 0 should have the right URL`);
todo_is(SessionStore.getLazyTabValue(newTabs[1], "url"), `http://example.com/?1`,
`New tab 1 should have the right lazy URL`);
for (let i = 2; i < numTabs; ++i) {
is(SessionStore.getLazyTabValue(tabs[i], "url"), `http://example.com/?${i}`,
`Tab ${i} should have the right lazy URL`);
is(SessionStore.getLazyTabValue(newTabs[i], "url"), `http://example.com/?${i}`,
`New tab ${i} should have the right lazy URL`);
}
BrowserTestUtils.closeWindow(newWindow);

Просмотреть файл

@ -454,10 +454,11 @@ class TabTracker extends TabTrackerBase {
// This tab is being created to adopt a tab from a different window.
// Handle the adoption.
this.adopt(nativeTab, adoptedTab);
adoptedTab.linkedBrowser.messageManager.sendAsyncMessage("Extension:SetFrameData", {
windowId: windowTracker.getId(nativeTab.ownerGlobal),
});
if (adoptedTab.linkedPanel) {
adoptedTab.linkedBrowser.messageManager.sendAsyncMessage("Extension:SetFrameData", {
windowId: windowTracker.getId(nativeTab.ownerGlobal),
});
}
} else {
// Save the size of the current tab, since the newly-created tab will
// likely be active by the time the promise below resolves and the