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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 'use strict';
6 const { Cu } = require('chrome');
7 const sp = require('sdk/simple-prefs');
8 const app = require('sdk/system/xul-app');
9 const self = require('sdk/self');
10 const tabs = require('sdk/tabs');
11 const { preferencesBranch } = require('sdk/self');
13 const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {});
15 exports.testDefaultValues = function (assert) {
16 assert.equal(sp.prefs.myHiddenInt, 5, 'myHiddenInt default is 5');
17 assert.equal(sp.prefs.myInteger, 8, 'myInteger default is 8');
18 assert.equal(sp.prefs.somePreference, 'TEST', 'somePreference default is correct');
19 }
21 exports.testOptionsType = function(assert, done) {
22 AddonManager.getAddonByID(self.id, function(aAddon) {
23 assert.equal(aAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, 'options type is inline');
24 done();
25 });
26 }
28 exports.testButton = function(assert, done) {
29 tabs.open({
30 url: 'about:addons',
31 onReady: function(tab) {
32 sp.once('sayHello', function() {
33 assert.pass('The button was pressed!');
34 tab.close(done)
35 });
37 tab.attach({
38 contentScriptWhen: 'end',
39 contentScript: 'function onLoad() {\n' +
40 'unsafeWindow.removeEventListener("load", onLoad, false);\n' +
41 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' +
42 'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' +
43 'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' +
44 'setTimeout(function() {\n' + // TODO: figure out why this is necessary..
45 'unsafeWindow.document.querySelector("button[label=\'Click me!\']").click()\n' +
46 '}, 250);\n' +
47 '}, false);\n' +
48 'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' +
49 '});\n' +
50 '}\n' +
51 // Wait for the load event ?
52 'if (document.readyState == "complete") {\n' +
53 'onLoad()\n' +
54 '} else {\n' +
55 'unsafeWindow.addEventListener("load", onLoad, false);\n' +
56 '}\n',
57 });
58 }
59 });
60 }
62 if (app.is('Firefox')) {
63 exports.testAOM = function(assert, done) {
64 tabs.open({
65 url: 'about:addons',
66 onReady: function(tab) {
67 tab.attach({
68 contentScriptWhen: 'end',
69 contentScript: 'function onLoad() {\n' +
70 'unsafeWindow.removeEventListener("load", onLoad, false);\n' +
71 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' +
72 'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' +
73 'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' +
74 'setTimeout(function() {\n' + // TODO: figure out why this is necessary..
75 'self.postMessage({\n' +
76 'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[title=\'some-title\']")),\n' +
77 'myInteger: getAttributes(unsafeWindow.document.querySelector("setting[title=\'my-int\']")),\n' +
78 'myHiddenInt: getAttributes(unsafeWindow.document.querySelector("setting[title=\'hidden-int\']")),\n' +
79 'sayHello: getAttributes(unsafeWindow.document.querySelector("button[label=\'Click me!\']"))\n' +
80 '});\n' +
81 '}, 250);\n' +
82 '}, false);\n' +
83 'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' +
84 '});\n' +
85 'function getAttributes(ele) {\n' +
86 'if (!ele) return {};\n' +
87 'return {\n' +
88 'pref: ele.getAttribute("pref"),\n' +
89 'type: ele.getAttribute("type"),\n' +
90 'title: ele.getAttribute("title"),\n' +
91 'desc: ele.getAttribute("desc"),\n' +
92 '"data-jetpack-id": ele.getAttribute(\'data-jetpack-id\')\n' +
93 '}\n' +
94 '}\n' +
95 '}\n' +
96 // Wait for the load event ?
97 'if (document.readyState == "complete") {\n' +
98 'onLoad()\n' +
99 '} else {\n' +
100 'unsafeWindow.addEventListener("load", onLoad, false);\n' +
101 '}\n',
102 onMessage: function(msg) {
103 // test somePreference
104 assert.equal(msg.somePreference.type, 'string', 'some pref is a string');
105 assert.equal(msg.somePreference.pref, 'extensions.'+self.id+'.somePreference', 'somePreference path is correct');
106 assert.equal(msg.somePreference.title, 'some-title', 'somePreference title is correct');
107 assert.equal(msg.somePreference.desc, 'Some short description for the preference', 'somePreference description is correct');
108 assert.equal(msg.somePreference['data-jetpack-id'], self.id, 'data-jetpack-id attribute value is correct');
110 // test myInteger
111 assert.equal(msg.myInteger.type, 'integer', 'myInteger is a int');
112 assert.equal(msg.myInteger.pref, 'extensions.'+self.id+'.myInteger', 'extensions.test-simple-prefs.myInteger');
113 assert.equal(msg.myInteger.title, 'my-int', 'myInteger title is correct');
114 assert.equal(msg.myInteger.desc, 'How many of them we have.', 'myInteger desc is correct');
115 assert.equal(msg.myInteger['data-jetpack-id'], self.id, 'data-jetpack-id attribute value is correct');
117 // test myHiddenInt
118 assert.equal(msg.myHiddenInt.type, undefined, 'myHiddenInt was not displayed');
119 assert.equal(msg.myHiddenInt.pref, undefined, 'myHiddenInt was not displayed');
120 assert.equal(msg.myHiddenInt.title, undefined, 'myHiddenInt was not displayed');
121 assert.equal(msg.myHiddenInt.desc, undefined, 'myHiddenInt was not displayed');
123 // test sayHello
124 assert.equal(msg.sayHello['data-jetpack-id'], self.id, 'data-jetpack-id attribute value is correct');
126 tab.close(done);
127 }
128 });
129 }
130 });
131 }
132 }
134 exports.testDefaultPreferencesBranch = function(assert) {
135 assert.equal(preferencesBranch, self.id, 'preferencesBranch default the same as self.id');
136 }
138 require('sdk/test/runner').runTestsFromModule(module);