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 | * Perform all editable text tests. |
michael@0 | 3 | */ |
michael@0 | 4 | function editableTextTestRun() |
michael@0 | 5 | { |
michael@0 | 6 | this.add = function add(aTest) |
michael@0 | 7 | { |
michael@0 | 8 | this.seq.push(aTest); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | this.run = function run() |
michael@0 | 12 | { |
michael@0 | 13 | this.iterate(); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | this.index = 0; |
michael@0 | 17 | this.seq = new Array(); |
michael@0 | 18 | |
michael@0 | 19 | this.iterate = function iterate() |
michael@0 | 20 | { |
michael@0 | 21 | if (this.index < this.seq.length) { |
michael@0 | 22 | this.seq[this.index++].startTest(this); |
michael@0 | 23 | return; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | this.seq = null; |
michael@0 | 27 | SimpleTest.finish(); |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Used to test nsIEditableTextAccessible methods. |
michael@0 | 33 | */ |
michael@0 | 34 | function editableTextTest(aID) |
michael@0 | 35 | { |
michael@0 | 36 | /** |
michael@0 | 37 | * Schedule a test, the given function with its arguments will be executed |
michael@0 | 38 | * when preceding test is complete. |
michael@0 | 39 | */ |
michael@0 | 40 | this.scheduleTest = function scheduleTest(aFunc) |
michael@0 | 41 | { |
michael@0 | 42 | // A data container acts like a dummy invoker, it's never invoked but |
michael@0 | 43 | // it's used to generate real invoker when previous invoker was handled. |
michael@0 | 44 | var dataContainer = { |
michael@0 | 45 | func: aFunc, |
michael@0 | 46 | funcArgs: Array.slice(arguments, 1) |
michael@0 | 47 | }; |
michael@0 | 48 | this.mEventQueue.push(dataContainer); |
michael@0 | 49 | |
michael@0 | 50 | if (!this.mEventQueueReady) { |
michael@0 | 51 | this.unwrapNextTest(); |
michael@0 | 52 | this.mEventQueueReady = true; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | /** |
michael@0 | 57 | * setTextContents test. |
michael@0 | 58 | */ |
michael@0 | 59 | this.setTextContents = function setTextContents(aValue) |
michael@0 | 60 | { |
michael@0 | 61 | var testID = "setTextContents '" + aValue + "' for " + prettyName(aID); |
michael@0 | 62 | |
michael@0 | 63 | function setTextContentsInvoke() |
michael@0 | 64 | { |
michael@0 | 65 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 66 | acc.setTextContents(aValue); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | var insertTripple = aValue ? [0, aValue.length, aValue] : null; |
michael@0 | 70 | var oldValue = getValue(aID); |
michael@0 | 71 | var removeTripple = oldValue ? [0, oldValue.length, oldValue] : null; |
michael@0 | 72 | |
michael@0 | 73 | this.generateTest(aID, removeTripple, insertTripple, setTextContentsInvoke, |
michael@0 | 74 | getValueChecker(aID, aValue), testID); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * insertText test. |
michael@0 | 79 | */ |
michael@0 | 80 | this.insertText = function insertText(aStr, aPos, aResStr, aResPos) |
michael@0 | 81 | { |
michael@0 | 82 | var testID = "insertText '" + aStr + "' at " + aPos + " for " + |
michael@0 | 83 | prettyName(aID); |
michael@0 | 84 | |
michael@0 | 85 | function insertTextInvoke() |
michael@0 | 86 | { |
michael@0 | 87 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 88 | acc.insertText(aStr, aPos); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | var resPos = (aResPos != undefined) ? aResPos : aPos; |
michael@0 | 92 | this.generateTest(aID, null, [resPos, resPos + aStr.length, aStr], |
michael@0 | 93 | insertTextInvoke, getValueChecker(aID, aResStr), testID); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * copyText test. |
michael@0 | 98 | */ |
michael@0 | 99 | this.copyText = function copyText(aStartPos, aEndPos, aClipboardStr) |
michael@0 | 100 | { |
michael@0 | 101 | var testID = "copyText from " + aStartPos + " to " + aEndPos + " for " + |
michael@0 | 102 | prettyName(aID); |
michael@0 | 103 | |
michael@0 | 104 | function copyTextInvoke() |
michael@0 | 105 | { |
michael@0 | 106 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 107 | acc.copyText(aStartPos, aEndPos); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | this.generateTest(aID, null, null, copyTextInvoke, |
michael@0 | 111 | getClipboardChecker(aID, aClipboardStr), testID); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * copyText and pasteText test. |
michael@0 | 116 | */ |
michael@0 | 117 | this.copyNPasteText = function copyNPasteText(aStartPos, aEndPos, |
michael@0 | 118 | aPos, aResStr) |
michael@0 | 119 | { |
michael@0 | 120 | var testID = "copyText from " + aStartPos + " to " + aEndPos + |
michael@0 | 121 | "and pasteText at " + aPos + " for " + prettyName(aID); |
michael@0 | 122 | |
michael@0 | 123 | function copyNPasteTextInvoke() |
michael@0 | 124 | { |
michael@0 | 125 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 126 | acc.copyText(aStartPos, aEndPos); |
michael@0 | 127 | acc.pasteText(aPos); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | this.generateTest(aID, null, [aStartPos, aEndPos, getTextFromClipboard], |
michael@0 | 131 | copyNPasteInvoke, getValueChecker(aID, aResStr), testID); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * cutText test. |
michael@0 | 136 | */ |
michael@0 | 137 | this.cutText = function cutText(aStartPos, aEndPos, aResStr, |
michael@0 | 138 | aResStartPos, aResEndPos) |
michael@0 | 139 | { |
michael@0 | 140 | var testID = "cutText from " + aStartPos + " to " + aEndPos + " for " + |
michael@0 | 141 | prettyName(aID); |
michael@0 | 142 | |
michael@0 | 143 | function cutTextInvoke() |
michael@0 | 144 | { |
michael@0 | 145 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 146 | acc.cutText(aStartPos, aEndPos); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | var resStartPos = (aResStartPos != undefined) ? aResStartPos : aStartPos; |
michael@0 | 150 | var resEndPos = (aResEndPos != undefined) ? aResEndPos : aEndPos; |
michael@0 | 151 | this.generateTest(aID, [resStartPos, resEndPos, getTextFromClipboard], null, |
michael@0 | 152 | cutTextInvoke, getValueChecker(aID, aResStr), testID); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | /** |
michael@0 | 156 | * cutText and pasteText test. |
michael@0 | 157 | */ |
michael@0 | 158 | this.cutNPasteText = function copyNPasteText(aStartPos, aEndPos, |
michael@0 | 159 | aPos, aResStr) |
michael@0 | 160 | { |
michael@0 | 161 | var testID = "cutText from " + aStartPos + " to " + aEndPos + |
michael@0 | 162 | " and pasteText at " + aPos + " for " + prettyName(aID); |
michael@0 | 163 | |
michael@0 | 164 | function cutNPasteTextInvoke() |
michael@0 | 165 | { |
michael@0 | 166 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 167 | acc.cutText(aStartPos, aEndPos); |
michael@0 | 168 | acc.pasteText(aPos); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | this.generateTest(aID, [aStartPos, aEndPos, getTextFromClipboard], |
michael@0 | 172 | [aPos, -1, getTextFromClipboard], |
michael@0 | 173 | cutNPasteTextInvoke, getValueChecker(aID, aResStr), |
michael@0 | 174 | testID); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | /** |
michael@0 | 178 | * pasteText test. |
michael@0 | 179 | */ |
michael@0 | 180 | this.pasteText = function pasteText(aPos, aResStr) |
michael@0 | 181 | { |
michael@0 | 182 | var testID = "pasteText at " + aPos + " for " + prettyName(aID); |
michael@0 | 183 | |
michael@0 | 184 | function pasteTextInvoke() |
michael@0 | 185 | { |
michael@0 | 186 | var acc = getAccessible(aID, nsIAccessibleEditableText); |
michael@0 | 187 | acc.pasteText(aPos); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | this.generateTest(aID, null, [aPos, -1, getTextFromClipboard], |
michael@0 | 191 | pasteTextInvoke, getValueChecker(aID, aResStr), testID); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | /** |
michael@0 | 195 | * deleteText test. |
michael@0 | 196 | */ |
michael@0 | 197 | this.deleteText = function deleteText(aStartPos, aEndPos, aResStr) |
michael@0 | 198 | { |
michael@0 | 199 | var testID = "deleteText from " + aStartPos + " to " + aEndPos + |
michael@0 | 200 | " for " + prettyName(aID); |
michael@0 | 201 | |
michael@0 | 202 | var oldValue = getValue(aID).substring(aStartPos, aEndPos); |
michael@0 | 203 | var removeTripple = oldValue ? [aStartPos, aEndPos, oldValue] : null; |
michael@0 | 204 | |
michael@0 | 205 | function deleteTextInvoke() |
michael@0 | 206 | { |
michael@0 | 207 | var acc = getAccessible(aID, [nsIAccessibleEditableText]); |
michael@0 | 208 | acc.deleteText(aStartPos, aEndPos); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | this.generateTest(aID, removeTripple, null, deleteTextInvoke, |
michael@0 | 212 | getValueChecker(aID, aResStr), testID); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 216 | // Implementation details. |
michael@0 | 217 | |
michael@0 | 218 | function getValue(aID) |
michael@0 | 219 | { |
michael@0 | 220 | var value = ""; |
michael@0 | 221 | var elm = getNode(aID); |
michael@0 | 222 | if (elm instanceof Components.interfaces.nsIDOMNSEditableElement) |
michael@0 | 223 | return elm.value; |
michael@0 | 224 | |
michael@0 | 225 | if (elm instanceof Components.interfaces.nsIDOMHTMLDocument) |
michael@0 | 226 | return elm.body.textContent; |
michael@0 | 227 | |
michael@0 | 228 | return elm.textContent; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | /** |
michael@0 | 232 | * Common checkers. |
michael@0 | 233 | */ |
michael@0 | 234 | function getValueChecker(aID, aValue) |
michael@0 | 235 | { |
michael@0 | 236 | var checker = { |
michael@0 | 237 | check: function valueChecker_check() |
michael@0 | 238 | { |
michael@0 | 239 | is(getValue(aID), aValue, "Wrong value " + aValue); |
michael@0 | 240 | } |
michael@0 | 241 | }; |
michael@0 | 242 | return checker; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | function getClipboardChecker(aID, aText) |
michael@0 | 246 | { |
michael@0 | 247 | var checker = { |
michael@0 | 248 | check: function clipboardChecker_check() |
michael@0 | 249 | { |
michael@0 | 250 | is(getTextFromClipboard(), aText, "Wrong text in clipboard."); |
michael@0 | 251 | } |
michael@0 | 252 | }; |
michael@0 | 253 | return checker; |
michael@0 | 254 | } |
michael@0 | 255 | |
michael@0 | 256 | function getValueNClipboardChecker(aID, aValue, aText) |
michael@0 | 257 | { |
michael@0 | 258 | var valueChecker = getValueChecker(aID, aValue); |
michael@0 | 259 | var clipboardChecker = getClipboardChecker(aID, aText); |
michael@0 | 260 | |
michael@0 | 261 | var checker = { |
michael@0 | 262 | check: function() |
michael@0 | 263 | { |
michael@0 | 264 | valueChecker.check(); |
michael@0 | 265 | clipboardChecker.check(); |
michael@0 | 266 | } |
michael@0 | 267 | }; |
michael@0 | 268 | return checker; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | /** |
michael@0 | 272 | * Process next scheduled test. |
michael@0 | 273 | */ |
michael@0 | 274 | this.unwrapNextTest = function unwrapNextTest() |
michael@0 | 275 | { |
michael@0 | 276 | var data = this.mEventQueue.mInvokers[this.mEventQueue.mIndex + 1]; |
michael@0 | 277 | if (data) |
michael@0 | 278 | data.func.apply(this, data.funcArgs); |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | /** |
michael@0 | 282 | * Used to generate an invoker object for the sheduled test. |
michael@0 | 283 | */ |
michael@0 | 284 | this.generateTest = function generateTest(aID, aRemoveTriple, aInsertTriple, |
michael@0 | 285 | aInvokeFunc, aChecker, aInvokerID) |
michael@0 | 286 | { |
michael@0 | 287 | var et = this; |
michael@0 | 288 | var invoker = { |
michael@0 | 289 | eventSeq: [], |
michael@0 | 290 | |
michael@0 | 291 | invoke: aInvokeFunc, |
michael@0 | 292 | finalCheck: function finalCheck() |
michael@0 | 293 | { |
michael@0 | 294 | aChecker.check(); |
michael@0 | 295 | et.unwrapNextTest(); // replace dummy invoker on real invoker object. |
michael@0 | 296 | }, |
michael@0 | 297 | getID: function getID() { return aInvokerID; } |
michael@0 | 298 | }; |
michael@0 | 299 | |
michael@0 | 300 | if (aRemoveTriple) { |
michael@0 | 301 | var checker = new textChangeChecker(aID, aRemoveTriple[0], |
michael@0 | 302 | aRemoveTriple[1], aRemoveTriple[2], |
michael@0 | 303 | false); |
michael@0 | 304 | invoker.eventSeq.push(checker); |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | if (aInsertTriple) { |
michael@0 | 308 | var checker = new textChangeChecker(aID, aInsertTriple[0], |
michael@0 | 309 | aInsertTriple[1], aInsertTriple[2], |
michael@0 | 310 | true); |
michael@0 | 311 | invoker.eventSeq.push(checker); |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | // Claim that we don't want to fail when no events are expected. |
michael@0 | 315 | if (!aRemoveTriple && !aInsertTriple) |
michael@0 | 316 | invoker.noEventsOnAction = true; |
michael@0 | 317 | |
michael@0 | 318 | this.mEventQueue.mInvokers[this.mEventQueue.mIndex + 1] = invoker; |
michael@0 | 319 | } |
michael@0 | 320 | |
michael@0 | 321 | /** |
michael@0 | 322 | * Run the tests. |
michael@0 | 323 | */ |
michael@0 | 324 | this.startTest = function startTest(aTestRun) |
michael@0 | 325 | { |
michael@0 | 326 | var testRunObj = aTestRun; |
michael@0 | 327 | var thisObj = this; |
michael@0 | 328 | this.mEventQueue.onFinish = function finishCallback() |
michael@0 | 329 | { |
michael@0 | 330 | // Notify textRun object that all tests were finished. |
michael@0 | 331 | testRunObj.iterate(); |
michael@0 | 332 | |
michael@0 | 333 | // Help GC to avoid leaks (refer to aTestRun from local variable, drop |
michael@0 | 334 | // onFinish function). |
michael@0 | 335 | thisObj.mEventQueue.onFinish = null; |
michael@0 | 336 | |
michael@0 | 337 | return DO_NOT_FINISH_TEST; |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | this.mEventQueue.invoke(); |
michael@0 | 341 | } |
michael@0 | 342 | |
michael@0 | 343 | this.mEventQueue = new eventQueue(); |
michael@0 | 344 | this.mEventQueueReady = false; |
michael@0 | 345 | } |
michael@0 | 346 |