gecko-dev/browser/components/extensions/test/browser/head_sessions.js
Tushar Saini (:shatur) 163e27b705 Bug 1337509 - Do not create tab objects with an unsupported 'selected' property. r=bsilverberg,mixedpuppy
MozReview-Commit-ID: 4Bi6LdNUxMo

--HG--
extra : rebase_source : 52baba39e08bc9d250ace3f4b46a591d7f641d47
2017-04-18 22:07:38 +05:30

47 lines
1.6 KiB
JavaScript

/* -*- 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");
}