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

mercurial