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 // Opening new windows in Fennec causes issues
7 module.metadata = {
8 engines: {
9 'Firefox': '*'
10 }
11 };
13 const { Ci } = require('chrome');
14 const { open, windows, isBrowser,
15 getXULWindow, getBaseWindow, getToplevelWindow, getMostRecentWindow,
16 getMostRecentBrowserWindow } = require('sdk/window/utils');
17 const { close } = require('sdk/window/helpers');
18 const windowUtils = require('sdk/deprecated/window-utils');
20 exports['test get nsIBaseWindow from nsIDomWindow'] = function(assert) {
21 let active = windowUtils.activeBrowserWindow;
23 assert.ok(!(active instanceof Ci.nsIBaseWindow),
24 'active window is not nsIBaseWindow');
26 assert.ok(getBaseWindow(active) instanceof Ci.nsIBaseWindow,
27 'base returns nsIBaseWindow');
28 };
30 exports['test get nsIXULWindow from nsIDomWindow'] = function(assert) {
31 let active = windowUtils.activeBrowserWindow;
32 assert.ok(!(active instanceof Ci.nsIXULWindow),
33 'active window is not nsIXULWindow');
34 assert.ok(getXULWindow(active) instanceof Ci.nsIXULWindow,
35 'base returns nsIXULWindow');
36 };
38 exports['test getToplevelWindow'] = function(assert) {
39 let active = windowUtils.activeBrowserWindow;
40 assert.equal(getToplevelWindow(active), active,
41 'getToplevelWindow of toplevel window returns the same window');
42 assert.equal(getToplevelWindow(active.content), active,
43 'getToplevelWindow of tab window returns the browser window');
44 assert.ok(getToplevelWindow(active) instanceof Ci.nsIDOMWindow,
45 'getToplevelWindow returns nsIDOMWindow');
46 };
48 exports['test top window creation'] = function(assert, done) {
49 let window = open('data:text/html;charset=utf-8,Hello top window');
50 assert.ok(~windows().indexOf(window), 'window was opened');
52 // Wait for the window unload before ending test
53 close(window).then(done);
54 };
56 exports['test new top window with options'] = function(assert, done) {
57 let window = open('data:text/html;charset=utf-8,Hi custom top window', {
58 name: 'test',
59 features: { height: 100, width: 200, toolbar: true }
60 });
61 assert.ok(~windows().indexOf(window), 'window was opened');
62 assert.equal(window.name, 'test', 'name was set');
63 assert.equal(window.innerHeight, 100, 'height is set');
64 assert.equal(window.innerWidth, 200, 'height is set');
65 assert.equal(window.toolbar.visible, true, 'toolbar was set');
67 // Wait for the window unload before ending test
68 close(window).then(done);
69 };
71 exports['test new top window with various URIs'] = function(assert, done) {
72 let msg = 'only chrome, resource and data uris are allowed';
73 assert.throws(function () {
74 open('foo');
75 }, msg);
76 assert.throws(function () {
77 open('http://foo');
78 }, msg);
79 assert.throws(function () {
80 open('https://foo');
81 }, msg);
82 assert.throws(function () {
83 open('ftp://foo');
84 }, msg);
85 assert.throws(function () {
86 open('//foo');
87 }, msg);
89 let chromeWindow = open('chrome://foo/content/');
90 assert.ok(~windows().indexOf(chromeWindow), 'chrome URI works');
92 let resourceWindow = open('resource://foo');
93 assert.ok(~windows().indexOf(resourceWindow), 'resource URI works');
95 // Wait for the window unload before ending test
96 close(chromeWindow).then(close.bind(null, resourceWindow)).then(done);
97 };
99 exports.testIsBrowser = function(assert) {
100 // dummy window, bad type
101 assert.equal(isBrowser({ document: { documentElement: { getAttribute: function() {
102 return 'navigator:browserx';
103 }}}}), false, 'dummy object with correct stucture and bad type does not pass');
105 assert.ok(isBrowser(getMostRecentBrowserWindow()), 'active browser window is a browser window');
106 assert.ok(!isBrowser({}), 'non window is not a browser window');
107 assert.ok(!isBrowser({ document: {} }), 'non window is not a browser window');
108 assert.ok(!isBrowser({ document: { documentElement: {} } }), 'non window is not a browser window');
109 assert.ok(!isBrowser(), 'no argument is not a browser window');
110 };
112 require('test').run(exports);