1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Include test fixture.
6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']);
9 * Test fixture for aria_util.js.
11 * @extends {ChromeVoxUnitTestBase}
13 function CvoxAriaUtilUnitTest() {}
15 CvoxAriaUtilUnitTest.prototype = {
16 __proto__: ChromeVoxUnitTestBase.prototype,
25 TEST_F('CvoxAriaUtilUnitTest', 'GetStateGridWithActiveCell', function() {
26 this.loadDoc(function() {/*!
27 <div id="grid" role="grid" aria-activedescendant="cell">
29 <div id="cell" role="gridcell">
34 cvox.AriaUtil.getStateMsgs($('grid'), true),
35 eqJSON([['aria_role_gridcell_pos', 1, 1]]));
38 TEST_F('CvoxAriaUtilUnitTest', 'GetActiveDescendant', function() {
39 this.loadDoc(function() {/*!
40 <div id="top" aria-activedescendant="child">
43 <div id="top_2" aria-activedescendant="child_2">
44 <div id="child_2" aria-activedescendant="grandchild_2">
45 <div id="grandchild_2" />
49 <h1>The buggy cases.</h1>
50 <div id="loop" aria-activedescendant="loop" />
51 <div id="circleA" aria-activedescendant="circleB">
52 <div id="circleB" aria-activedescendant="circleA" />
57 var topElt = $('top');
58 var childElt = $('child');
59 assertEquals(childElt, cvox.AriaUtil.getActiveDescendant(topElt));
61 // childElt has not aria-activedescendant, so return null.
62 assertEquals(null, cvox.AriaUtil.getActiveDescendant(childElt));
65 var top2Elt = $('top_2');
66 var grandchild2Elt = $('grandchild_2');
67 assertEquals(grandchild2Elt, cvox.AriaUtil.getActiveDescendant(top2Elt));
69 // The buggy cases. These are invalid, so return null as if the
70 // aria-activedescendant tags did not exist.
71 var loopElt = $('loop');
72 assertEquals(null, cvox.AriaUtil.getActiveDescendant(loopElt));
74 var circleAElt = $('circleA');
75 assertEquals(null, cvox.AriaUtil.getActiveDescendant(circleAElt));
78 TEST_F('CvoxAriaUtilUnitTest', 'ListIndexAndState', function() {
79 this.loadDoc(function() {/*!
80 <div id="l" role="listbox" tabindex="0" aria-activedescendant="l2">
81 <div id="l1" role="option">A</div>
82 <div id="l2" role="option">B</div>
83 <div id="l3" role="option">C</div>
85 <div id="a" role="listbox" tabindex="0" aria-activedescendant="a2">
86 <div id="a1" role="option" aria-setsize="10" aria-posinset="5">A</div>
87 <div id="a2" role="option" aria-setsize="20" aria-posinset="15">B</div>
88 <div id="a3" role="option" aria-setsize="30" aria-posinset="25">C</div>
90 <div id="b" role="listbox" tabindex="0" aria-activedescendant="b2">
91 <div id="b1" role="option" aria-posinset="3">A</div>
92 <div id="b2" role="option" aria-posinset="2">B</div>
93 <div id="b3" role="option" aria-posinset="1">C</div>
97 var optionElt = $('l2');
99 cvox.AriaUtil.getStateMsgs(optionElt),
100 eqJSON([['list_position', 2, 3]]));
102 var ariaOptionElt = $('a2');
104 cvox.AriaUtil.getStateMsgs(ariaOptionElt),
105 eqJSON([['list_position', 15, 20]]));
107 ariaOptionElt = $('b3');
109 cvox.AriaUtil.getStateMsgs(ariaOptionElt),
110 eqJSON([['list_position', 1, 3]]));
113 TEST_F('CvoxAriaUtilUnitTest', 'GetLiveRegions', function() {
114 this.loadDoc(function() {/*!
116 <div id="progress" role="progressbar" aria-live="polite" aria-valuenow="1">
121 <div id="progress2" role="progressbar" aria-live="polite" aria-valuenow="1">
129 var progressLiveRegions = cvox.AriaUtil.getLiveRegions(progress);
130 assertEquals(1, progressLiveRegions.length);
131 assertNotEquals(-1, progressLiveRegions.indexOf(progress));
133 var outerLiveRegions = cvox.AriaUtil.getLiveRegions(outer);
134 assertEquals(2, outerLiveRegions.length);
135 assertNotEquals(-1, outerLiveRegions.indexOf(progress));
136 assertNotEquals(-1, outerLiveRegions.indexOf(progress2));
138 // getLiveRegions works walking up the tree as well.
139 var ptextLiveRegions = cvox.AriaUtil.getLiveRegions(ptext);
140 assertEquals(1, ptextLiveRegions.length);
141 assertNotEquals(-1, ptextLiveRegions.indexOf(progress));