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

mercurial