Bug 845870 - [AccessFu] Tests for utterance name generation from explicit name vs subtree utterance. r=eeejay r=marcoz

This commit is contained in:
Yura Zenevich 2013-05-28 10:51:45 -07:00
Родитель bca30d2884
Коммит 510da6f3cf
4 изменённых файлов: 258 добавлений и 70 удалений

Просмотреть файл

@ -13,7 +13,9 @@ include $(DEPTH)/config/autoconf.mk
MOCHITEST_A11Y_FILES =\
jsatcommon.js \
utterance.js \
test_alive.html \
test_explicit_names.html \
test_utterance_order.html \
$(NULL)

Просмотреть файл

@ -0,0 +1,154 @@
<html>
<head>
<title>[AccessFu] Trust explicitly associated names when speaking certain elements</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="utterance.js"></script>
<script type="application/javascript">
function doTest() {
// Test the following accOrElmOrID.
var tests = [{
accOrElmOrID: "anchor1",
expected: ["link", "title"]
}, {
accOrElmOrID: "anchor2",
expected: ["link", "This is a link"]
}, {
accOrElmOrID: "button1",
expected: ["button", "Press me"]
}, {
accOrElmOrID: "button2",
expected: ["button", "Press me"]
}, {
accOrElmOrID: "textarea1",
expected: ["text area", "Test Text Area", "This is the text area text."]
}, {
accOrElmOrID: "textarea2",
expected: ["text area", "This is the text area text."]
}, {
accOrElmOrID: "heading1",
expected: ["heading level 1", "Test heading", "This is the heading."]
}, {
accOrElmOrID: "heading2",
expected: ["heading level 1", "This is the heading."]
}, {
accOrElmOrID: "list",
expected: ["list 2 items", "Test List", "First item", "Top of the list",
"1. ", "list one", "Last item", "2. ", "list two"]
}, {
accOrElmOrID: "dlist",
expected: ["definition list 0.5 items", "Test Definition List", "dd one "]
}, {
accOrElmOrID: "li_one",
expected: ["list 2 items", "Test List", "First item", "Top of the list"]
}, {
accOrElmOrID: "li_two",
expected: ["list 2 items", "Test List", "Last item", "2. ", "list two"]
}, {
accOrElmOrID: "cell",
expected: ["table", "Fruits and vegetables", "List of Fruits",
"list 4 items","First item", " ", "link", "Apples", " ", "link",
"Bananas", " ", "link", "Peaches", "Last item", " ", "link", "Plums"]
}, {
accOrElmOrID: "app.net",
expected: ["list 2 items", "First item", " ", "link", "star",
"Last item", " ", "link", "repost"]
}, {
// Test pivot to list from li_one.
accOrElmOrID: "list",
oldAccOrElmOrID: "li_one",
expected: ["list 2 items", "Test List", "First item", "Top of the list",
"1. ", "list one", "Last item", "2. ", "list two"]
}, {
// Test pivot to li_one from list.
accOrElmOrID: "li_one",
oldAccOrElmOrID: "list",
expected: ["list 2 items", "Test List", "First item", "Top of the list"]
}, {
// Test pivot to "apples" link from the table cell.
accOrElmOrID: "apples",
oldAccOrElmOrID: "cell",
expected: ["List of Fruits", "list 4 items", "First item", "link",
"Apples"]
}, {
// Test pivot to the table cell from the "apples" link.
accOrElmOrID: "cell",
oldAccOrElmOrID: "apples",
expected: ["List of Fruits", "list 4 items", "First item", " ", "link",
"Apples", " ", "link", "Bananas", " ", "link", "Peaches", "Last item",
" ", "link", "Plums"]
}];
// Test various explicit names vs the utterance generated from subtrees.
tests.forEach(function run(test) {
testUtterance(test.expected, test.accOrElmOrID, test.oldAccOrElmOrID);
});
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<div id="root">
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=845870"
title="[AccessFu] Trust explicitly associated names when speaking certain elements">
Mozilla Bug 845870
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<button id="button1" aria-label="Press me">This is not a name</button>
<button id="button2">Press me</button>
<a id="anchor1" href="#test" title="title"></a>
<a id="anchor2" href="#test">This is a link</a>
<textarea id="textarea1" title="Test Text Area" cols="80" rows="5">This is the text area text.</textarea>
<textarea id="textarea2" cols="80" rows="5">This is the text area text.</textarea>
<h1 id="heading1" title="Test heading">This is the heading.</h1>
<h1 id="heading2">This is the heading.</h1>
<ol id="list" title="Test List">
<li id="li_one" aria-label="Top of the list">list one</li>
<li id="li_two">list two</li>
</ol>
<dl id="dlist" title="Test Definition List">
<dd id="dd_one">dd one</li>
</dl>
<table>
<caption>Fruits and vegetables</caption>
<tr>
<td id="cell" aria-label="List of Fruits">
<ul style="list-style-type: none;">
<li><a id="apples" href="#">Apples</a></li>
<li><a id="bananas" href="#">Bananas</a></li>
<li><a href="#">Peaches</a></li>
<li><a href="#">Plums</a></li>
</ul>
</td>
</tr>
</table>
<!-- app.net -->
<ul id="app.net" class="unstyled ul-horizontal yui3-u fixed-right ta-right" style="list-style-type: none;">
<li class="yui3-u">
<a href="#star" data-starred="0" data-star-button="1" data-post-id="5098826">
<i aria-label="star" class="icon-star-empty"></i>
</a>
</li>
<li class="yui3-u repost">
<a href="#repost" title="repost" data-repost-button="1" data-reposted="0" data-post-id="5098826">
<i aria-label="repost" class="icon-repost"></i>
</a>
</li>
</ul>
</div>
</body>
</html>

Просмотреть файл

@ -12,82 +12,50 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=753984
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="./utterance.js"></script>
<script type="application/javascript">
const Cu = Components.utils;
const PREF_UTTERANCE_ORDER = "accessibility.accessfu.utterance";
Cu.import('resource://gre/modules/accessibility/Utils.jsm');
Cu.import("resource://gre/modules/accessibility/UtteranceGenerator.jsm",
this);
// Test UtteranceGenerator.genForContext utterance order for
// a particular accessible context with an optional old accessible.
function testContextUtterance(expected, aAccOrElmOrID, oldAAccOrElmOrID) {
oldAAccOrElmOrID = oldAAccOrElmOrID || "root";
var accessible = getAccessible(aAccOrElmOrID);
var oldAccessible = getAccessible(oldAAccOrElmOrID);
var context = new PivotContext(accessible, oldAccessible);
var utterance = UtteranceGenerator.genForContext(context);
isDeeply(utterance, expected,
"Utterance order is correct for " + aAccOrElmOrID);
}
// Test UtteranceGenerator.genForObject for a particular aAccOrElmOrID.
function testUtterance(utteranceOrder, aAccOrElmOrID) {
var accessible = getAccessible(aAccOrElmOrID);
var utterance = UtteranceGenerator.genForObject(accessible);
var expectedNameIndex = utteranceOrder === 0 ? utterance.length - 1 : 0;
if (aAccOrElmOrID === "li_one" || aAccOrElmOrID === "cell") {
// List item's and table cell's name is not included into an object
// utterance.
expectedNameIndex = -1;
}
ok(utterance.indexOf(accessible.name) === expectedNameIndex,
"Object utterance is correct for " + aAccOrElmOrID);
}
function doTest() {
// Test the following aAccOrElmOrID (with optional old aAccOrElmOrID).
// Note: each aAccOrElmOrID entry maps to a unique object utterance
// Test the following accOrElmOrID (with optional old accOrElmOrID).
// Note: each accOrElmOrID entry maps to a unique object utterance
// generator function within the UtteranceGenerator.
var tests = [{
aAccOrElmOrID: "anchor",
accOrElmOrID: "anchor",
expected: [["link", "title"], ["title", "link"]]
}, {
aAccOrElmOrID: "textarea",
accOrElmOrID: "textarea",
expected: [[
"text area", "Test Text Area", "This is the text area text."
"text area", "This is the text area text."
], [
"This is the text area text.", "Test Text Area", "text area"
"This is the text area text.", "text area"
]]
}, {
aAccOrElmOrID: "heading",
accOrElmOrID: "heading",
expected: [
["heading level 1", "Test heading"],
["Test heading", "heading level 1"]
]
}, {
aAccOrElmOrID: "list",
accOrElmOrID: "list",
expected: [
["list 1 items", "Test List", "First item", "1. ", "list one"],
["1. ", "list one", "First item", "Test List", "list 1 items"]
["list 1 items", "First item", "1. ", "list one"],
["1. ", "list one", "First item", "list 1 items"]
]
}, {
aAccOrElmOrID: "dlist",
accOrElmOrID: "dlist",
expected: [
["definition list 0.5 items", "Test Definition List", "dd one "],
["dd one ", "Test Definition List", "definition list 0.5 items"]
["definition list 0.5 items", "dd one "],
["dd one ", "definition list 0.5 items"]
]
}, {
aAccOrElmOrID: "li_one",
accOrElmOrID: "li_one",
expected: [
["list 1 items", "Test List", "First item", "1. ", "list one"],
["1. ", "list one", "First item", "Test List", "list 1 items"]
["list 1 items", "First item", "1. ", "list one"],
["1. ", "list one", "First item", "list 1 items"]
]
}, {
aAccOrElmOrID: "cell",
accOrElmOrID: "cell",
expected: [[
"table", "Fruits and vegetables", "list 4 items", "First item", " ",
"link", "Apples", " ", "link", "Bananas", " ", "link", "Peaches",
@ -99,24 +67,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=753984
]]
}, {
// Test pivot to list from li_one.
aAccOrElmOrID: "list",
oldAAccOrElmOrID: "li_one",
accOrElmOrID: "list",
oldAccOrElmOrID: "li_one",
expected: [
["list 1 items", "Test List", "First item", "1. ", "list one"],
["1. ", "list one", "First item", "Test List", "list 1 items"]
["list 1 items", "First item", "1. ", "list one"],
["1. ", "list one", "First item", "list 1 items"]
]
}, {
// Test pivot to "apples" link from the table cell.
aAccOrElmOrID: "apples",
oldAAccOrElmOrID: "cell",
accOrElmOrID: "apples",
oldAccOrElmOrID: "cell",
expected: [
["list 4 items", "First item", "link", "Apples"],
["Apples", "link", "First item", "list 4 items"]
]
}, {
// Test pivot to 'bananas' link from 'apples' link.
aAccOrElmOrID: "bananas",
oldAAccOrElmOrID: "apples",
accOrElmOrID: "bananas",
oldAccOrElmOrID: "apples",
expected: [["link", "Bananas"], ["Bananas", "link"]]
}];
@ -126,14 +94,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=753984
utteranceOrderValues.forEach(
function testUtteranceOrder(utteranceOrder) {
SpecialPowers.setIntPref(PREF_UTTERANCE_ORDER, utteranceOrder);
testContextUtterance(test.expected[utteranceOrder],
test.aAccOrElmOrID, test.oldAAccOrElmOrID);
// Just need to test object utterance for individual
// aAccOrElmOrID.
if (test.oldAAccOrElmOrID) {
return;
}
testUtterance(utteranceOrder, test.aAccOrElmOrID);
var expected = test.expected[utteranceOrder];
testUtterance(expected, test.accOrElmOrID, test.oldAccOrElmOrID);
}
);
});
@ -158,12 +120,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=753984
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<a id="anchor" href="#test" title="title"></a>
<textarea id="textarea" title="Test Text Area" cols="80" rows="5">This is the text area text.</textarea>
<textarea id="textarea" cols="80" rows="5">This is the text area text.</textarea>
<h1 id="heading" title="Test heading"></h1>
<ol id="list" title="Test List">
<ol id="list">
<li id="li_one">list one</li>
</ol>
<dl id="dlist" title="Test Definition List">
<dl id="dlist">
<dd id="dd_one">dd one</li>
</dl>
<table>

