summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/test-tab-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'addon-sdk/source/test/test-tab-utils.js')
-rw-r--r--addon-sdk/source/test/test-tab-utils.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/addon-sdk/source/test/test-tab-utils.js b/addon-sdk/source/test/test-tab-utils.js
new file mode 100644
index 000000000..1b631a105
--- /dev/null
+++ b/addon-sdk/source/test/test-tab-utils.js
@@ -0,0 +1,69 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { getTabs } = require('sdk/tabs/utils');
+const { isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
+const { browserWindows } = require('sdk/windows');
+const tabs = require('sdk/tabs');
+const { isPrivate } = require('sdk/private-browsing');
+const { openTab, closeTab, getTabContentWindow, getOwnerWindow } = require('sdk/tabs/utils');
+const { open, close } = require('sdk/window/helpers');
+const { windows } = require('sdk/window/utils');
+const { getMostRecentBrowserWindow } = require('sdk/window/utils');
+const { fromIterator } = require('sdk/util/array');
+
+if (isWindowPBSupported) {
+ exports.testGetTabs = function(assert, done) {
+ let tabCount = getTabs().length;
+ let windowCount = browserWindows.length;
+
+ open(null, {
+ features: {
+ private: true,
+ toolbar: true,
+ chrome: true
+ }
+ }).then(function(window) {
+ assert.ok(isPrivate(window), 'new tab is private');
+
+ assert.equal(getTabs().length, tabCount, 'there are no new tabs found');
+ getTabs().forEach(function(tab) {
+ assert.equal(isPrivate(tab), false, 'all found tabs are not private');
+ assert.equal(isPrivate(getOwnerWindow(tab)), false, 'all found tabs are not private');
+ assert.equal(isPrivate(getTabContentWindow(tab)), false, 'all found tabs are not private');
+ });
+
+ assert.equal(browserWindows.length, windowCount, 'there are no new windows found');
+ fromIterator(browserWindows).forEach(function(window) {
+ assert.equal(isPrivate(window), false, 'all found windows are not private');
+ });
+
+ assert.equal(windows(null, {includePrivate: true}).length, 2, 'there are really two windows');
+
+ close(window).then(done);
+ });
+ };
+}
+else if (isTabPBSupported) {
+ exports.testGetTabs = function(assert, done) {
+ let startTabCount = getTabs().length;
+ let tab = openTab(getMostRecentBrowserWindow(), 'about:blank', {
+ isPrivate: true
+ });
+
+ assert.ok(isPrivate(getTabContentWindow(tab)), 'new tab is private');
+ let utils_tabs = getTabs();
+ assert.equal(utils_tabs.length, startTabCount + 1,
+ 'there are two tabs found');
+ assert.equal(utils_tabs[utils_tabs.length-1], tab,
+ 'the last tab is the opened tab');
+ assert.equal(browserWindows.length, 1, 'there is only one window');
+ closeTab(tab);
+
+ done();
+ };
+}
+
+require('sdk/test').run(exports);