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 | const Cu = Components.utils; |
michael@0 | 2 | const PREF_UTTERANCE_ORDER = "accessibility.accessfu.utterance"; |
michael@0 | 3 | |
michael@0 | 4 | Cu.import('resource://gre/modules/accessibility/Utils.jsm'); |
michael@0 | 5 | Cu.import("resource://gre/modules/accessibility/OutputGenerator.jsm", this); |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * Test context output generation. |
michael@0 | 9 | * |
michael@0 | 10 | * @param expected {Array} expected output. |
michael@0 | 11 | * @param aAccOrElmOrID identifier to get an accessible to test. |
michael@0 | 12 | * @param aOldAccOrElmOrID optional identifier to get an accessible relative to |
michael@0 | 13 | * the |aAccOrElmOrID|. |
michael@0 | 14 | * @param aGenerator the output generator to use when generating accessible |
michael@0 | 15 | * output |
michael@0 | 16 | * |
michael@0 | 17 | * Note: if |aOldAccOrElmOrID| is not provided, the |aAccOrElmOrID| must be |
michael@0 | 18 | * scoped to the "root" element in markup. |
michael@0 | 19 | */ |
michael@0 | 20 | function testContextOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, aGenerator) { |
michael@0 | 21 | var accessible = getAccessible(aAccOrElmOrID); |
michael@0 | 22 | var oldAccessible = aOldAccOrElmOrID !== null ? |
michael@0 | 23 | getAccessible(aOldAccOrElmOrID || 'root') : null; |
michael@0 | 24 | var context = new PivotContext(accessible, oldAccessible); |
michael@0 | 25 | var output = aGenerator.genForContext(context).output; |
michael@0 | 26 | |
michael@0 | 27 | // Create a version of the output that has null members where we have |
michael@0 | 28 | // null members in the expected output. Those are indexes that are not testable |
michael@0 | 29 | // because of the changing nature of the test (different window names), or strings |
michael@0 | 30 | // that are inaccessible to us, like the title of parent documents. |
michael@0 | 31 | var masked_output = []; |
michael@0 | 32 | for (var i=0; i < output.length; i++) { |
michael@0 | 33 | if (expected[i] === null) { |
michael@0 | 34 | masked_output.push(null); |
michael@0 | 35 | } else { |
michael@0 | 36 | masked_output[i] = output[i]; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | isDeeply(masked_output, expected, |
michael@0 | 41 | "Context output is correct for " + aAccOrElmOrID + |
michael@0 | 42 | " (output: " + output.join(", ") + ") ==" + |
michael@0 | 43 | " (expected: " + expected.join(", ") + ")"); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Test object output generated array that includes names. |
michael@0 | 48 | * Note: test ignores outputs without the name. |
michael@0 | 49 | * |
michael@0 | 50 | * @param aAccOrElmOrID identifier to get an accessible to test. |
michael@0 | 51 | * @param aGenerator the output generator to use when generating accessible |
michael@0 | 52 | * output |
michael@0 | 53 | */ |
michael@0 | 54 | function testObjectOutput(aAccOrElmOrID, aGenerator) { |
michael@0 | 55 | var accessible = getAccessible(aAccOrElmOrID); |
michael@0 | 56 | var context = new PivotContext(accessible); |
michael@0 | 57 | var output = aGenerator.genForObject(accessible, context); |
michael@0 | 58 | var outputOrder; |
michael@0 | 59 | try { |
michael@0 | 60 | outputOrder = SpecialPowers.getIntPref(PREF_UTTERANCE_ORDER); |
michael@0 | 61 | } catch (ex) { |
michael@0 | 62 | // PREF_UTTERANCE_ORDER not set. |
michael@0 | 63 | outputOrder = 0; |
michael@0 | 64 | } |
michael@0 | 65 | var expectedNameIndex = outputOrder === 0 ? output.length - 1 : 0; |
michael@0 | 66 | var nameIndex = output.indexOf(accessible.name); |
michael@0 | 67 | |
michael@0 | 68 | if (nameIndex > -1) { |
michael@0 | 69 | ok(output.indexOf(accessible.name) === expectedNameIndex, |
michael@0 | 70 | "Object output is correct for " + aAccOrElmOrID); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | /** |
michael@0 | 75 | * Test object and context output for an accessible. |
michael@0 | 76 | * |
michael@0 | 77 | * @param expected {Array} expected output. |
michael@0 | 78 | * @param aAccOrElmOrID identifier to get an accessible to test. |
michael@0 | 79 | * @param aOldAccOrElmOrID optional identifier to get an accessible relative to |
michael@0 | 80 | * the |aAccOrElmOrID|. |
michael@0 | 81 | * @param aOutputKind the type of output |
michael@0 | 82 | */ |
michael@0 | 83 | function testOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, aOutputKind) { |
michael@0 | 84 | var generator; |
michael@0 | 85 | if (aOutputKind === 1) { |
michael@0 | 86 | generator = UtteranceGenerator; |
michael@0 | 87 | } else { |
michael@0 | 88 | generator = BrailleGenerator; |
michael@0 | 89 | } |
michael@0 | 90 | testContextOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, generator); |
michael@0 | 91 | // Just need to test object output for individual |
michael@0 | 92 | // accOrElmOrID. |
michael@0 | 93 | if (aOldAccOrElmOrID) { |
michael@0 | 94 | return; |
michael@0 | 95 | } |
michael@0 | 96 | testObjectOutput(aAccOrElmOrID, generator); |
michael@0 | 97 | } |