Просмотреть файл

@ -0,0 +1,70 @@
const Cu = Components.utils;
const PREF_UTTERANCE_ORDER = "accessibility.accessfu.utterance";
Cu.import('resource://gre/modules/accessibility/Utils.jsm');
Cu.import("resource://gre/modules/accessibility/UtteranceGenerator.jsm",
this);
/**
* Test context utterance generation.
*
* @param expected {Array} expected utterance.
* @param aAccOrElmOrID identifier to get an accessible to test.
* @param aOldAccOrElmOrID optional identifier to get an accessible relative to
* the |aAccOrElmOrID|.
*
* Note: if |aOldAccOrElmOrID| is not provided, the |aAccOrElmOrID| must be
* scoped to the "root" element in markup.
*/
function testContextUtterance(expected, aAccOrElmOrID, aOldAccOrElmOrID) {
aOldAccOrElmOrID = aOldAccOrElmOrID || "root";
var accessible = getAccessible(aAccOrElmOrID);
var oldAccessible = getAccessible(aOldAccOrElmOrID);
var context = new PivotContext(accessible, oldAccessible);
var utterance = UtteranceGenerator.genForContext(context);
isDeeply(utterance, expected,
"Context utterance is correct for " + aAccOrElmOrID);
}
/**
* Test object utterance generated array that includes names.
* Note: test ignores utterances without the name.
*
* @param aAccOrElmOrID identifier to get an accessible to test.
*/
function testObjectUtterance(aAccOrElmOrID) {
var accessible = getAccessible(aAccOrElmOrID);
var utterance = UtteranceGenerator.genForObject(accessible);
var utteranceOrder;
try {
utteranceOrder = SpecialPowers.getIntPref(PREF_UTTERANCE_ORDER);
} catch (ex) {
// PREF_UTTERANCE_ORDER not set.
utteranceOrder = 0;
}
var expectedNameIndex = utteranceOrder === 0 ? utterance.length - 1 : 0;
var nameIndex = utterance.indexOf(accessible.name);
if (nameIndex > -1) {
ok(utterance.indexOf(accessible.name) === expectedNameIndex,
"Object utterance is correct for " + aAccOrElmOrID);
}
}
/**
* Test object and context utterance for an accessible.
*
* @param expected {Array} expected utterance.
* @param aAccOrElmOrID identifier to get an accessible to test.
* @param aOldAccOrElmOrID optional identifier to get an accessible relative to
* the |aAccOrElmOrID|.
*/
function testUtterance(expected, aAccOrElmOrID, aOldAccOrElmOrID) {
testContextUtterance(expected, aAccOrElmOrID, aOldAccOrElmOrID);
// Just need to test object utterance for individual
// accOrElmOrID.
if (aOldAccOrElmOrID) {
return;
}
testObjectUtterance(aAccOrElmOrID);
}