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

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 'use strict';
michael@0 5
michael@0 6 const { Ci } = require('chrome');
michael@0 7 const { isPrivateBrowsingSupported } = require('sdk/self');
michael@0 8 const tabs = require('sdk/tabs');
michael@0 9 const { browserWindows: windows } = require('sdk/windows');
michael@0 10 const { isPrivate } = require('sdk/private-browsing');
michael@0 11 const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
michael@0 12 const { is } = require('sdk/system/xul-app');
michael@0 13 const { isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
michael@0 14
michael@0 15 const TAB_URL = 'data:text/html;charset=utf-8,TEST-TAB';
michael@0 16
michael@0 17 exports.testIsPrivateBrowsingTrue = function(assert) {
michael@0 18 assert.ok(isPrivateBrowsingSupported,
michael@0 19 'isPrivateBrowsingSupported property is true');
michael@0 20 };
michael@0 21
michael@0 22 // test tab.open with isPrivate: true
michael@0 23 // test isPrivate on a tab
michael@0 24 // test getOwnerWindow on windows and tabs
michael@0 25 exports.testGetOwnerWindow = function(assert, done) {
michael@0 26 let window = windows.activeWindow;
michael@0 27 let chromeWindow = getOwnerWindow(window);
michael@0 28 assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found');
michael@0 29
michael@0 30 tabs.open({
michael@0 31 url: 'about:blank',
michael@0 32 isPrivate: true,
michael@0 33 onOpen: function(tab) {
michael@0 34 // test that getOwnerWindow works as expected
michael@0 35 if (is('Fennec')) {
michael@0 36 assert.notStrictEqual(chromeWindow, getOwnerWindow(tab));
michael@0 37 assert.ok(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow);
michael@0 38 }
michael@0 39 else {
michael@0 40 if (isWindowPBSupported) {
michael@0 41 assert.notStrictEqual(chromeWindow,
michael@0 42 getOwnerWindow(tab),
michael@0 43 'associated window is not the same for window and window\'s tab');
michael@0 44 }
michael@0 45 else {
michael@0 46 assert.strictEqual(chromeWindow,
michael@0 47 getOwnerWindow(tab),
michael@0 48 'associated window is the same for window and window\'s tab');
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 let pbSupported = isTabPBSupported || isWindowPBSupported;
michael@0 53
michael@0 54 // test that the tab is private if it should be
michael@0 55 assert.equal(isPrivate(tab), pbSupported);
michael@0 56 assert.equal(isPrivate(getOwnerWindow(tab)), pbSupported);
michael@0 57
michael@0 58 tab.close(function() done());
michael@0 59 }
michael@0 60 });
michael@0 61 };
michael@0 62
michael@0 63 // test that it is possible to open a private tab
michael@0 64 exports.testTabOpenPrivate = function(assert, done) {
michael@0 65 tabs.open({
michael@0 66 url: TAB_URL,
michael@0 67 isPrivate: true,
michael@0 68 onReady: function(tab) {
michael@0 69 assert.equal(tab.url, TAB_URL, 'opened correct tab');
michael@0 70 assert.equal(isPrivate(tab), (isWindowPBSupported || isTabPBSupported));
michael@0 71
michael@0 72 tab.close(function() {
michael@0 73 done();
michael@0 74 });
michael@0 75 }
michael@0 76 });
michael@0 77 }
michael@0 78
michael@0 79
michael@0 80 // test that it is possible to open a non private tab
michael@0 81 exports.testTabOpenPrivateDefault = function(assert, done) {
michael@0 82 tabs.open({
michael@0 83 url: TAB_URL,
michael@0 84 onReady: function(tab) {
michael@0 85 assert.equal(tab.url, TAB_URL, 'opened correct tab');
michael@0 86 assert.equal(isPrivate(tab), false);
michael@0 87
michael@0 88 tab.close(function() {
michael@0 89 done();
michael@0 90 });
michael@0 91 }
michael@0 92 });
michael@0 93 }
michael@0 94
michael@0 95 // test that it is possible to open a non private tab in explicit case
michael@0 96 exports.testTabOpenPrivateOffExplicit = function(assert, done) {
michael@0 97 tabs.open({
michael@0 98 url: TAB_URL,
michael@0 99 isPrivate: false,
michael@0 100 onReady: function(tab) {
michael@0 101 assert.equal(tab.url, TAB_URL, 'opened correct tab');
michael@0 102 assert.equal(isPrivate(tab), false);
michael@0 103
michael@0 104 tab.close(function() {
michael@0 105 done();
michael@0 106 });
michael@0 107 }
michael@0 108 });
michael@0 109 }
michael@0 110
michael@0 111 // test windows.open with isPrivate: true
michael@0 112 // test isPrivate on a window
michael@0 113 if (!is('Fennec')) {
michael@0 114 // test that it is possible to open a private window
michael@0 115 exports.testWindowOpenPrivate = function(assert, done) {
michael@0 116 windows.open({
michael@0 117 url: TAB_URL,
michael@0 118 isPrivate: true,
michael@0 119 onOpen: function(window) {
michael@0 120 let tab = window.tabs[0];
michael@0 121 tab.once('ready', function() {
michael@0 122 assert.equal(tab.url, TAB_URL, 'opened correct tab');
michael@0 123 assert.equal(isPrivate(tab), isWindowPBSupported, 'tab is private');
michael@0 124
michael@0 125 window.close(function() {
michael@0 126 done();
michael@0 127 });
michael@0 128 });
michael@0 129 }
michael@0 130 });
michael@0 131 };
michael@0 132
michael@0 133 exports.testIsPrivateOnWindowOn = function(assert, done) {
michael@0 134 windows.open({
michael@0 135 isPrivate: true,
michael@0 136 onOpen: function(window) {
michael@0 137 assert.equal(isPrivate(window), isWindowPBSupported, 'isPrivate for a window is true when it should be');
michael@0 138 assert.equal(isPrivate(window.tabs[0]), isWindowPBSupported, 'isPrivate for a tab is false when it should be');
michael@0 139 window.close(done);
michael@0 140 }
michael@0 141 });
michael@0 142 };
michael@0 143
michael@0 144 exports.testIsPrivateOnWindowOffImplicit = function(assert, done) {
michael@0 145 windows.open({
michael@0 146 onOpen: function(window) {
michael@0 147 assert.equal(isPrivate(window), false, 'isPrivate for a window is false when it should be');
michael@0 148 assert.equal(isPrivate(window.tabs[0]), false, 'isPrivate for a tab is false when it should be');
michael@0 149 window.close(done);
michael@0 150 }
michael@0 151 })
michael@0 152 }
michael@0 153
michael@0 154 exports.testIsPrivateOnWindowOffExplicit = function(assert, done) {
michael@0 155 windows.open({
michael@0 156 isPrivate: false,
michael@0 157 onOpen: function(window) {
michael@0 158 assert.equal(isPrivate(window), false, 'isPrivate for a window is false when it should be');
michael@0 159 assert.equal(isPrivate(window.tabs[0]), false, 'isPrivate for a tab is false when it should be');
michael@0 160 window.close(done);
michael@0 161 }
michael@0 162 })
michael@0 163 }
michael@0 164 }

mercurial