Thu, 15 Jan 2015 15:59:08 +0100
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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 'use strict';
6 const { isTabOpen, activateTab, openTab,
7 closeTab, getTabURL, getWindowHoldingTab } = require('sdk/tabs/utils');
8 const windows = require('sdk/deprecated/window-utils');
9 const { LoaderWithHookedConsole } = require('sdk/test/loader');
10 const { setTimeout } = require('sdk/timers');
11 const app = require("sdk/system/xul-app");
12 const tabs = require('sdk/tabs');
13 const isAustralis = "gCustomizeMode" in windows.activeBrowserWindow;
14 const { set: setPref, get: getPref } = require("sdk/preferences/service");
15 const { PrefsTarget } = require("sdk/preferences/event-target");
16 const { defer } = require('sdk/core/promise');
18 const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings";
20 let uri = require('sdk/self').data.url('index.html');
22 function closeTabPromise(tab) {
23 let { promise, resolve } = defer();
24 let url = getTabURL(tab);
26 tabs.on('close', function onCloseTab(t) {
27 if (t.url == url) {
28 tabs.removeListener('close', onCloseTab);
29 setTimeout(_ => resolve(tab))
30 }
31 });
32 closeTab(tab);
34 return promise;
35 }
37 function isChromeVisible(window) {
38 let x = window.document.documentElement.getAttribute('disablechrome')
39 return x !== 'true';
40 }
42 // Once Bug 903018 is resolved, just move the application testing to
43 // module.metadata.engines
44 if (app.is('Firefox')) {
46 exports['test add-on page deprecation message'] = function(assert, done) {
47 let { loader, messages } = LoaderWithHookedConsole(module);
49 loader.require('sdk/preferences/event-target').PrefsTarget({
50 branchName: "devtools.errorconsole."
51 }).on("deprecation_warnings", function() {
52 if (!getPref(DEPRECATE_PREF, false)) {
53 return undefined;
54 }
56 loader.require('sdk/addon-page');
58 assert.equal(messages.length, 1, "only one error is dispatched");
59 assert.equal(messages[0].type, "error", "the console message is an error");
61 let msg = messages[0].msg;
62 assert.ok(msg.indexOf("DEPRECATED") === 0,
63 "The message is deprecation message");
65 loader.unload();
66 done();
67 return undefined;
68 });
69 setPref(DEPRECATE_PREF, false);
70 setPref(DEPRECATE_PREF, true);
71 };
73 exports['test that add-on page has no chrome'] = function(assert, done) {
74 let { loader } = LoaderWithHookedConsole(module);
75 loader.require('sdk/addon-page');
77 let window = windows.activeBrowserWindow;
78 let tab = openTab(window, uri);
80 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
82 // need to do this in another turn to make sure event listener
83 // that sets property has time to do that.
84 setTimeout(function() {
85 activateTab(tab);
87 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis,
88 'chrome is not visible for addon page');
90 closeTabPromise(tab).then(function() {
91 assert.ok(isChromeVisible(window), 'chrome is visible again');
92 loader.unload();
93 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
94 done();
95 }).then(null, assert.fail);
96 });
97 };
99 exports['test that add-on page with hash has no chrome'] = function(assert, done) {
100 let { loader } = LoaderWithHookedConsole(module);
101 loader.require('sdk/addon-page');
103 let window = windows.activeBrowserWindow;
104 let tab = openTab(window, uri + "#foo");
106 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
108 // need to do this in another turn to make sure event listener
109 // that sets property has time to do that.
110 setTimeout(function() {
111 activateTab(tab);
113 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis,
114 'chrome is not visible for addon page');
116 closeTabPromise(tab).then(function() {
117 assert.ok(isChromeVisible(window), 'chrome is visible again');
118 loader.unload();
119 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
120 done();
121 }).then(null, assert.fail);
122 });
123 };
125 exports['test that add-on page with querystring has no chrome'] = function(assert, done) {
126 let { loader } = LoaderWithHookedConsole(module);
127 loader.require('sdk/addon-page');
129 let window = windows.activeBrowserWindow;
130 let tab = openTab(window, uri + '?foo=bar');
132 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
134 // need to do this in another turn to make sure event listener
135 // that sets property has time to do that.
136 setTimeout(function() {
137 activateTab(tab);
139 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis,
140 'chrome is not visible for addon page');
142 closeTabPromise(tab).then(function() {
143 assert.ok(isChromeVisible(window), 'chrome is visible again');
144 loader.unload();
145 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
146 done();
147 }).then(null, assert.fail);
148 });
149 };
151 exports['test that add-on page with hash and querystring has no chrome'] = function(assert, done) {
152 let { loader } = LoaderWithHookedConsole(module);
153 loader.require('sdk/addon-page');
155 let window = windows.activeBrowserWindow;
156 let tab = openTab(window, uri + '#foo?foo=bar');
158 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
160 // need to do this in another turn to make sure event listener
161 // that sets property has time to do that.
162 setTimeout(function() {
163 activateTab(tab);
165 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis,
166 'chrome is not visible for addon page');
168 closeTabPromise(tab).then(function() {
169 assert.ok(isChromeVisible(window), 'chrome is visible again');
170 loader.unload();
171 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
172 done();
173 }).then(null, assert.fail);
174 });
175 };
177 exports['test that malformed uri is not an addon-page'] = function(assert, done) {
178 let { loader } = LoaderWithHookedConsole(module);
179 loader.require('sdk/addon-page');
181 let window = windows.activeBrowserWindow;
182 let tab = openTab(window, uri + 'anguage');
184 // need to do this in another turn to make sure event listener
185 // that sets property has time to do that.
186 setTimeout(function() {
187 activateTab(tab);
189 assert.ok(isChromeVisible(window), 'chrome is visible for malformed uri');
191 closeTabPromise(tab).then(function() {
192 loader.unload();
193 done();
194 }).then(null, assert.fail);
195 });
196 };
198 } else {
199 exports['test unsupported'] = (assert) => assert.pass('This application is unsupported.');
200 }
202 require('sdk/test/runner').runTestsFromModule(module);