tor-browser

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

browser_tab_groups_state.js (2966B)


      1 "use strict";
      2 
      3 const ORIG_STATE = SessionStore.getBrowserState();
      4 
      5 registerCleanupFunction(async () => {
      6  await SessionStoreTestUtils.promiseBrowserState(ORIG_STATE);
      7 });
      8 
      9 /**
     10 * @param {WindowStateData} windowState
     11 * @returns {TabStateData|undefined}
     12 */
     13 function findTabStateByUrl(windowState, url) {
     14  return windowState.tabs.find(tabState => tabState.userTypedValue == url);
     15 }
     16 
     17 add_task(async function test_TabGroupsInState() {
     18  let win = await promiseNewWindowLoaded();
     19  let aboutRobotsTab = BrowserTestUtils.addTab(win.gBrowser, "about:robots");
     20  let aboutMozillaTab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla");
     21  BrowserTestUtils.addTab(win.gBrowser, "about:about");
     22 
     23  let group = win.gBrowser.addTabGroup([aboutRobotsTab, aboutMozillaTab], {
     24    label: "non-meta about pages",
     25  });
     26 
     27  let state = ss.getWindowState(win);
     28 
     29  Assert.equal(state.windows.length, 1, "should have state from 1 window");
     30  let windowState = state.windows[0];
     31 
     32  Assert.ok(windowState.groups, "window state should have a `groups` property");
     33  Assert.equal(windowState.groups.length, 1, "there should be one tab group");
     34  let groupState = windowState.groups[0];
     35 
     36  Assert.equal(
     37    groupState.id,
     38    group.id,
     39    "tab group ID should be recorded in state"
     40  );
     41  Assert.equal(
     42    groupState.name,
     43    group.label,
     44    "tab group name should be recorded in state"
     45  );
     46  Assert.equal(
     47    groupState.color,
     48    group.color,
     49    "tab group color should be recorded in state"
     50  );
     51  Assert.equal(
     52    groupState.collapsed,
     53    group.collapsed,
     54    "tab group collapsed state should be recorded in state"
     55  );
     56 
     57  Assert.equal(
     58    windowState.tabs.length,
     59    4,
     60    "there should be 3 tabs in session state + 1 initial tab"
     61  );
     62 
     63  const aboutRobotsTabState = findTabStateByUrl(windowState, "about:robots");
     64  Assert.ok(aboutRobotsTabState, "about:robots tab should be in session state");
     65  Assert.equal(
     66    aboutRobotsTabState.groupId,
     67    group.id,
     68    "about:robots tab should be part of the tab group"
     69  );
     70 
     71  const aboutMozillaTabState = findTabStateByUrl(windowState, "about:mozilla");
     72  Assert.ok(
     73    aboutMozillaTabState,
     74    "about:mozilla tab should be in session state"
     75  );
     76  Assert.equal(
     77    aboutMozillaTabState.groupId,
     78    group.id,
     79    "about:mozilla tab should be part of the tab group"
     80  );
     81 
     82  const aboutAboutTabState = findTabStateByUrl(windowState, "about:about");
     83  Assert.ok(aboutAboutTabState, "about:about tab should be in session state");
     84  Assert.ok(
     85    !aboutAboutTabState.groupId,
     86    "about:about tab should NOT be part of the tab group"
     87  );
     88 
     89  // collapse the tab group and make sure the tab group data updates
     90  group.collapsed = true;
     91 
     92  state = ss.getWindowState(win);
     93  groupState = state.windows[0].groups[0];
     94  Assert.equal(
     95    groupState.collapsed,
     96    group.collapsed,
     97    "updated tab group collapsed state should be recorded in state"
     98  );
     99  await BrowserTestUtils.closeWindow(win);
    100  forgetClosedWindows();
    101 });