michael@0: 'use strict'; michael@0: michael@0: const { getTabs } = require('sdk/tabs/utils'); michael@0: const { isGlobalPBSupported, isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils'); michael@0: const { browserWindows } = require('sdk/windows'); michael@0: const tabs = require('sdk/tabs'); michael@0: const { pb } = require('./private-browsing/helper'); michael@0: const { isPrivate } = require('sdk/private-browsing'); michael@0: const { openTab, closeTab, getTabContentWindow, getOwnerWindow } = require('sdk/tabs/utils'); michael@0: const { open, close } = require('sdk/window/helpers'); michael@0: const { windows } = require('sdk/window/utils'); michael@0: const { getMostRecentBrowserWindow } = require('sdk/window/utils'); michael@0: const { fromIterator } = require('sdk/util/array'); michael@0: michael@0: if (isWindowPBSupported) { michael@0: exports.testGetTabs = function(assert, done) { michael@0: let tabCount = getTabs().length; michael@0: let windowCount = browserWindows.length; michael@0: michael@0: open(null, { michael@0: features: { michael@0: private: true, michael@0: toolbar: true, michael@0: chrome: true michael@0: } michael@0: }).then(function(window) { michael@0: assert.ok(isPrivate(window), 'new tab is private'); michael@0: michael@0: assert.equal(getTabs().length, tabCount, 'there are no new tabs found'); michael@0: getTabs().forEach(function(tab) { michael@0: assert.equal(isPrivate(tab), false, 'all found tabs are not private'); michael@0: assert.equal(isPrivate(getOwnerWindow(tab)), false, 'all found tabs are not private'); michael@0: assert.equal(isPrivate(getTabContentWindow(tab)), false, 'all found tabs are not private'); michael@0: }); michael@0: michael@0: assert.equal(browserWindows.length, windowCount, 'there are no new windows found'); michael@0: fromIterator(browserWindows).forEach(function(window) { michael@0: assert.equal(isPrivate(window), false, 'all found windows are not private'); michael@0: }); michael@0: michael@0: assert.equal(windows(null, {includePrivate: true}).length, 2, 'there are really two windows'); michael@0: michael@0: close(window).then(done); michael@0: }); michael@0: }; michael@0: } michael@0: else if (isTabPBSupported) { michael@0: exports.testGetTabs = function(assert, done) { michael@0: let startTabCount = getTabs().length; michael@0: let tab = openTab(getMostRecentBrowserWindow(), 'about:blank', { michael@0: isPrivate: true michael@0: }); michael@0: michael@0: assert.ok(isPrivate(getTabContentWindow(tab)), 'new tab is private'); michael@0: let utils_tabs = getTabs(); michael@0: assert.equal(utils_tabs.length, startTabCount + 1, michael@0: 'there are two tabs found'); michael@0: assert.equal(utils_tabs[utils_tabs.length-1], tab, michael@0: 'the last tab is the opened tab'); michael@0: assert.equal(browserWindows.length, 1, 'there is only one window'); michael@0: closeTab(tab); michael@0: michael@0: done(); michael@0: }; michael@0: } michael@0: michael@0: require('test').run(exports);