summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/head_sessions.js
blob: db58c128c64f0afb64a8b100469457f77d9b5932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

/* exported recordInitialTimestamps onlyNewItemsFilter checkRecentlyClosed */

let initialTimestamps = [];

function recordInitialTimestamps(timestamps) {
  initialTimestamps = timestamps;
}

function onlyNewItemsFilter(item) {
  return !initialTimestamps.includes(item.lastModified);
}

function checkWindow(window) {
  for (let prop of ["focused", "incognito", "alwaysOnTop"]) {
    is(window[prop], false, `closed window has the expected value for ${prop}`);
  }
  for (let prop of ["state", "type"]) {
    is(
      window[prop],
      "normal",
      `closed window has the expected value for ${prop}`
    );
  }
}

function checkTab(tab, windowId, incognito) {
  for (let prop of ["highlighted", "active", "pinned"]) {
    is(tab[prop], false, `closed tab has the expected value for ${prop}`);
  }
  is(tab.windowId, windowId, "closed tab has the expected value for windowId");
  is(
    tab.incognito,
    incognito,
    "closed tab has the expected value for incognito"
  );
}

function checkRecentlyClosed(
  recentlyClosed,
  expectedCount,
  windowId,
  incognito = false
) {
  let sessionIds = new Set();
  is(
    recentlyClosed.length,
    expectedCount,
    "the expected number of closed tabs/windows was found"
  );
  for (let item of recentlyClosed) {
    if (item.window) {
      sessionIds.add(item.window.sessionId);
      checkWindow(item.window);
    } else if (item.tab) {
      sessionIds.add(item.tab.sessionId);
      checkTab(item.tab, windowId, incognito);
    }
  }
  is(sessionIds.size, expectedCount, "each item has a unique sessionId");
}