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 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const { Hotkey } = require("sdk/hotkeys"); |
michael@0 | 8 | const { keyDown } = require("sdk/dom/events/keys"); |
michael@0 | 9 | const { Loader } = require('sdk/test/loader'); |
michael@0 | 10 | const timer = require("sdk/timers"); |
michael@0 | 11 | const winUtils = require("sdk/deprecated/window-utils"); |
michael@0 | 12 | |
michael@0 | 13 | exports["test hotkey: function key"] = function(assert, done) { |
michael@0 | 14 | var element = winUtils.activeBrowserWindow.document.documentElement; |
michael@0 | 15 | var showHotKey = Hotkey({ |
michael@0 | 16 | combo: "f1", |
michael@0 | 17 | onPress: function() { |
michael@0 | 18 | assert.pass("first callback is called"); |
michael@0 | 19 | assert.equal(this, showHotKey, |
michael@0 | 20 | 'Context `this` in `onPress` should be the hotkey object'); |
michael@0 | 21 | keyDown(element, "f2"); |
michael@0 | 22 | showHotKey.destroy(); |
michael@0 | 23 | } |
michael@0 | 24 | }); |
michael@0 | 25 | |
michael@0 | 26 | var hideHotKey = Hotkey({ |
michael@0 | 27 | combo: "f2", |
michael@0 | 28 | onPress: function() { |
michael@0 | 29 | assert.pass("second callback is called"); |
michael@0 | 30 | hideHotKey.destroy(); |
michael@0 | 31 | done(); |
michael@0 | 32 | } |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | keyDown(element, "f1"); |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | exports["test hotkey: accel alt shift"] = function(assert, done) { |
michael@0 | 39 | var element = winUtils.activeBrowserWindow.document.documentElement; |
michael@0 | 40 | var showHotKey = Hotkey({ |
michael@0 | 41 | combo: "accel-shift-6", |
michael@0 | 42 | onPress: function() { |
michael@0 | 43 | assert.pass("first callback is called"); |
michael@0 | 44 | keyDown(element, "accel-alt-shift-6"); |
michael@0 | 45 | showHotKey.destroy(); |
michael@0 | 46 | } |
michael@0 | 47 | }); |
michael@0 | 48 | |
michael@0 | 49 | var hideHotKey = Hotkey({ |
michael@0 | 50 | combo: "accel-alt-shift-6", |
michael@0 | 51 | onPress: function() { |
michael@0 | 52 | assert.pass("second callback is called"); |
michael@0 | 53 | hideHotKey.destroy(); |
michael@0 | 54 | done(); |
michael@0 | 55 | } |
michael@0 | 56 | }); |
michael@0 | 57 | |
michael@0 | 58 | keyDown(element, "accel-shift-6"); |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | exports["test hotkey meta & control"] = function(assert, done) { |
michael@0 | 62 | var element = winUtils.activeBrowserWindow.document.documentElement; |
michael@0 | 63 | var showHotKey = Hotkey({ |
michael@0 | 64 | combo: "meta-3", |
michael@0 | 65 | onPress: function() { |
michael@0 | 66 | assert.pass("first callback is called"); |
michael@0 | 67 | keyDown(element, "alt-control-shift-b"); |
michael@0 | 68 | showHotKey.destroy(); |
michael@0 | 69 | } |
michael@0 | 70 | }); |
michael@0 | 71 | |
michael@0 | 72 | var hideHotKey = Hotkey({ |
michael@0 | 73 | combo: "Ctrl-Alt-Shift-B", |
michael@0 | 74 | onPress: function() { |
michael@0 | 75 | assert.pass("second callback is called"); |
michael@0 | 76 | hideHotKey.destroy(); |
michael@0 | 77 | done(); |
michael@0 | 78 | } |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | keyDown(element, "meta-3"); |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | exports["test hotkey: control-1 / meta--"] = function(assert, done) { |
michael@0 | 85 | var element = winUtils.activeBrowserWindow.document.documentElement; |
michael@0 | 86 | var showHotKey = Hotkey({ |
michael@0 | 87 | combo: "control-1", |
michael@0 | 88 | onPress: function() { |
michael@0 | 89 | assert.pass("first callback is called"); |
michael@0 | 90 | keyDown(element, "meta--"); |
michael@0 | 91 | showHotKey.destroy(); |
michael@0 | 92 | } |
michael@0 | 93 | }); |
michael@0 | 94 | |
michael@0 | 95 | var hideHotKey = Hotkey({ |
michael@0 | 96 | combo: "meta--", |
michael@0 | 97 | onPress: function() { |
michael@0 | 98 | assert.pass("second callback is called"); |
michael@0 | 99 | hideHotKey.destroy(); |
michael@0 | 100 | done(); |
michael@0 | 101 | } |
michael@0 | 102 | }); |
michael@0 | 103 | |
michael@0 | 104 | keyDown(element, "control-1"); |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | exports["test invalid combos"] = function(assert) { |
michael@0 | 108 | assert.throws(function() { |
michael@0 | 109 | Hotkey({ |
michael@0 | 110 | combo: "d", |
michael@0 | 111 | onPress: function() {} |
michael@0 | 112 | }); |
michael@0 | 113 | }, "throws if no modifier is present"); |
michael@0 | 114 | assert.throws(function() { |
michael@0 | 115 | Hotkey({ |
michael@0 | 116 | combo: "alt", |
michael@0 | 117 | onPress: function() {} |
michael@0 | 118 | }); |
michael@0 | 119 | }, "throws if no key is present"); |
michael@0 | 120 | assert.throws(function() { |
michael@0 | 121 | Hotkey({ |
michael@0 | 122 | combo: "alt p b", |
michael@0 | 123 | onPress: function() {} |
michael@0 | 124 | }); |
michael@0 | 125 | }, "throws if more then one key is present"); |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | exports["test no exception on unmodified keypress"] = function(assert) { |
michael@0 | 129 | var element = winUtils.activeBrowserWindow.document.documentElement; |
michael@0 | 130 | var someHotkey = Hotkey({ |
michael@0 | 131 | combo: "control-alt-1", |
michael@0 | 132 | onPress: function() { |
michael@0 | 133 | } |
michael@0 | 134 | }); |
michael@0 | 135 | keyDown(element, "a"); |
michael@0 | 136 | assert.pass("No exception throw, unmodified keypress passed"); |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | exports["test hotkey: automatic destroy"] = function(assert, done) { |
michael@0 | 140 | // Hacky way to be able to create unloadable modules via makeSandboxedLoader. |
michael@0 | 141 | let loader = Loader(module); |
michael@0 | 142 | |
michael@0 | 143 | var called = false; |
michael@0 | 144 | var element = loader.require("sdk/deprecated/window-utils").activeBrowserWindow.document.documentElement; |
michael@0 | 145 | var hotkey = loader.require("sdk/hotkeys").Hotkey({ |
michael@0 | 146 | combo: "accel-shift-x", |
michael@0 | 147 | onPress: function() { |
michael@0 | 148 | called = true; |
michael@0 | 149 | } |
michael@0 | 150 | }); |
michael@0 | 151 | |
michael@0 | 152 | // Unload the module so that previous hotkey is automatically destroyed |
michael@0 | 153 | loader.unload(); |
michael@0 | 154 | |
michael@0 | 155 | // Ensure that the hotkey is really destroyed |
michael@0 | 156 | keyDown(element, "accel-shift-x"); |
michael@0 | 157 | |
michael@0 | 158 | timer.setTimeout(function () { |
michael@0 | 159 | assert.ok(!called, "Hotkey is destroyed and not called."); |
michael@0 | 160 | done(); |
michael@0 | 161 | }, 0); |
michael@0 | 162 | }; |
michael@0 | 163 | |
michael@0 | 164 | require("test").run(exports); |