addon-sdk/source/test/addons/private-browsing-supported/test-global-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 windowUtils = require('sdk/deprecated/window-utils');
michael@0 7 const { isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils');
michael@0 8 const { getFrames, getWindowTitle, onFocus, isWindowPrivate, windows, isBrowser } = require('sdk/window/utils');
michael@0 9 const { open, close, focus } = require('sdk/window/helpers');
michael@0 10 const { isPrivate } = require('sdk/private-browsing');
michael@0 11 const { Panel } = require('sdk/panel');
michael@0 12 const { Widget } = require('sdk/widget');
michael@0 13 const { fromIterator: toArray } = require('sdk/util/array');
michael@0 14
michael@0 15 let { Loader } = require('sdk/test/loader');
michael@0 16 let loader = Loader(module, {
michael@0 17 console: Object.create(console, {
michael@0 18 error: {
michael@0 19 value: function(e) !/DEPRECATED:/.test(e) ? console.error(e) : undefined
michael@0 20 }
michael@0 21 })
michael@0 22 });
michael@0 23 const pb = loader.require('sdk/private-browsing');
michael@0 24
michael@0 25 function makeEmptyBrowserWindow(options) {
michael@0 26 options = options || {};
michael@0 27 return open('chrome://browser/content/browser.xul', {
michael@0 28 features: {
michael@0 29 chrome: true,
michael@0 30 private: !!options.private,
michael@0 31 toolbar: true
michael@0 32 }
michael@0 33 });
michael@0 34 }
michael@0 35
michael@0 36 exports.testShowPanelAndWidgetOnPrivateWindow = function(assert, done) {
michael@0 37 var myPrivateWindow;
michael@0 38 var finished = false;
michael@0 39 var privateWindow;
michael@0 40 var privateWindowClosed = false;
michael@0 41
michael@0 42 pb.once('start', function() {
michael@0 43 assert.pass('private browsing mode started');
michael@0 44
michael@0 45 // make a new private window
michael@0 46 makeEmptyBrowserWindow().then(function(window) {
michael@0 47 myPrivateWindow = window;
michael@0 48
michael@0 49 let wt = windowUtils.WindowTracker({
michael@0 50 onTrack: function(window) {
michael@0 51 if (!isBrowser(window) || window !== myPrivateWindow) return;
michael@0 52
michael@0 53 assert.ok(isWindowPrivate(window), 'window is private onTrack!');
michael@0 54 let panel = Panel({
michael@0 55 onShow: function() {
michael@0 56 assert.ok(this.isShowing, 'the panel is showing on the private window');
michael@0 57
michael@0 58 let count = 0;
michael@0 59 let widget = Widget({
michael@0 60 id: "testShowPanelAndWidgetOnPrivateWindow-id",
michael@0 61 label: "My Hello Widget",
michael@0 62 content: "Hello!",
michael@0 63 onAttach: function(mod) {
michael@0 64 count++;
michael@0 65 if (count == 2) {
michael@0 66 panel.destroy();
michael@0 67 widget.destroy();
michael@0 68 close(window);
michael@0 69 }
michael@0 70 }
michael@0 71 });
michael@0 72 }
michael@0 73 }).show(null, window.gBrowser);
michael@0 74 },
michael@0 75 onUntrack: function(window) {
michael@0 76 if (window === myPrivateWindow) {
michael@0 77 wt.unload();
michael@0 78
michael@0 79 pb.once('stop', function() {
michael@0 80 assert.pass('private browsing mode end');
michael@0 81 done();
michael@0 82 });
michael@0 83
michael@0 84 pb.deactivate();
michael@0 85 }
michael@0 86 }
michael@0 87 });
michael@0 88
michael@0 89 assert.equal(isWindowPrivate(window), true, 'the opened window is private');
michael@0 90 assert.equal(isPrivate(window), true, 'the opened window is private');
michael@0 91 assert.ok(getFrames(window).length > 1, 'there are frames for private window');
michael@0 92 assert.equal(getWindowTitle(window), window.document.title,
michael@0 93 'getWindowTitle works');
michael@0 94 });
michael@0 95 });
michael@0 96 pb.activate();
michael@0 97 };
michael@0 98
michael@0 99 exports.testWindowTrackerDoesNotIgnorePrivateWindows = function(assert, done) {
michael@0 100 var myPrivateWindow;
michael@0 101 var count = 0;
michael@0 102
michael@0 103 let wt = windowUtils.WindowTracker({
michael@0 104 onTrack: function(window) {
michael@0 105 if (!isBrowser(window) || !isWindowPrivate(window)) return;
michael@0 106 assert.ok(isWindowPrivate(window), 'window is private onTrack!');
michael@0 107 if (++count == 1)
michael@0 108 close(window);
michael@0 109 },
michael@0 110 onUntrack: function(window) {
michael@0 111 if (count == 1 && isWindowPrivate(window)) {
michael@0 112 wt.unload();
michael@0 113
michael@0 114 pb.once('stop', function() {
michael@0 115 assert.pass('private browsing mode end');
michael@0 116 done();
michael@0 117 });
michael@0 118 pb.deactivate();
michael@0 119 }
michael@0 120 }
michael@0 121 });
michael@0 122
michael@0 123 pb.once('start', function() {
michael@0 124 assert.pass('private browsing mode started');
michael@0 125 makeEmptyBrowserWindow();
michael@0 126 });
michael@0 127 pb.activate();
michael@0 128 }
michael@0 129
michael@0 130 exports.testWindowIteratorDoesNotIgnorePrivateWindows = function(assert, done) {
michael@0 131 pb.once('start', function() {
michael@0 132 // make a new private window
michael@0 133 makeEmptyBrowserWindow().then(function(window) {
michael@0 134 assert.ok(isWindowPrivate(window), "window is private");
michael@0 135 assert.equal(isPrivate(window), true, 'the opened window is private');
michael@0 136 assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) > -1,
michael@0 137 "window is in windowIterator()");
michael@0 138 assert.ok(windows(null, { includePrivate: true }).indexOf(window) > -1,
michael@0 139 "window is in windows()");
michael@0 140
michael@0 141 return close(window).then(function() {
michael@0 142 pb.once('stop', function() {
michael@0 143 done();
michael@0 144 });
michael@0 145 pb.deactivate();
michael@0 146 });
michael@0 147 }).then(null, assert.fail);
michael@0 148 });
michael@0 149 pb.activate();
michael@0 150 };

mercurial