Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / chromevox / common / aria_util_test.unitjs
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.
4
5 // Include test fixture.
6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']);
7
8 /**
9  * Test fixture for aria_util.js.
10  * @constructor
11  * @extends {ChromeVoxUnitTestBase}
12  */
13 function CvoxAriaUtilUnitTest() {}
14
15 CvoxAriaUtilUnitTest.prototype = {
16   __proto__: ChromeVoxUnitTestBase.prototype,
17
18   /** @override */
19   closureModuleDeps: [
20     'cvox.AriaUtil',
21     'cvox.ChromeVox',
22     'cvox.DomUtil',]
23 };
24
25 TEST_F('CvoxAriaUtilUnitTest', 'GetStateGridWithActiveCell', function() {
26   this.loadDoc(function() {/*!
27     <div id="grid" role="grid" aria-activedescendant="cell">
28       <div role="row">
29         <div id="cell" role="gridcell">
30       </div>
31     </div>
32   */});
33   assertThat(
34       cvox.AriaUtil.getStateMsgs($('grid'), true),
35       eqJSON([['aria_role_gridcell_pos', 1, 1]]));
36 });
37
38 TEST_F('CvoxAriaUtilUnitTest', 'GetActiveDescendant', function() {
39   this.loadDoc(function() {/*!
40     <div id="top" aria-activedescendant="child">
41       <div id="child" />
42     </div>
43     <div id="top_2" aria-activedescendant="child_2">
44       <div id="child_2" aria-activedescendant="grandchild_2">
45         <div id="grandchild_2" />
46       </div>
47     </div>
48
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" />
53     </div>
54   */});
55
56   // The typical case.
57   var topElt = $('top');
58   var childElt = $('child');
59   assertEquals(childElt, cvox.AriaUtil.getActiveDescendant(topElt));
60
61   // childElt has not aria-activedescendant, so return null.
62   assertEquals(null, cvox.AriaUtil.getActiveDescendant(childElt));
63
64   // The chained case.
65   var top2Elt = $('top_2');
66   var grandchild2Elt = $('grandchild_2');
67   assertEquals(grandchild2Elt, cvox.AriaUtil.getActiveDescendant(top2Elt));
68
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));
73
74   var circleAElt = $('circleA');
75   assertEquals(null, cvox.AriaUtil.getActiveDescendant(circleAElt));
76 });
77
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>
84     </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>
89     </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>
94     </div>
95   */});
96
97   var optionElt = $('l2');
98   assertThat(
99       cvox.AriaUtil.getStateMsgs(optionElt),
100       eqJSON([['list_position', 2, 3]]));
101
102   var ariaOptionElt = $('a2');
103   assertThat(
104       cvox.AriaUtil.getStateMsgs(ariaOptionElt),
105       eqJSON([['list_position', 15, 20]]));
106
107   ariaOptionElt = $('b3');
108   assertThat(
109       cvox.AriaUtil.getStateMsgs(ariaOptionElt),
110       eqJSON([['list_position', 1, 3]]));
111 });
112
113 TEST_F('CvoxAriaUtilUnitTest', 'GetLiveRegions', function() {
114   this.loadDoc(function() {/*!
115    <div id="outer">
116     <div id="progress" role="progressbar" aria-live="polite" aria-valuenow="1">
117       <div id="ptext">
118         1% complete.
119       </div>
120     </div>
121     <div id="progress2" role="progressbar" aria-live="polite" aria-valuenow="1">
122       <div id="ptext2">
123         1% complete.
124       </div>
125     </div>
126    </div>
127   */});
128
129   var progressLiveRegions = cvox.AriaUtil.getLiveRegions(progress);
130   assertEquals(1, progressLiveRegions.length);
131   assertNotEquals(-1, progressLiveRegions.indexOf(progress));
132
133   var outerLiveRegions = cvox.AriaUtil.getLiveRegions(outer);
134   assertEquals(2, outerLiveRegions.length);
135   assertNotEquals(-1, outerLiveRegions.indexOf(progress));
136   assertNotEquals(-1, outerLiveRegions.indexOf(progress2));
137
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));
142 });