Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | // Fennec support tracked in bug #809412 |
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 windowUtils = require('sdk/deprecated/window-utils'); |
michael@0 | 14 | const { Cc, Ci } = require('chrome'); |
michael@0 | 15 | const { isWindowPBSupported } = require('sdk/private-browsing/utils'); |
michael@0 | 16 | const { getFrames, getWindowTitle, onFocus, isWindowPrivate } = require('sdk/window/utils'); |
michael@0 | 17 | const { open, close, focus } = require('sdk/window/helpers'); |
michael@0 | 18 | const WM = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator); |
michael@0 | 19 | const { isPrivate } = require('sdk/private-browsing'); |
michael@0 | 20 | const { fromIterator: toArray } = require('sdk/util/array'); |
michael@0 | 21 | const { defer } = require('sdk/core/promise'); |
michael@0 | 22 | const { setTimeout } = require('sdk/timers'); |
michael@0 | 23 | |
michael@0 | 24 | function tick() { |
michael@0 | 25 | let deferred = defer(); |
michael@0 | 26 | setTimeout(deferred.resolve); |
michael@0 | 27 | return deferred.promise; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function makeEmptyBrowserWindow(options) { |
michael@0 | 31 | options = options || {}; |
michael@0 | 32 | return open('chrome://browser/content/browser.xul', { |
michael@0 | 33 | features: { |
michael@0 | 34 | chrome: true, |
michael@0 | 35 | private: !!options.private |
michael@0 | 36 | } |
michael@0 | 37 | }); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | exports.testWindowTrackerIgnoresPrivateWindows = function(assert, done) { |
michael@0 | 41 | var myNonPrivateWindow, myPrivateWindow; |
michael@0 | 42 | var finished = false; |
michael@0 | 43 | var privateWindow; |
michael@0 | 44 | var privateWindowClosed = false; |
michael@0 | 45 | |
michael@0 | 46 | let wt = windowUtils.WindowTracker({ |
michael@0 | 47 | onTrack: function(window) { |
michael@0 | 48 | assert.ok(!isWindowPrivate(window), 'private window was not tracked!'); |
michael@0 | 49 | }, |
michael@0 | 50 | onUntrack: function(window) { |
michael@0 | 51 | assert.ok(!isWindowPrivate(window), 'private window was not tracked!'); |
michael@0 | 52 | // PWPB case |
michael@0 | 53 | if (window === myPrivateWindow && isWindowPBSupported) { |
michael@0 | 54 | privateWindowClosed = true; |
michael@0 | 55 | } |
michael@0 | 56 | if (window === myNonPrivateWindow) { |
michael@0 | 57 | assert.ok(!privateWindowClosed); |
michael@0 | 58 | wt.unload(); |
michael@0 | 59 | done(); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | // make a new private window |
michael@0 | 65 | makeEmptyBrowserWindow({ |
michael@0 | 66 | private: true |
michael@0 | 67 | }).then(function(window) { |
michael@0 | 68 | myPrivateWindow = window; |
michael@0 | 69 | |
michael@0 | 70 | assert.equal(isWindowPrivate(window), isWindowPBSupported); |
michael@0 | 71 | assert.ok(getFrames(window).length > 1, 'there are frames for private window'); |
michael@0 | 72 | assert.equal(getWindowTitle(window), window.document.title, |
michael@0 | 73 | 'getWindowTitle works'); |
michael@0 | 74 | |
michael@0 | 75 | return close(window).then(function() { |
michael@0 | 76 | return makeEmptyBrowserWindow().then(function(window) { |
michael@0 | 77 | myNonPrivateWindow = window; |
michael@0 | 78 | assert.pass('opened new window'); |
michael@0 | 79 | return close(window); |
michael@0 | 80 | }); |
michael@0 | 81 | }); |
michael@0 | 82 | }).then(null, assert.fail); |
michael@0 | 83 | }; |
michael@0 | 84 | |
michael@0 | 85 | // Test setting activeWIndow and onFocus for private windows |
michael@0 | 86 | exports.testSettingActiveWindowDoesNotIgnorePrivateWindow = function(assert, done) { |
michael@0 | 87 | let browserWindow = WM.getMostRecentWindow("navigator:browser"); |
michael@0 | 88 | |
michael@0 | 89 | assert.equal(windowUtils.activeBrowserWindow, browserWindow, |
michael@0 | 90 | "Browser window is the active browser window."); |
michael@0 | 91 | assert.ok(!isPrivate(browserWindow), "Browser window is not private."); |
michael@0 | 92 | |
michael@0 | 93 | // make a new private window |
michael@0 | 94 | makeEmptyBrowserWindow({ private: true }).then(focus).then(window => { |
michael@0 | 95 | // PWPB case |
michael@0 | 96 | if (isWindowPBSupported) { |
michael@0 | 97 | assert.ok(isPrivate(window), "window is private"); |
michael@0 | 98 | assert.notDeepEqual(windowUtils.activeBrowserWindow, browserWindow); |
michael@0 | 99 | } |
michael@0 | 100 | // Global case |
michael@0 | 101 | else { |
michael@0 | 102 | assert.ok(!isPrivate(window), "window is not private"); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | assert.strictEqual(windowUtils.activeBrowserWindow, window, |
michael@0 | 106 | "Correct active browser window pb supported"); |
michael@0 | 107 | assert.notStrictEqual(browserWindow, window, |
michael@0 | 108 | "The window is not the old browser window"); |
michael@0 | 109 | |
michael@0 | 110 | |
michael@0 | 111 | return onFocus(windowUtils.activeWindow = browserWindow).then(_ => { |
michael@0 | 112 | assert.strictEqual(windowUtils.activeWindow, browserWindow, |
michael@0 | 113 | "Correct active window [1]"); |
michael@0 | 114 | assert.strictEqual(windowUtils.activeBrowserWindow, browserWindow, |
michael@0 | 115 | "Correct active browser window [1]"); |
michael@0 | 116 | |
michael@0 | 117 | // test focus(window) |
michael@0 | 118 | return focus(window).then(w => { |
michael@0 | 119 | assert.strictEqual(w, window, 'require("sdk/window/helpers").focus on window works'); |
michael@0 | 120 | }).then(tick); |
michael@0 | 121 | }).then(_ => { |
michael@0 | 122 | assert.strictEqual(windowUtils.activeBrowserWindow, window, |
michael@0 | 123 | "Correct active browser window [2]"); |
michael@0 | 124 | assert.strictEqual(windowUtils.activeWindow, window, |
michael@0 | 125 | "Correct active window [2]"); |
michael@0 | 126 | |
michael@0 | 127 | // test setting a private window |
michael@0 | 128 | return onFocus(windowUtils.activeWindow = window); |
michael@0 | 129 | }).then(function() { |
michael@0 | 130 | assert.deepEqual(windowUtils.activeBrowserWindow, window, |
michael@0 | 131 | "Correct active browser window [3]"); |
michael@0 | 132 | assert.deepEqual(windowUtils.activeWindow, window, |
michael@0 | 133 | "Correct active window [3]"); |
michael@0 | 134 | |
michael@0 | 135 | // just to get back to original state |
michael@0 | 136 | return onFocus(windowUtils.activeWindow = browserWindow); |
michael@0 | 137 | }).then(_ => { |
michael@0 | 138 | assert.deepEqual(windowUtils.activeBrowserWindow, browserWindow, |
michael@0 | 139 | "Correct active browser window when pb mode is supported [4]"); |
michael@0 | 140 | assert.deepEqual(windowUtils.activeWindow, browserWindow, |
michael@0 | 141 | "Correct active window when pb mode is supported [4]"); |
michael@0 | 142 | |
michael@0 | 143 | return close(window); |
michael@0 | 144 | }) |
michael@0 | 145 | }).then(done).then(null, assert.fail); |
michael@0 | 146 | }; |
michael@0 | 147 | |
michael@0 | 148 | exports.testActiveWindowDoesNotIgnorePrivateWindow = function(assert, done) { |
michael@0 | 149 | // make a new private window |
michael@0 | 150 | makeEmptyBrowserWindow({ |
michael@0 | 151 | private: true |
michael@0 | 152 | }).then(function(window) { |
michael@0 | 153 | // PWPB case |
michael@0 | 154 | if (isWindowPBSupported) { |
michael@0 | 155 | assert.equal(isPrivate(windowUtils.activeWindow), true, |
michael@0 | 156 | "active window is private"); |
michael@0 | 157 | assert.equal(isPrivate(windowUtils.activeBrowserWindow), true, |
michael@0 | 158 | "active browser window is private"); |
michael@0 | 159 | assert.ok(isWindowPrivate(window), "window is private"); |
michael@0 | 160 | assert.ok(isPrivate(window), "window is private"); |
michael@0 | 161 | |
michael@0 | 162 | // pb mode is supported |
michael@0 | 163 | assert.ok( |
michael@0 | 164 | isWindowPrivate(windowUtils.activeWindow), |
michael@0 | 165 | "active window is private when pb mode is supported"); |
michael@0 | 166 | assert.ok( |
michael@0 | 167 | isWindowPrivate(windowUtils.activeBrowserWindow), |
michael@0 | 168 | "active browser window is private when pb mode is supported"); |
michael@0 | 169 | assert.ok(isPrivate(windowUtils.activeWindow), |
michael@0 | 170 | "active window is private when pb mode is supported"); |
michael@0 | 171 | assert.ok(isPrivate(windowUtils.activeBrowserWindow), |
michael@0 | 172 | "active browser window is private when pb mode is supported"); |
michael@0 | 173 | } |
michael@0 | 174 | // Global case |
michael@0 | 175 | else { |
michael@0 | 176 | assert.equal(isPrivate(windowUtils.activeWindow), false, |
michael@0 | 177 | "active window is not private"); |
michael@0 | 178 | assert.equal(isPrivate(windowUtils.activeBrowserWindow), false, |
michael@0 | 179 | "active browser window is not private"); |
michael@0 | 180 | assert.equal(isWindowPrivate(window), false, "window is not private"); |
michael@0 | 181 | assert.equal(isPrivate(window), false, "window is not private"); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | return close(window); |
michael@0 | 185 | }).then(done).then(null, assert.fail); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | exports.testWindowIteratorIgnoresPrivateWindows = function(assert, done) { |
michael@0 | 189 | // make a new private window |
michael@0 | 190 | makeEmptyBrowserWindow({ |
michael@0 | 191 | private: true |
michael@0 | 192 | }).then(function(window) { |
michael@0 | 193 | // PWPB case |
michael@0 | 194 | if (isWindowPBSupported) { |
michael@0 | 195 | assert.ok(isWindowPrivate(window), "window is private"); |
michael@0 | 196 | assert.equal(toArray(windowUtils.windowIterator()).indexOf(window), -1, |
michael@0 | 197 | "window is not in windowIterator()"); |
michael@0 | 198 | } |
michael@0 | 199 | // Global case |
michael@0 | 200 | else { |
michael@0 | 201 | assert.equal(isWindowPrivate(window), false, "window is not private"); |
michael@0 | 202 | assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) > -1, |
michael@0 | 203 | "window is in windowIterator()"); |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | return close(window); |
michael@0 | 207 | }).then(done).then(null, assert.fail); |
michael@0 | 208 | }; |
michael@0 | 209 | |
michael@0 | 210 | require("sdk/test").run(exports); |