browser/components/sessionstore/test/browser_merge_closed_tabs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * This test ensures that closed tabs are merged when restoring
     6  * a window state without overwriting tabs.
     7  */
     8 add_task(function () {
     9   const initialState = {
    10     windows: [{
    11       tabs: [
    12         { entries: [{ url: "about:blank" }] }
    13       ],
    14       _closedTabs: [
    15         { state: { entries: [{ ID: 1000, url: "about:blank" }]} },
    16         { state: { entries: [{ ID: 1001, url: "about:blank" }]} }
    17       ]
    18     }]
    19   }
    21   const restoreState = {
    22     windows: [{
    23       tabs: [
    24         { entries: [{ url: "about:robots" }] }
    25       ],
    26       _closedTabs: [
    27         { state: { entries: [{ ID: 1002, url: "about:robots" }]} },
    28         { state: { entries: [{ ID: 1003, url: "about:robots" }]} },
    29         { state: { entries: [{ ID: 1004, url: "about:robots" }]} }
    30       ]
    31     }]
    32   }
    34   const maxTabsUndo = 4;
    35   gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", maxTabsUndo);
    37   // Open a new window and restore it to an initial state.
    38   let win = yield promiseNewWindowLoaded({private: false});
    39   SessionStore.setWindowState(win, JSON.stringify(initialState), true);
    40   is(SessionStore.getClosedTabCount(win), 2, "2 closed tabs after restoring initial state");
    42   // Restore the new state but do not overwrite existing tabs (this should
    43   // cause the closed tabs to be merged).
    44   SessionStore.setWindowState(win, JSON.stringify(restoreState), false);
    46   // Verify the windows closed tab data is correct.
    47   let iClosed = initialState.windows[0]._closedTabs;
    48   let rClosed = restoreState.windows[0]._closedTabs;
    49   let cData = JSON.parse(SessionStore.getClosedTabData(win));
    51   is(cData.length, Math.min(iClosed.length + rClosed.length, maxTabsUndo),
    52      "Number of closed tabs is correct");
    54   // When the closed tabs are merged the restored tabs are considered to be
    55   // closed more recently.
    56   for (let i = 0; i < cData.length; i++) {
    57     if (i < rClosed.length) {
    58       is(cData[i].state.entries[0].ID, rClosed[i].state.entries[0].ID,
    59          "Closed tab entry matches");
    60     } else {
    61       is(cData[i].state.entries[0].ID, iClosed[i - rClosed.length].state.entries[0].ID,
    62          "Closed tab entry matches");
    63     }
    64   }
    66   // Clean up.
    67   gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
    68   win.close();
    69 });

mercurial