addon-sdk/source/test/addons/private-browsing-supported/test-window-tabs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/addons/private-browsing-supported/test-window-tabs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +'use strict';
     1.5 +
     1.6 +const tabs = require('sdk/tabs');
     1.7 +const { isPrivate } = require('sdk/private-browsing');
     1.8 +const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
     1.9 +const { promise: windowPromise, close, focus } = require('sdk/window/helpers');
    1.10 +const { getMostRecentBrowserWindow } = require('sdk/window/utils');
    1.11 +
    1.12 +exports.testOpenTabWithPrivateActiveWindowNoIsPrivateOption = function(assert, done) {
    1.13 +  let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true });
    1.14 +
    1.15 +  windowPromise(window, 'load').then(focus).then(function (window) {
    1.16 +    assert.ok(isPrivate(window), 'new window is private');
    1.17 +
    1.18 +    tabs.open({
    1.19 +      url: 'about:blank',
    1.20 +      onOpen: function(tab) {
    1.21 +        assert.ok(isPrivate(tab), 'new tab is private');
    1.22 +        assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private');
    1.23 +        assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same');
    1.24 +
    1.25 +        close(window).then(done).then(null, assert.fail);
    1.26 +      }
    1.27 +    })
    1.28 +  }).then(null, assert.fail);
    1.29 +}
    1.30 +
    1.31 +exports.testOpenTabWithNonPrivateActiveWindowNoIsPrivateOption = function(assert, done) {
    1.32 +  let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false });
    1.33 +
    1.34 +  windowPromise(window, 'load').then(focus).then(function (window) {
    1.35 +    assert.equal(isPrivate(window), false, 'new window is not private');
    1.36 +
    1.37 +    tabs.open({
    1.38 +      url: 'about:blank',
    1.39 +      onOpen: function(tab) {
    1.40 +        assert.equal(isPrivate(tab), false, 'new tab is not private');
    1.41 +        assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private');
    1.42 +        assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same');
    1.43 +
    1.44 +        close(window).then(done).then(null, assert.fail);
    1.45 +      }
    1.46 +    })
    1.47 +  }).then(null, assert.fail);
    1.48 +}
    1.49 +
    1.50 +exports.testOpenTabWithPrivateActiveWindowWithIsPrivateOptionTrue = function(assert, done) {
    1.51 +  let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true });
    1.52 +
    1.53 +  windowPromise(window, 'load').then(focus).then(function (window) {
    1.54 +    assert.ok(isPrivate(window), 'new window is private');
    1.55 +
    1.56 +    tabs.open({
    1.57 +      url: 'about:blank',
    1.58 +      isPrivate: true,
    1.59 +      onOpen: function(tab) {
    1.60 +        assert.ok(isPrivate(tab), 'new tab is private');
    1.61 +        assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private');
    1.62 +        assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same');
    1.63 +
    1.64 +        close(window).then(done).then(null, assert.fail);
    1.65 +      }
    1.66 +    })
    1.67 +  }).then(null, assert.fail);
    1.68 +}
    1.69 +
    1.70 +exports.testOpenTabWithNonPrivateActiveWindowWithIsPrivateOptionFalse = function(assert, done) {
    1.71 +  let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false });
    1.72 +
    1.73 +  windowPromise(window, 'load').then(focus).then(function (window) {
    1.74 +    assert.equal(isPrivate(window), false, 'new window is not private');
    1.75 +
    1.76 +    tabs.open({
    1.77 +      url: 'about:blank',
    1.78 +      isPrivate: false,
    1.79 +      onOpen: function(tab) {
    1.80 +        assert.equal(isPrivate(tab), false, 'new tab is not private');
    1.81 +        assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private');
    1.82 +        assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same');
    1.83 +
    1.84 +        close(window).then(done).then(null, assert.fail);
    1.85 +      }
    1.86 +    })
    1.87 +  }).then(null, assert.fail);
    1.88 +}

mercurial