michael@0: const Cu = Components.utils; michael@0: const PREF_UTTERANCE_ORDER = "accessibility.accessfu.utterance"; michael@0: michael@0: Cu.import('resource://gre/modules/accessibility/Utils.jsm'); michael@0: Cu.import("resource://gre/modules/accessibility/OutputGenerator.jsm", this); michael@0: michael@0: /** michael@0: * Test context output generation. michael@0: * michael@0: * @param expected {Array} expected output. michael@0: * @param aAccOrElmOrID identifier to get an accessible to test. michael@0: * @param aOldAccOrElmOrID optional identifier to get an accessible relative to michael@0: * the |aAccOrElmOrID|. michael@0: * @param aGenerator the output generator to use when generating accessible michael@0: * output michael@0: * michael@0: * Note: if |aOldAccOrElmOrID| is not provided, the |aAccOrElmOrID| must be michael@0: * scoped to the "root" element in markup. michael@0: */ michael@0: function testContextOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, aGenerator) { michael@0: var accessible = getAccessible(aAccOrElmOrID); michael@0: var oldAccessible = aOldAccOrElmOrID !== null ? michael@0: getAccessible(aOldAccOrElmOrID || 'root') : null; michael@0: var context = new PivotContext(accessible, oldAccessible); michael@0: var output = aGenerator.genForContext(context).output; michael@0: michael@0: // Create a version of the output that has null members where we have michael@0: // null members in the expected output. Those are indexes that are not testable michael@0: // because of the changing nature of the test (different window names), or strings michael@0: // that are inaccessible to us, like the title of parent documents. michael@0: var masked_output = []; michael@0: for (var i=0; i < output.length; i++) { michael@0: if (expected[i] === null) { michael@0: masked_output.push(null); michael@0: } else { michael@0: masked_output[i] = output[i]; michael@0: } michael@0: } michael@0: michael@0: isDeeply(masked_output, expected, michael@0: "Context output is correct for " + aAccOrElmOrID + michael@0: " (output: " + output.join(", ") + ") ==" + michael@0: " (expected: " + expected.join(", ") + ")"); michael@0: } michael@0: michael@0: /** michael@0: * Test object output generated array that includes names. michael@0: * Note: test ignores outputs without the name. michael@0: * michael@0: * @param aAccOrElmOrID identifier to get an accessible to test. michael@0: * @param aGenerator the output generator to use when generating accessible michael@0: * output michael@0: */ michael@0: function testObjectOutput(aAccOrElmOrID, aGenerator) { michael@0: var accessible = getAccessible(aAccOrElmOrID); michael@0: var context = new PivotContext(accessible); michael@0: var output = aGenerator.genForObject(accessible, context); michael@0: var outputOrder; michael@0: try { michael@0: outputOrder = SpecialPowers.getIntPref(PREF_UTTERANCE_ORDER); michael@0: } catch (ex) { michael@0: // PREF_UTTERANCE_ORDER not set. michael@0: outputOrder = 0; michael@0: } michael@0: var expectedNameIndex = outputOrder === 0 ? output.length - 1 : 0; michael@0: var nameIndex = output.indexOf(accessible.name); michael@0: michael@0: if (nameIndex > -1) { michael@0: ok(output.indexOf(accessible.name) === expectedNameIndex, michael@0: "Object output is correct for " + aAccOrElmOrID); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Test object and context output for an accessible. michael@0: * michael@0: * @param expected {Array} expected output. michael@0: * @param aAccOrElmOrID identifier to get an accessible to test. michael@0: * @param aOldAccOrElmOrID optional identifier to get an accessible relative to michael@0: * the |aAccOrElmOrID|. michael@0: * @param aOutputKind the type of output michael@0: */ michael@0: function testOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, aOutputKind) { michael@0: var generator; michael@0: if (aOutputKind === 1) { michael@0: generator = UtteranceGenerator; michael@0: } else { michael@0: generator = BrailleGenerator; michael@0: } michael@0: testContextOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, generator); michael@0: // Just need to test object output for individual michael@0: // accOrElmOrID. michael@0: if (aOldAccOrElmOrID) { michael@0: return; michael@0: } michael@0: testObjectOutput(aAccOrElmOrID, generator); michael@0: }