tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_closedId.js (3111B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BACKUP_STATE = SessionStore.getBrowserState();
      7 
      8 async function add_new_tab(URL) {
      9  let tab = BrowserTestUtils.addTab(gBrowser, URL);
     10  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     11  return tab;
     12 }
     13 
     14 add_task(async function test_closedId_order() {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [
     17      ["browser.sessionstore.restore_on_demand", true],
     18      ["browser.sessionstore.restore_tabs_lazily", true],
     19    ],
     20  });
     21  // reset to 0
     22  SessionStore.resetNextClosedId();
     23  await promiseBrowserState({
     24    windows: [
     25      {
     26        selected: 1, // SessionStore uses 1-based indexing.
     27        tabs: [
     28          {
     29            entries: [],
     30          },
     31        ],
     32        _closedTabs: [
     33          {
     34            state: {
     35              entries: [
     36                {
     37                  url: "https://www.example.com/",
     38                  triggeringPrincipal_base64,
     39                },
     40              ],
     41              selected: 1,
     42            },
     43            closedId: 0,
     44            closedAt: Date.now() - 100,
     45            title: "Example",
     46          },
     47          {
     48            state: {
     49              entries: [
     50                {
     51                  url: "about:mozilla",
     52                  triggeringPrincipal_base64,
     53                },
     54              ],
     55            },
     56            closedId: 1,
     57            closedAt: Date.now() - 50,
     58            title: "about:mozilla",
     59          },
     60          {
     61            state: {
     62              entries: [
     63                {
     64                  url: "https://www.example.net/",
     65                  triggeringPrincipal_base64,
     66                },
     67              ],
     68            },
     69            closedId: 2,
     70            closedAt: Date.now(),
     71            title: "Example",
     72          },
     73        ],
     74      },
     75    ],
     76  });
     77 
     78  let tab = await add_new_tab("about:firefoxview");
     79 
     80  is(
     81    SessionStore.getClosedTabCountForWindow(window),
     82    3,
     83    "Closed tab count after restored session is 3"
     84  );
     85 
     86  let initialClosedId =
     87    SessionStore.getClosedTabDataForWindow(window)[0].closedId;
     88 
     89  // If this fails, that means one of the closedId's in the stubbed data in this test needs to be updated
     90  // to reflect what the initial closedId is when a new tab is open and closed (which may change as more tests
     91  // for session store are added here). You can manually verify a change to stubbed data by commenting out
     92  // this._resetClosedTabsIds in SessionStore.sys.mjs temporarily and then the "Each tab has a unique closedId" case should fail.
     93  is(initialClosedId, 0, "Initial closedId is 0");
     94 
     95  await openAndCloseTab(window, "about:robots"); // closedId should be higher than the ones we just restored.
     96 
     97  let closedData = SessionStore.getClosedTabDataForWindow(window);
     98  is(closedData.length, 4, "Should have data for 4 closed tabs.");
     99  is(
    100    new Set(closedData.map(t => t.closedId)).size,
    101    4,
    102    "Each tab has a unique closedId"
    103  );
    104 
    105  BrowserTestUtils.removeTab(tab);
    106 
    107  // Clean up for the next task.
    108  await promiseBrowserState(BACKUP_STATE);
    109 });