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 | const { Ci, Cu } = require('chrome'); |
michael@0 | 7 | const { safeMerge } = require('sdk/util/object'); |
michael@0 | 8 | const windows = require('sdk/windows').browserWindows; |
michael@0 | 9 | const tabs = require('sdk/tabs'); |
michael@0 | 10 | const winUtils = require('sdk/window/utils'); |
michael@0 | 11 | const { isWindowPrivate } = winUtils; |
michael@0 | 12 | const { isPrivateBrowsingSupported } = require('sdk/self'); |
michael@0 | 13 | const { is } = require('sdk/system/xul-app'); |
michael@0 | 14 | const { isPrivate } = require('sdk/private-browsing'); |
michael@0 | 15 | const { getOwnerWindow } = require('sdk/private-browsing/window/utils'); |
michael@0 | 16 | const { LoaderWithHookedConsole } = require("sdk/test/loader"); |
michael@0 | 17 | const { getMode, isGlobalPBSupported, |
michael@0 | 18 | isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils'); |
michael@0 | 19 | const { pb } = require('./private-browsing/helper'); |
michael@0 | 20 | const prefs = require('sdk/preferences/service'); |
michael@0 | 21 | const { set: setPref } = require("sdk/preferences/service"); |
michael@0 | 22 | const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings"; |
michael@0 | 23 | |
michael@0 | 24 | const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); |
michael@0 | 25 | |
michael@0 | 26 | const kAutoStartPref = "browser.privatebrowsing.autostart"; |
michael@0 | 27 | |
michael@0 | 28 | // is global pb is enabled? |
michael@0 | 29 | if (isGlobalPBSupported) { |
michael@0 | 30 | safeMerge(module.exports, require('./private-browsing/global')); |
michael@0 | 31 | |
michael@0 | 32 | exports.testGlobalOnlyOnFirefox = function(assert) { |
michael@0 | 33 | assert.ok(is("Firefox"), "isGlobalPBSupported is only true on Firefox"); |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | else if (isWindowPBSupported) { |
michael@0 | 37 | safeMerge(module.exports, require('./private-browsing/windows')); |
michael@0 | 38 | |
michael@0 | 39 | exports.testPWOnlyOnFirefox = function(assert) { |
michael@0 | 40 | assert.ok(is("Firefox"), "isWindowPBSupported is only true on Firefox"); |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | // only on Fennec |
michael@0 | 44 | else if (isTabPBSupported) { |
michael@0 | 45 | safeMerge(module.exports, require('./private-browsing/tabs')); |
michael@0 | 46 | |
michael@0 | 47 | exports.testPTOnlyOnFennec = function(assert) { |
michael@0 | 48 | assert.ok(is("Fennec"), "isTabPBSupported is only true on Fennec"); |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | exports.testIsPrivateDefaults = function(assert) { |
michael@0 | 53 | assert.equal(isPrivate(), false, 'undefined is not private'); |
michael@0 | 54 | assert.equal(isPrivate('test'), false, 'strings are not private'); |
michael@0 | 55 | assert.equal(isPrivate({}), false, 'random objects are not private'); |
michael@0 | 56 | assert.equal(isPrivate(4), false, 'numbers are not private'); |
michael@0 | 57 | assert.equal(isPrivate(/abc/), false, 'regex are not private'); |
michael@0 | 58 | assert.equal(isPrivate(function() {}), false, 'functions are not private'); |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | exports.testWindowDefaults = function(assert) { |
michael@0 | 62 | setPref(DEPRECATE_PREF, true); |
michael@0 | 63 | // Ensure that browserWindow still works while being deprecated |
michael@0 | 64 | let { loader, messages } = LoaderWithHookedConsole(module); |
michael@0 | 65 | let windows = loader.require("sdk/windows").browserWindows; |
michael@0 | 66 | assert.equal(windows.activeWindow.isPrivateBrowsing, false, |
michael@0 | 67 | 'window is not private browsing by default'); |
michael@0 | 68 | assert.ok(/DEPRECATED.+isPrivateBrowsing/.test(messages[0].msg), |
michael@0 | 69 | 'isPrivateBrowsing is deprecated'); |
michael@0 | 70 | |
michael@0 | 71 | let chromeWin = winUtils.getMostRecentBrowserWindow(); |
michael@0 | 72 | assert.equal(getMode(chromeWin), false); |
michael@0 | 73 | assert.equal(isWindowPrivate(chromeWin), false); |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | // tests for the case where private browsing doesn't exist |
michael@0 | 77 | exports.testIsActiveDefault = function(assert) { |
michael@0 | 78 | assert.equal(pb.isActive, false, |
michael@0 | 79 | 'pb.isActive returns false when private browsing isn\'t supported'); |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | exports.testIsPrivateBrowsingFalseDefault = function(assert) { |
michael@0 | 83 | assert.equal(isPrivateBrowsingSupported, false, |
michael@0 | 84 | 'isPrivateBrowsingSupported property is false by default'); |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | exports.testGetOwnerWindow = function(assert, done) { |
michael@0 | 88 | let window = windows.activeWindow; |
michael@0 | 89 | let chromeWindow = getOwnerWindow(window); |
michael@0 | 90 | assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found'); |
michael@0 | 91 | |
michael@0 | 92 | tabs.open({ |
michael@0 | 93 | url: 'about:blank', |
michael@0 | 94 | isPrivate: true, |
michael@0 | 95 | onOpen: function(tab) { |
michael@0 | 96 | // test that getOwnerWindow works as expected |
michael@0 | 97 | if (is('Fennec')) { |
michael@0 | 98 | assert.notStrictEqual(chromeWindow, getOwnerWindow(tab)); |
michael@0 | 99 | assert.ok(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow); |
michael@0 | 100 | } |
michael@0 | 101 | else { |
michael@0 | 102 | assert.strictEqual(chromeWindow, getOwnerWindow(tab), 'associated window is the same for window and window\'s tab'); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | // test that the tab is not private |
michael@0 | 106 | // private flag should be ignored by default |
michael@0 | 107 | assert.ok(!isPrivate(tab)); |
michael@0 | 108 | assert.ok(!isPrivate(getOwnerWindow(tab))); |
michael@0 | 109 | |
michael@0 | 110 | tab.close(done); |
michael@0 | 111 | } |
michael@0 | 112 | }); |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | exports.testNSIPrivateBrowsingChannel = function(assert) { |
michael@0 | 116 | let channel = Services.io.newChannel("about:blank", null, null); |
michael@0 | 117 | channel.QueryInterface(Ci.nsIPrivateBrowsingChannel); |
michael@0 | 118 | assert.equal(isPrivate(channel), false, 'isPrivate detects non-private channels'); |
michael@0 | 119 | channel.setPrivate(true); |
michael@0 | 120 | assert.ok(isPrivate(channel), 'isPrivate detects private channels'); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | exports.testNewGlobalPBService = function(assert) { |
michael@0 | 124 | assert.equal(isPrivate(), false, 'isPrivate() is false by default'); |
michael@0 | 125 | prefs.set(kAutoStartPref, true); |
michael@0 | 126 | assert.equal(prefs.get(kAutoStartPref, false), true, kAutoStartPref + ' is true now'); |
michael@0 | 127 | assert.equal(isPrivate(), true, 'isPrivate() is true now'); |
michael@0 | 128 | prefs.set(kAutoStartPref, false); |
michael@0 | 129 | assert.equal(isPrivate(), false, 'isPrivate() is false again'); |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | require('sdk/test').run(exports); |