Bug 1442694 - Add tests for preopened pinned tabs r=Gijs
☠☠ backed out by 4a87b6ac14c0 ☠ ☠
authorDoug Thayer <dothayer@mozilla.com>
Mon, 25 Feb 2019 19:19:30 +0000
changeset 460958 f100f8631f78c50427ecd50f0dee4009d06ca4e1
parent 460957 7a20c79a0e1236116417ef0b317e065f4e274b9f
child 460959 959aa87abd32bbab3b094cf01939e5569ac3245c
push id35613
push usernerli@mozilla.com
push dateTue, 26 Feb 2019 03:52:35 +0000
treeherdermozilla-central@faec87a80ed1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1442694
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1442694 - Add tests for preopened pinned tabs r=Gijs Depends on D18742 Differential Revision: https://phabricator.services.mozilla.com/D19463
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_preopened_apptabs.js
browser/components/sessionstore/test/head.js
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -244,18 +244,18 @@ var SessionStore = {
   setBrowserState: function ss_setBrowserState(aState) {
     SessionStoreInternal.setBrowserState(aState);
   },
 
   getWindowState: function ss_getWindowState(aWindow) {
     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) {
     return SessionStoreInternal.getTabState(aTab);
   },
 
   setTabState: function ss_setTabState(aTab, aState) {
     SessionStoreInternal.setTabState(aTab, aState);
@@ -2495,22 +2495,25 @@ var SessionStoreInternal = {
     if (DyingWindowCache.has(aWindow)) {
       let data = DyingWindowCache.get(aWindow);
       return JSON.stringify({ windows: [data] });
     }
 
     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();
   },
 
   getTabState: function ssi_getTabState(aTab) {
     if (!aTab || !aTab.ownerGlobal) {
       throw Components.Exception("Need a valid tab", Cr.NS_ERROR_INVALID_ARG);
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -108,16 +108,17 @@ support-files = file_formdata_password.h
 skip-if = (verify && (os == 'win' || os == 'mac'))
 [browser_global_store.js]
 [browser_history_persist.js]
 [browser_label_and_icon.js]
 [browser_merge_closed_tabs.js]
 [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
 [browser_replace_load.js]
 [browser_restore_redirect.js]
 [browser_restore_cookies_noOriginAttributes.js]
 [browser_scrollPositions.js]
 [browser_scrollPositionsReaderMode.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_preopened_apptabs.js
@@ -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);
+});
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -185,18 +185,19 @@ function promiseWindowRestored(win) {
   return new Promise(resolve => win.addEventListener("SSWindowRestored", resolve, {once: true}));
 }
 
 async function setBrowserState(state, win = window) {
   ss.setBrowserState(typeof state != "string" ? JSON.stringify(state) : state);
   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);
 }
 
 /**
  * Wait for a content -> chrome message.
  */
 function promiseContentMessage(browser, name) {
   let mm = browser.messageManager;