1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/test/test-tab-utils.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +'use strict'; 1.5 + 1.6 +const { getTabs } = require('sdk/tabs/utils'); 1.7 +const { isGlobalPBSupported, isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils'); 1.8 +const { browserWindows } = require('sdk/windows'); 1.9 +const tabs = require('sdk/tabs'); 1.10 +const { pb } = require('./private-browsing/helper'); 1.11 +const { isPrivate } = require('sdk/private-browsing'); 1.12 +const { openTab, closeTab, getTabContentWindow, getOwnerWindow } = require('sdk/tabs/utils'); 1.13 +const { open, close } = require('sdk/window/helpers'); 1.14 +const { windows } = require('sdk/window/utils'); 1.15 +const { getMostRecentBrowserWindow } = require('sdk/window/utils'); 1.16 +const { fromIterator } = require('sdk/util/array'); 1.17 + 1.18 +if (isWindowPBSupported) { 1.19 + exports.testGetTabs = function(assert, done) { 1.20 + let tabCount = getTabs().length; 1.21 + let windowCount = browserWindows.length; 1.22 + 1.23 + open(null, { 1.24 + features: { 1.25 + private: true, 1.26 + toolbar: true, 1.27 + chrome: true 1.28 + } 1.29 + }).then(function(window) { 1.30 + assert.ok(isPrivate(window), 'new tab is private'); 1.31 + 1.32 + assert.equal(getTabs().length, tabCount, 'there are no new tabs found'); 1.33 + getTabs().forEach(function(tab) { 1.34 + assert.equal(isPrivate(tab), false, 'all found tabs are not private'); 1.35 + assert.equal(isPrivate(getOwnerWindow(tab)), false, 'all found tabs are not private'); 1.36 + assert.equal(isPrivate(getTabContentWindow(tab)), false, 'all found tabs are not private'); 1.37 + }); 1.38 + 1.39 + assert.equal(browserWindows.length, windowCount, 'there are no new windows found'); 1.40 + fromIterator(browserWindows).forEach(function(window) { 1.41 + assert.equal(isPrivate(window), false, 'all found windows are not private'); 1.42 + }); 1.43 + 1.44 + assert.equal(windows(null, {includePrivate: true}).length, 2, 'there are really two windows'); 1.45 + 1.46 + close(window).then(done); 1.47 + }); 1.48 + }; 1.49 +} 1.50 +else if (isTabPBSupported) { 1.51 + exports.testGetTabs = function(assert, done) { 1.52 + let startTabCount = getTabs().length; 1.53 + let tab = openTab(getMostRecentBrowserWindow(), 'about:blank', { 1.54 + isPrivate: true 1.55 + }); 1.56 + 1.57 + assert.ok(isPrivate(getTabContentWindow(tab)), 'new tab is private'); 1.58 + let utils_tabs = getTabs(); 1.59 + assert.equal(utils_tabs.length, startTabCount + 1, 1.60 + 'there are two tabs found'); 1.61 + assert.equal(utils_tabs[utils_tabs.length-1], tab, 1.62 + 'the last tab is the opened tab'); 1.63 + assert.equal(browserWindows.length, 1, 'there is only one window'); 1.64 + closeTab(tab); 1.65 + 1.66 + done(); 1.67 + }; 1.68 +} 1.69 + 1.70 +require('test').run(exports);