michael@0: 'use strict'; michael@0: michael@0: const tabs = require('sdk/tabs'); michael@0: const { isPrivate } = require('sdk/private-browsing'); michael@0: const { getOwnerWindow } = require('sdk/private-browsing/window/utils'); michael@0: const { promise: windowPromise, close, focus } = require('sdk/window/helpers'); michael@0: const { getMostRecentBrowserWindow } = require('sdk/window/utils'); michael@0: michael@0: exports.testOpenTabWithPrivateActiveWindowNoIsPrivateOption = function(assert, done) { michael@0: let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true }); michael@0: michael@0: windowPromise(window, 'load').then(focus).then(function (window) { michael@0: assert.ok(isPrivate(window), 'new window is private'); michael@0: michael@0: tabs.open({ michael@0: url: 'about:blank', michael@0: onOpen: function(tab) { michael@0: assert.ok(isPrivate(tab), 'new tab is private'); michael@0: assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private'); michael@0: assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same'); michael@0: michael@0: close(window).then(done).then(null, assert.fail); michael@0: } michael@0: }) michael@0: }).then(null, assert.fail); michael@0: } michael@0: michael@0: exports.testOpenTabWithNonPrivateActiveWindowNoIsPrivateOption = function(assert, done) { michael@0: let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false }); michael@0: michael@0: windowPromise(window, 'load').then(focus).then(function (window) { michael@0: assert.equal(isPrivate(window), false, 'new window is not private'); michael@0: michael@0: tabs.open({ michael@0: url: 'about:blank', michael@0: onOpen: function(tab) { michael@0: assert.equal(isPrivate(tab), false, 'new tab is not private'); michael@0: assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private'); michael@0: assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same'); michael@0: michael@0: close(window).then(done).then(null, assert.fail); michael@0: } michael@0: }) michael@0: }).then(null, assert.fail); michael@0: } michael@0: michael@0: exports.testOpenTabWithPrivateActiveWindowWithIsPrivateOptionTrue = function(assert, done) { michael@0: let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true }); michael@0: michael@0: windowPromise(window, 'load').then(focus).then(function (window) { michael@0: assert.ok(isPrivate(window), 'new window is private'); michael@0: michael@0: tabs.open({ michael@0: url: 'about:blank', michael@0: isPrivate: true, michael@0: onOpen: function(tab) { michael@0: assert.ok(isPrivate(tab), 'new tab is private'); michael@0: assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private'); michael@0: assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same'); michael@0: michael@0: close(window).then(done).then(null, assert.fail); michael@0: } michael@0: }) michael@0: }).then(null, assert.fail); michael@0: } michael@0: michael@0: exports.testOpenTabWithNonPrivateActiveWindowWithIsPrivateOptionFalse = function(assert, done) { michael@0: let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false }); michael@0: michael@0: windowPromise(window, 'load').then(focus).then(function (window) { michael@0: assert.equal(isPrivate(window), false, 'new window is not private'); michael@0: michael@0: tabs.open({ michael@0: url: 'about:blank', michael@0: isPrivate: false, michael@0: onOpen: function(tab) { michael@0: assert.equal(isPrivate(tab), false, 'new tab is not private'); michael@0: assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private'); michael@0: assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same'); michael@0: michael@0: close(window).then(done).then(null, assert.fail); michael@0: } michael@0: }) michael@0: }).then(null, assert.fail); michael@0: }