Bug 1442694 - Add tests for preopened pinned tabs r=Gijs

Depends on D18742

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Doug Thayer 2019-02-25 19:19:30 +00:00
Родитель 978e0344ff
Коммит d2b8144761
4 изменённых файлов: 149 добавлений и 6 удалений

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

@ -249,8 +249,8 @@ var SessionStore = {
return SessionStoreInternal.getWindowState(aWindow);
},
setWindowState: function ss_setWindowState(aWindow, aState, aOverwrite) {
SessionStoreInternal.setWindowState(aWindow, aState, aOverwrite);
setWindowState: function ss_setWindowState(aWindow, aState, aOverwrite, aFirstWindow) {
SessionStoreInternal.setWindowState(aWindow, aState, aOverwrite, aFirstWindow);
},
getTabState: function ss_getTabState(aTab) {
@ -2500,12 +2500,15 @@ var SessionStoreInternal = {
throw Components.Exception("Window is not tracked", Cr.NS_ERROR_INVALID_ARG);
},
setWindowState: function ssi_setWindowState(aWindow, aState, aOverwrite) {
setWindowState: function ssi_setWindowState(aWindow, aState, aOverwrite, aFirstWindow) {
if (!aWindow.__SSi) {
throw Components.Exception("Window is not tracked", Cr.NS_ERROR_INVALID_ARG);
}
this.restoreWindows(aWindow, aState, {overwriteTabs: aOverwrite});
this.restoreWindows(aWindow, aState, {
overwriteTabs: aOverwrite,
firstWindow: aFirstWindow,
});
// Notify of changes to closed objects.
this._notifyOfClosedObjectsChange();

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

@ -113,6 +113,7 @@ skip-if = (verify && (os == 'win' || os == 'mac'))
[browser_old_favicon.js]
[browser_page_title.js]
[browser_pending_tabs.js]
[browser_preopened_apptabs.js]
[browser_privatetabs.js]
[browser_purge_shistory.js]
skip-if = e10s # Bug 1271024

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

@ -0,0 +1,138 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
const PREF_NUM_PINNED_TABS = "browser.tabs.firstWindowRestore.numPinnedTabs";
function muffleMainWindowType() {
let oldWinType = document.documentElement.getAttribute("windowtype");
// Check if we've already done this to allow calling multiple times:
if (oldWinType != "navigator:testrunner") {
// Make the main test window not count as a browser window any longer
document.documentElement.setAttribute("windowtype", "navigator:testrunner");
registerCleanupFunction(() => {
document.documentElement.setAttribute("windowtype", oldWinType);
});
}
}
registerCleanupFunction(function() {
Services.prefs.clearUserPref(PREF_NUM_PINNED_TABS);
});
add_task(async function testPrefSynced() {
Services.prefs.setIntPref(PREF_NUM_PINNED_TABS, 3);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }], pinned: true },
], selected: 3 }] };
muffleMainWindowType();
let win = await BrowserTestUtils.openNewBrowserWindow();
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 1);
await setWindowState(win, state, false, true);
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 4);
await BrowserTestUtils.closeWindow(win);
});
add_task(async function testPrefSyncedSelected() {
Services.prefs.setIntPref(PREF_NUM_PINNED_TABS, 3);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }], pinned: true },
], selected: 1 }] };
muffleMainWindowType();
let win = await BrowserTestUtils.openNewBrowserWindow();
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 1);
await setWindowState(win, state, false, true);
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 4);
await BrowserTestUtils.closeWindow(win);
});
add_task(async function testPrefTooHigh() {
Services.prefs.setIntPref(PREF_NUM_PINNED_TABS, 5);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }], pinned: true },
], selected: 3 }] };
muffleMainWindowType();
let win = await BrowserTestUtils.openNewBrowserWindow();
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 5);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 1);
await setWindowState(win, state, false, true);
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 4);
await BrowserTestUtils.closeWindow(win);
});
add_task(async function testPrefTooLow() {
Services.prefs.setIntPref(PREF_NUM_PINNED_TABS, 1);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }], pinned: true },
], selected: 3 }] };
muffleMainWindowType();
let win = await BrowserTestUtils.openNewBrowserWindow();
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 1);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 1);
await setWindowState(win, state, false, true);
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 4);
await BrowserTestUtils.closeWindow(win);
});
add_task(async function testPrefTooHighSelected() {
Services.prefs.setIntPref(PREF_NUM_PINNED_TABS, 5);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }], pinned: true },
], selected: 1 }] };
muffleMainWindowType();
let win = await BrowserTestUtils.openNewBrowserWindow();
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 5);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 1);
await setWindowState(win, state, false, true);
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 4);
await BrowserTestUtils.closeWindow(win);
});
add_task(async function testPrefTooLowSelected() {
Services.prefs.setIntPref(PREF_NUM_PINNED_TABS, 1);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }], pinned: true },
{ entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }], pinned: true },
], selected: 1 }] };
muffleMainWindowType();
let win = await BrowserTestUtils.openNewBrowserWindow();
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 1);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 1);
await setWindowState(win, state, false, true);
Assert.equal([...win.gBrowser.tabs].filter(t => t.pinned).length, 3);
Assert.equal([...win.gBrowser.tabs].filter(t => !!t.linkedPanel).length, 4);
await BrowserTestUtils.closeWindow(win);
});

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

@ -190,8 +190,9 @@ async function setBrowserState(state, win = window) {
await promiseWindowRestored(win);
}
async function setWindowState(win, state, overwrite = false) {
ss.setWindowState(win, typeof state != "string" ? JSON.stringify(state) : state, overwrite);
async function setWindowState(win, state, overwrite = false, firstWindow = false) {
ss.setWindowState(win, typeof state != "string" ? JSON.stringify(state) : state,
overwrite, firstWindow);
await promiseWindowRestored(win);
}