Bug 1521346 - Preserve lazyness when moving tabs into a new window. r=jaws

TODO: the first lazy tab is not moved using gBrowser.adoptTab, so it's still unlazified.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Oriol Brufau 2019-01-31 00:33:39 +00:00
Родитель 97310d7a60
Коммит 8f1a936f96
4 изменённых файлов: 67 добавлений и 16 удалений

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

@ -2306,6 +2306,7 @@ window._gBrowser = {
sameProcessAsFrameLoader, sameProcessAsFrameLoader,
skipAnimation, skipAnimation,
skipBackgroundNotify, skipBackgroundNotify,
title,
triggeringPrincipal, triggeringPrincipal,
userContextId, userContextId,
recordExecution, recordExecution,
@ -2549,6 +2550,13 @@ window._gBrowser = {
userContextId); userContextId);
b.registeredOpenURI = lazyBrowserURI; b.registeredOpenURI = lazyBrowserURI;
} }
SessionStore.setTabState(t, {
entries: [{
url: lazyBrowserURI ? lazyBrowserURI.spec : "about:blank",
title,
triggeringPrincipal_base64: Utils.serializePrincipal(triggeringPrincipal),
}],
});
} else { } else {
this._insertBrowser(t, true); this._insertBrowser(t, true);
} }
@ -3809,12 +3817,15 @@ window._gBrowser = {
// the same remote type and process as the one we're swapping in. // the same remote type and process as the one we're swapping in.
// This makes sure we don't get a short-lived process for the new tab. // This makes sure we don't get a short-lived process for the new tab.
let linkedBrowser = aTab.linkedBrowser; let linkedBrowser = aTab.linkedBrowser;
let createLazyBrowser = !aTab.linkedPanel;
let params = { let params = {
eventDetail: { adoptedTab: aTab }, eventDetail: { adoptedTab: aTab },
preferredRemoteType: linkedBrowser.remoteType, preferredRemoteType: linkedBrowser.remoteType,
sameProcessAsFrameLoader: linkedBrowser.frameLoader, sameProcessAsFrameLoader: linkedBrowser.frameLoader,
skipAnimation: true, skipAnimation: true,
index: aIndex, index: aIndex,
createLazyBrowser,
allowInheritPrincipal: createLazyBrowser,
}; };
let numPinned = this._numPinnedTabs; let numPinned = this._numPinnedTabs;
@ -3831,10 +3842,12 @@ window._gBrowser = {
aTab.parentNode._finishAnimateTabMove(); aTab.parentNode._finishAnimateTabMove();
// Stop the about:blank load. if (!createLazyBrowser) {
newBrowser.stop(); // Stop the about:blank load.
// Make sure it has a docshell. newBrowser.stop();
newBrowser.docShell; // Make sure it has a docshell.
newBrowser.docShell;
}
if (!this.swapBrowsersAndCloseOther(newTab, aTab)) { if (!this.swapBrowsersAndCloseOther(newTab, aTab)) {
// Swapping wasn't permitted. Bail out. // Swapping wasn't permitted. Bail out.

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

@ -44,3 +44,52 @@ add_task(async function test() {
BrowserTestUtils.closeWindow(newWindow); BrowserTestUtils.closeWindow(newWindow);
BrowserTestUtils.removeTab(tab4); BrowserTestUtils.removeTab(tab4);
}); });
add_task(async function testLazyTabs() {
let params = {createLazyBrowser: true};
let tabs = [];
let numTabs = 4;
for (let i = 0; i < numTabs; ++i) {
tabs.push(BrowserTestUtils.addTab(gBrowser, `http://example.com/?${i}`, params));
}
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
for (let i = 1; i < numTabs; ++i) {
await triggerClickOn(tabs[i], { ctrlKey: true });
}
isnot(tabs[0].linkedPanel, "", `Tab 0 shouldn't be lazy`);
for (let i = 1; i < numTabs; ++i) {
is(tabs[i].linkedPanel, "", `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`);
}
let newWindow = gBrowser.replaceTabsWithWindow(tabs[0]);
await TestUtils.waitForCondition(() => newWindow.gBrowser, `Wait for gBrowser`);
await TestUtils.waitForCondition(() => newWindow.gBrowser.visibleTabs.length == numTabs,
`Wait for all ${numTabs} tabs to get moved to the new window`);
tabs = newWindow.gBrowser.tabs;
isnot(tabs[0].linkedPanel, "", `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`);
for (let i = 2; i < numTabs; ++i) {
is(tabs[i].linkedPanel, "", `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`);
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`);
}
BrowserTestUtils.closeWindow(newWindow);
});

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

@ -56,7 +56,7 @@ add_task(async function testReopen() {
let tab1 = await addTab("http://mochi.test:8888/1"); let tab1 = await addTab("http://mochi.test:8888/1");
let tab2 = await addTab("http://mochi.test:8888/2"); let tab2 = await addTab("http://mochi.test:8888/2");
let tab3 = await addTab("http://mochi.test:8888/3"); let tab3 = await addTab("http://mochi.test:8888/3");
let tab4 = await addTab("http://mochi.test:8888/3", {createLazyBrowser: true}); let tab4 = BrowserTestUtils.addTab(gBrowser, "http://mochi.test:8888/3", {createLazyBrowser: true});
await BrowserTestUtils.switchTab(gBrowser, tab1); await BrowserTestUtils.switchTab(gBrowser, tab1);

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

@ -14,8 +14,6 @@ ChromeUtils.defineModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm"); "resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "SessionStore", ChromeUtils.defineModuleGetter(this, "SessionStore",
"resource:///modules/sessionstore/SessionStore.jsm"); "resource:///modules/sessionstore/SessionStore.jsm");
ChromeUtils.defineModuleGetter(this, "Utils",
"resource://gre/modules/sessionstore/Utils.jsm");
XPCOMUtils.defineLazyGetter(this, "strBundle", function() { XPCOMUtils.defineLazyGetter(this, "strBundle", function() {
return Services.strings.createBundle("chrome://global/locale/extensions.properties"); return Services.strings.createBundle("chrome://global/locale/extensions.properties");
@ -634,15 +632,6 @@ this.tabs = class extends ExtensionAPI {
options.triggeringPrincipal = principal; options.triggeringPrincipal = principal;
let nativeTab = window.gBrowser.addTab(url, options); let nativeTab = window.gBrowser.addTab(url, options);
if (createProperties.discarded) {
SessionStore.setTabState(nativeTab, {
entries: [{
url: url,
title: options.title,
triggeringPrincipal_base64: Utils.serializePrincipal(principal),
}],
});
}
if (active) { if (active) {
window.gBrowser.selectedTab = nativeTab; window.gBrowser.selectedTab = nativeTab;