accessible/tests/mochitest/jsat/output.js

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

mercurial