Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 2 | // Event constants |
michael@0 | 3 | |
michael@0 | 4 | const MOUSEDOWN_EVENT = 1; |
michael@0 | 5 | const MOUSEUP_EVENT = 2; |
michael@0 | 6 | const CLICK_EVENT = 4; |
michael@0 | 7 | const COMMAND_EVENT = 8; |
michael@0 | 8 | const FOCUS_EVENT = 16; |
michael@0 | 9 | |
michael@0 | 10 | const CLICK_EVENTS = MOUSEDOWN_EVENT | MOUSEUP_EVENT | CLICK_EVENT; |
michael@0 | 11 | const XUL_EVENTS = CLICK_EVENTS | COMMAND_EVENT; |
michael@0 | 12 | |
michael@0 | 13 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 14 | // Public functions |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * Test default accessible actions. |
michael@0 | 18 | * |
michael@0 | 19 | * Action tester interface is: |
michael@0 | 20 | * |
michael@0 | 21 | * var actionObj = { |
michael@0 | 22 | * // identifier of accessible to perform an action on |
michael@0 | 23 | * get ID() {}, |
michael@0 | 24 | * |
michael@0 | 25 | * // index of the action |
michael@0 | 26 | * get actionIndex() {}, |
michael@0 | 27 | * |
michael@0 | 28 | * // name of the action |
michael@0 | 29 | * get actionName() {}, |
michael@0 | 30 | * |
michael@0 | 31 | * // DOM events (see constants defined above) |
michael@0 | 32 | * get events() {}, |
michael@0 | 33 | * |
michael@0 | 34 | * // [optional] identifier of target DOM events listeners are registered on, |
michael@0 | 35 | * // used with 'events', if missing then 'ID' is used instead. |
michael@0 | 36 | * get targetID() {}, |
michael@0 | 37 | * |
michael@0 | 38 | * // [optional] perform checks when 'click' event is handled if 'events' |
michael@0 | 39 | * // is used. |
michael@0 | 40 | * checkOnClickEvent: function() {}, |
michael@0 | 41 | * |
michael@0 | 42 | * // [optional] an array of invoker's checker objects (see eventQueue |
michael@0 | 43 | * // constructor events.js) |
michael@0 | 44 | * get eventSeq() {} |
michael@0 | 45 | * }; |
michael@0 | 46 | * |
michael@0 | 47 | * |
michael@0 | 48 | * @param aArray [in] an array of action cheker objects |
michael@0 | 49 | */ |
michael@0 | 50 | function testActions(aArray) |
michael@0 | 51 | { |
michael@0 | 52 | gActionsQueue = new eventQueue(); |
michael@0 | 53 | |
michael@0 | 54 | for (var idx = 0; idx < aArray.length; idx++) { |
michael@0 | 55 | |
michael@0 | 56 | var actionObj = aArray[idx]; |
michael@0 | 57 | var accOrElmOrID = actionObj.ID; |
michael@0 | 58 | var actionIndex = actionObj.actionIndex; |
michael@0 | 59 | var actionName = actionObj.actionName; |
michael@0 | 60 | var events = actionObj.events; |
michael@0 | 61 | var accOrElmOrIDOfTarget = actionObj.targetID ? |
michael@0 | 62 | actionObj.targetID : accOrElmOrID; |
michael@0 | 63 | |
michael@0 | 64 | var eventSeq = new Array(); |
michael@0 | 65 | if (events) { |
michael@0 | 66 | var elm = getNode(accOrElmOrIDOfTarget); |
michael@0 | 67 | if (events & MOUSEDOWN_EVENT) |
michael@0 | 68 | eventSeq.push(new checkerOfActionInvoker("mousedown", elm)); |
michael@0 | 69 | |
michael@0 | 70 | if (events & MOUSEUP_EVENT) |
michael@0 | 71 | eventSeq.push(new checkerOfActionInvoker("mouseup", elm)); |
michael@0 | 72 | |
michael@0 | 73 | if (events & CLICK_EVENT) |
michael@0 | 74 | eventSeq.push(new checkerOfActionInvoker("click", elm, actionObj)); |
michael@0 | 75 | |
michael@0 | 76 | if (events & COMMAND_EVENT) |
michael@0 | 77 | eventSeq.push(new checkerOfActionInvoker("command", elm)); |
michael@0 | 78 | |
michael@0 | 79 | if (events & FOCUS_EVENT) |
michael@0 | 80 | eventSeq.push(new focusChecker(elm)); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | if (actionObj.eventSeq) |
michael@0 | 84 | eventSeq = eventSeq.concat(actionObj.eventSeq); |
michael@0 | 85 | |
michael@0 | 86 | var invoker = new actionInvoker(accOrElmOrID, actionIndex, actionName, |
michael@0 | 87 | eventSeq); |
michael@0 | 88 | gActionsQueue.push(invoker); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | gActionsQueue.invoke(); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Test action names and descriptions. |
michael@0 | 96 | */ |
michael@0 | 97 | function testActionNames(aID, aActions) |
michael@0 | 98 | { |
michael@0 | 99 | var actions = (typeof aActions == "string") ? |
michael@0 | 100 | [ aActions ] : (aActions || []); |
michael@0 | 101 | |
michael@0 | 102 | var acc = getAccessible(aID); |
michael@0 | 103 | is(acc.actionCount, actions.length, "Wong number of actions."); |
michael@0 | 104 | for (var i = 0; i < actions.length; i++ ) { |
michael@0 | 105 | is(acc.getActionName(i), actions[i], "Wrong action name at " + i + " index."); |
michael@0 | 106 | is(acc.getActionDescription(0), gActionDescrMap[actions[i]], |
michael@0 | 107 | "Wrong action description at " + i + "index."); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 112 | // Private |
michael@0 | 113 | |
michael@0 | 114 | var gActionsQueue = null; |
michael@0 | 115 | |
michael@0 | 116 | function actionInvoker(aAccOrElmOrId, aActionIndex, aActionName, aEventSeq) |
michael@0 | 117 | { |
michael@0 | 118 | this.invoke = function actionInvoker_invoke() |
michael@0 | 119 | { |
michael@0 | 120 | var acc = getAccessible(aAccOrElmOrId); |
michael@0 | 121 | if (!acc) |
michael@0 | 122 | return INVOKER_ACTION_FAILED; |
michael@0 | 123 | |
michael@0 | 124 | var isThereActions = acc.actionCount > 0; |
michael@0 | 125 | ok(isThereActions, |
michael@0 | 126 | "No actions on the accessible for " + prettyName(aAccOrElmOrId)); |
michael@0 | 127 | |
michael@0 | 128 | if (!isThereActions) |
michael@0 | 129 | return INVOKER_ACTION_FAILED; |
michael@0 | 130 | |
michael@0 | 131 | is(acc.getActionName(aActionIndex), aActionName, |
michael@0 | 132 | "Wrong action name of the accessible for " + prettyName(aAccOrElmOrId)); |
michael@0 | 133 | |
michael@0 | 134 | try { |
michael@0 | 135 | acc.doAction(aActionIndex); |
michael@0 | 136 | } |
michael@0 | 137 | catch (e){ |
michael@0 | 138 | ok(false, "doAction(" + aActionIndex + ") failed with: " + e.name); |
michael@0 | 139 | return INVOKER_ACTION_FAILED; |
michael@0 | 140 | } |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | this.eventSeq = aEventSeq; |
michael@0 | 144 | |
michael@0 | 145 | this.getID = function actionInvoker_getID() |
michael@0 | 146 | { |
michael@0 | 147 | return "invoke an action " + aActionName + " at index " + aActionIndex + |
michael@0 | 148 | " on " + prettyName(aAccOrElmOrId); |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | function checkerOfActionInvoker(aType, aTarget, aActionObj) |
michael@0 | 153 | { |
michael@0 | 154 | this.type = aType; |
michael@0 | 155 | |
michael@0 | 156 | this.target = aTarget; |
michael@0 | 157 | |
michael@0 | 158 | this.phase = false; |
michael@0 | 159 | |
michael@0 | 160 | this.getID = function getID() |
michael@0 | 161 | { |
michael@0 | 162 | return aType + " event handling"; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | this.check = function check(aEvent) |
michael@0 | 166 | { |
michael@0 | 167 | if (aActionObj && "checkOnClickEvent" in aActionObj) |
michael@0 | 168 | aActionObj.checkOnClickEvent(aEvent); |
michael@0 | 169 | } |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | var gActionDescrMap = |
michael@0 | 173 | { |
michael@0 | 174 | jump: "Jump", |
michael@0 | 175 | press: "Press", |
michael@0 | 176 | check: "Check", |
michael@0 | 177 | uncheck: "Uncheck", |
michael@0 | 178 | select: "Select", |
michael@0 | 179 | open: "Open", |
michael@0 | 180 | close: "Close", |
michael@0 | 181 | switch: "Switch", |
michael@0 | 182 | click: "Click", |
michael@0 | 183 | collapse: "Collapse", |
michael@0 | 184 | expand: "Expand", |
michael@0 | 185 | activate: "Activate", |
michael@0 | 186 | cycle: "Cycle" |
michael@0 | 187 | }; |