Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | 'use strict'; |
michael@0 | 2 | |
michael@0 | 3 | const { getTabs } = require('sdk/tabs/utils'); |
michael@0 | 4 | const { isGlobalPBSupported, isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils'); |
michael@0 | 5 | const { browserWindows } = require('sdk/windows'); |
michael@0 | 6 | const tabs = require('sdk/tabs'); |
michael@0 | 7 | const { pb } = require('./private-browsing/helper'); |
michael@0 | 8 | const { isPrivate } = require('sdk/private-browsing'); |
michael@0 | 9 | const { openTab, closeTab, getTabContentWindow, getOwnerWindow } = require('sdk/tabs/utils'); |
michael@0 | 10 | const { open, close } = require('sdk/window/helpers'); |
michael@0 | 11 | const { windows } = require('sdk/window/utils'); |
michael@0 | 12 | const { getMostRecentBrowserWindow } = require('sdk/window/utils'); |
michael@0 | 13 | const { fromIterator } = require('sdk/util/array'); |
michael@0 | 14 | |
michael@0 | 15 | if (isWindowPBSupported) { |
michael@0 | 16 | exports.testGetTabs = function(assert, done) { |
michael@0 | 17 | let tabCount = getTabs().length; |
michael@0 | 18 | let windowCount = browserWindows.length; |
michael@0 | 19 | |
michael@0 | 20 | open(null, { |
michael@0 | 21 | features: { |
michael@0 | 22 | private: true, |
michael@0 | 23 | toolbar: true, |
michael@0 | 24 | chrome: true |
michael@0 | 25 | } |
michael@0 | 26 | }).then(function(window) { |
michael@0 | 27 | assert.ok(isPrivate(window), 'new tab is private'); |
michael@0 | 28 | |
michael@0 | 29 | assert.equal(getTabs().length, tabCount, 'there are no new tabs found'); |
michael@0 | 30 | getTabs().forEach(function(tab) { |
michael@0 | 31 | assert.equal(isPrivate(tab), false, 'all found tabs are not private'); |
michael@0 | 32 | assert.equal(isPrivate(getOwnerWindow(tab)), false, 'all found tabs are not private'); |
michael@0 | 33 | assert.equal(isPrivate(getTabContentWindow(tab)), false, 'all found tabs are not private'); |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | assert.equal(browserWindows.length, windowCount, 'there are no new windows found'); |
michael@0 | 37 | fromIterator(browserWindows).forEach(function(window) { |
michael@0 | 38 | assert.equal(isPrivate(window), false, 'all found windows are not private'); |
michael@0 | 39 | }); |
michael@0 | 40 | |
michael@0 | 41 | assert.equal(windows(null, {includePrivate: true}).length, 2, 'there are really two windows'); |
michael@0 | 42 | |
michael@0 | 43 | close(window).then(done); |
michael@0 | 44 | }); |
michael@0 | 45 | }; |
michael@0 | 46 | } |
michael@0 | 47 | else if (isTabPBSupported) { |
michael@0 | 48 | exports.testGetTabs = function(assert, done) { |
michael@0 | 49 | let startTabCount = getTabs().length; |
michael@0 | 50 | let tab = openTab(getMostRecentBrowserWindow(), 'about:blank', { |
michael@0 | 51 | isPrivate: true |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | assert.ok(isPrivate(getTabContentWindow(tab)), 'new tab is private'); |
michael@0 | 55 | let utils_tabs = getTabs(); |
michael@0 | 56 | assert.equal(utils_tabs.length, startTabCount + 1, |
michael@0 | 57 | 'there are two tabs found'); |
michael@0 | 58 | assert.equal(utils_tabs[utils_tabs.length-1], tab, |
michael@0 | 59 | 'the last tab is the opened tab'); |
michael@0 | 60 | assert.equal(browserWindows.length, 1, 'there is only one window'); |
michael@0 | 61 | closeTab(tab); |
michael@0 | 62 | |
michael@0 | 63 | done(); |
michael@0 | 64 | }; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | require('test').run(exports); |