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