Thu, 15 Jan 2015 15:59:08 +0100
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 { Cu } = require('chrome'); |
michael@0 | 7 | const sp = require('sdk/simple-prefs'); |
michael@0 | 8 | const app = require('sdk/system/xul-app'); |
michael@0 | 9 | const self = require('sdk/self'); |
michael@0 | 10 | const tabs = require('sdk/tabs'); |
michael@0 | 11 | const { preferencesBranch } = require('sdk/self'); |
michael@0 | 12 | |
michael@0 | 13 | const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {}); |
michael@0 | 14 | |
michael@0 | 15 | exports.testRegression = function(assert) { |
michael@0 | 16 | assert.equal(self.preferencesBranch, self.id, 'preferencesBranch returns id here'); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | exports.testDefaultValues = function (assert) { |
michael@0 | 20 | assert.equal(sp.prefs.myHiddenInt, 5, 'myHiddenInt default is 5'); |
michael@0 | 21 | assert.equal(sp.prefs.myInteger, 8, 'myInteger default is 8'); |
michael@0 | 22 | assert.equal(sp.prefs.somePreference, 'TEST', 'somePreference default is correct'); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | exports.testOptionsType = function(assert, done) { |
michael@0 | 26 | AddonManager.getAddonByID(self.id, function(aAddon) { |
michael@0 | 27 | assert.equal(aAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, 'options type is inline'); |
michael@0 | 28 | done(); |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | if (app.is('Firefox')) { |
michael@0 | 33 | exports.testAOM = function(assert, done) { |
michael@0 | 34 | tabs.open({ |
michael@0 | 35 | url: 'about:addons', |
michael@0 | 36 | onReady: function(tab) { |
michael@0 | 37 | tab.attach({ |
michael@0 | 38 | contentScriptWhen: 'end', |
michael@0 | 39 | contentScript: 'function onLoad() {\n' + |
michael@0 | 40 | 'unsafeWindow.removeEventListener("load", onLoad, false);\n' + |
michael@0 | 41 | 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' + |
michael@0 | 42 | 'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' + |
michael@0 | 43 | 'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' + |
michael@0 | 44 | 'setTimeout(function() {\n' + // TODO: figure out why this is necessary.. |
michael@0 | 45 | 'self.postMessage({\n' + |
michael@0 | 46 | 'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[title=\'some-title\']")),\n' + |
michael@0 | 47 | 'myInteger: getAttributes(unsafeWindow.document.querySelector("setting[title=\'my-int\']")),\n' + |
michael@0 | 48 | 'myHiddenInt: getAttributes(unsafeWindow.document.querySelector("setting[title=\'hidden-int\']"))\n' + |
michael@0 | 49 | '});\n' + |
michael@0 | 50 | '}, 250);\n' + |
michael@0 | 51 | '}, false);\n' + |
michael@0 | 52 | 'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' + |
michael@0 | 53 | '});\n' + |
michael@0 | 54 | 'function getAttributes(ele) {\n' + |
michael@0 | 55 | 'if (!ele) return {};\n' + |
michael@0 | 56 | 'return {\n' + |
michael@0 | 57 | 'pref: ele.getAttribute("pref"),\n' + |
michael@0 | 58 | 'type: ele.getAttribute("type"),\n' + |
michael@0 | 59 | 'title: ele.getAttribute("title"),\n' + |
michael@0 | 60 | 'desc: ele.getAttribute("desc")\n' + |
michael@0 | 61 | '}\n' + |
michael@0 | 62 | '}\n' + |
michael@0 | 63 | '}\n' + |
michael@0 | 64 | // Wait for the load event ? |
michael@0 | 65 | 'if (document.readyState == "complete") {\n' + |
michael@0 | 66 | 'onLoad()\n' + |
michael@0 | 67 | '} else {\n' + |
michael@0 | 68 | 'unsafeWindow.addEventListener("load", onLoad, false);\n' + |
michael@0 | 69 | '}\n', |
michael@0 | 70 | onMessage: function(msg) { |
michael@0 | 71 | // test somePreference |
michael@0 | 72 | assert.equal(msg.somePreference.type, 'string', 'some pref is a string'); |
michael@0 | 73 | assert.equal(msg.somePreference.pref, 'extensions.'+self.preferencesBranch+'.somePreference', 'somePreference path is correct'); |
michael@0 | 74 | assert.equal(msg.somePreference.title, 'some-title', 'somePreference title is correct'); |
michael@0 | 75 | assert.equal(msg.somePreference.desc, 'Some short description for the preference', 'somePreference description is correct'); |
michael@0 | 76 | |
michael@0 | 77 | // test myInteger |
michael@0 | 78 | assert.equal(msg.myInteger.type, 'integer', 'myInteger is a int'); |
michael@0 | 79 | assert.equal(msg.myInteger.pref, 'extensions.'+self.preferencesBranch+'.myInteger', 'extensions.test-simple-prefs.myInteger'); |
michael@0 | 80 | assert.equal(msg.myInteger.title, 'my-int', 'myInteger title is correct'); |
michael@0 | 81 | assert.equal(msg.myInteger.desc, 'How many of them we have.', 'myInteger desc is correct'); |
michael@0 | 82 | |
michael@0 | 83 | // test myHiddenInt |
michael@0 | 84 | assert.equal(msg.myHiddenInt.type, undefined, 'myHiddenInt was not displayed'); |
michael@0 | 85 | assert.equal(msg.myHiddenInt.pref, undefined, 'myHiddenInt was not displayed'); |
michael@0 | 86 | assert.equal(msg.myHiddenInt.title, undefined, 'myHiddenInt was not displayed'); |
michael@0 | 87 | assert.equal(msg.myHiddenInt.desc, undefined, 'myHiddenInt was not displayed'); |
michael@0 | 88 | |
michael@0 | 89 | tab.close(done); |
michael@0 | 90 | } |
michael@0 | 91 | }); |
michael@0 | 92 | } |
michael@0 | 93 | }); |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | require('sdk/test/runner').runTestsFromModule(module); |