Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 /** | |
| 6 * Test fixture for aria_util.js. | |
| 7 * @constructor | |
| 8 * @extends {testing.Test} | |
| 9 */ | |
| 10 function AriaUtilUnitTest() {} | |
| 11 | |
| 12 AriaUtilUnitTest.prototype = { | |
| 13 __proto__: testing.Test.prototype, | |
| 14 | |
| 15 /** | |
|
Peter Lundblad
2014/05/22 15:24:25
nit: indentation.
dmazzoni
2014/05/22 16:27:32
Done.
| |
| 16 * This test fixture uses the WebUI test framework, so we need to | |
| 17 * have any WebUI page loaded first. | |
| 18 */ | |
| 19 browsePreload: 'chrome://settings-frame', | |
|
Peter Lundblad
2014/05/22 15:24:25
Looks like a temporary hack to me. Maybe make a b
Peter Lundblad
2014/05/22 15:24:25
There seems to be a DUMMY_URL constant for this pu
dmazzoni
2014/05/22 16:27:32
Yes! That works, thanks.
dmazzoni
2014/05/22 16:27:32
Moved to a base class!
I don't think there's an e
| |
| 20 | |
| 21 /** | |
|
Peter Lundblad
2014/05/22 15:24:25
nit: Indent.
dmazzoni
2014/05/22 16:27:32
Done.
| |
| 22 * Loads some inlined html into the current document, replacing | |
| 23 * whatever was there previously. To use it, call it with the html | |
| 24 * inside an inline comment, like this: | |
| 25 * | |
| 26 * this.loadDoc(function() {/*! | |
| 27 * <p>Html goes here</p> | |
| 28 * * /}); | |
| 29 */ | |
| 30 loadDoc: function(commentEncodedHtml) { | |
|
Peter Lundblad
2014/05/22 15:24:25
Looks like a candidate to moved into a base class.
dmazzoni
2014/05/22 16:27:32
Done.
| |
| 31 var html = commentEncodedHtml.toString(). | |
| 32 replace(/^[^\/]+\/\*!?/, ''). | |
| 33 replace(/\*\/[^\/]+$/, ''); | |
| 34 document.open(); | |
| 35 document.write(html); | |
| 36 document.close(); | |
| 37 }, | |
| 38 | |
| 39 /** @override */ | |
| 40 extraLibraries: [ | |
| 41 'aria_util.js', | |
| 42 'dom_util.js', | |
| 43 'node_state.js', | |
| 44 'chromevox.js', | |
| 45 '../host/interface/abstract_earcons.js'] | |
|
Peter Lundblad
2014/05/22 15:24:25
Given our dependency situation, I am wondering if
dmazzoni
2014/05/22 16:27:32
That would be cool if you'd like to look into that
| |
| 46 }; | |
| 47 | |
| 48 TEST_F('AriaUtilUnitTest', 'GetStateGridWithActiveCell', function() { | |
| 49 this.loadDoc(function() {/*! | |
| 50 <div id="grid" role="grid" aria-activedescendant="cell"> | |
| 51 <div role="row"> | |
| 52 <div id="cell" role="gridcell"> | |
| 53 </div> | |
| 54 </div> | |
| 55 */}); | |
|
Peter Lundblad
2014/05/22 15:24:25
Neat trick! Hadn't seen it before;)
| |
| 56 assertEquals( | |
|
Peter Lundblad
2014/05/22 15:24:25
I think assertThat(..., eqJSON) is a nice and comp
dmazzoni
2014/05/22 16:27:32
Agreed, that works great, thanks.
| |
| 57 [['aria_role_gridcell_pos', 1, 1]].toString(), | |
| 58 cvox.AriaUtil.getStateMsgs($('grid'), true). | |
| 59 toString()); | |
| 60 }); | |
| 61 | |
| 62 TEST_F('AriaUtilUnitTest', 'GetActiveDescendant', function() { | |
| 63 this.loadDoc(function() {/*! | |
| 64 <div id="top" aria-activedescendant="child"> | |
| 65 <div id="child" /> | |
| 66 </div> | |
| 67 <div id="top_2" aria-activedescendant="child_2"> | |
| 68 <div id="child_2" aria-activedescendant="grandchild_2"> | |
| 69 <div id="grandchild_2" /> | |
| 70 </div> | |
| 71 </div> | |
| 72 | |
| 73 <h1>The buggy cases.</h1> | |
| 74 <div id="loop" aria-activedescendant="loop" /> | |
| 75 <div id="circleA" aria-activedescendant="circleB"> | |
| 76 <div id="circleB" aria-activedescendant="circleA" /> | |
| 77 </div> | |
| 78 */}); | |
| 79 | |
| 80 // The typical case. | |
| 81 var topElt = $('top'); | |
| 82 var childElt = $('child'); | |
| 83 assertEquals(childElt, cvox.AriaUtil.getActiveDescendant(topElt)); | |
| 84 | |
| 85 // childElt has not aria-activedescendant, so return null. | |
| 86 assertEquals(null, cvox.AriaUtil.getActiveDescendant(childElt)); | |
| 87 | |
| 88 // The chained case. | |
| 89 var top2Elt = $('top_2'); | |
| 90 var grandchild2Elt = $('grandchild_2'); | |
| 91 assertEquals(grandchild2Elt, cvox.AriaUtil.getActiveDescendant(top2Elt)); | |
| 92 | |
| 93 // The buggy cases. These are invalid, so return null as if the | |
| 94 // aria-activedescendant tags did not exist. | |
| 95 var loopElt = $('loop'); | |
| 96 assertEquals(null, cvox.AriaUtil.getActiveDescendant(loopElt)); | |
| 97 | |
| 98 var circleAElt = $('circleA'); | |
| 99 assertEquals(null, cvox.AriaUtil.getActiveDescendant(circleAElt)); | |
| 100 }); | |
| 101 | |
| 102 TEST_F('AriaUtilUnitTest', 'ListIndexAndState', function() { | |
| 103 this.loadDoc(function() {/*! | |
| 104 <div id="l" role="listbox" tabindex="0" aria-activedescendant="l2"> | |
| 105 <div id="l1" role="option">A</div> | |
| 106 <div id="l2" role="option">B</div> | |
| 107 <div id="l3" role="option">C</div> | |
| 108 </div> | |
| 109 <div id="a" role="listbox" tabindex="0" aria-activedescendant="a2"> | |
| 110 <div id="a1" role="option" aria-setsize="10" aria-posinset="5">A</div> | |
| 111 <div id="a2" role="option" aria-setsize="20" aria-posinset="15">B</div> | |
| 112 <div id="a3" role="option" aria-setsize="30" aria-posinset="25">C</div> | |
| 113 </div> | |
| 114 <div id="b" role="listbox" tabindex="0" aria-activedescendant="b2"> | |
| 115 <div id="b1" role="option" aria-posinset="3">A</div> | |
| 116 <div id="b2" role="option" aria-posinset="2">B</div> | |
| 117 <div id="b3" role="option" aria-posinset="1">C</div> | |
| 118 </div> | |
| 119 */}); | |
| 120 | |
| 121 var optionElt = $('l2'); | |
| 122 assertEquals( | |
| 123 [['list_position', 2, 3]].toString(), | |
| 124 cvox.AriaUtil.getStateMsgs(optionElt).toString()); | |
| 125 | |
| 126 var ariaOptionElt = $('a2'); | |
| 127 assertEquals( | |
| 128 [['list_position', 15, 20]].toString(), | |
| 129 cvox.AriaUtil.getStateMsgs(ariaOptionElt).toString()); | |
| 130 | |
| 131 ariaOptionElt = $('b3'); | |
| 132 assertEquals( | |
| 133 [['list_position', 1, 3]].toString(), | |
| 134 cvox.AriaUtil.getStateMsgs(ariaOptionElt).toString()); | |
| 135 }); | |
| 136 | |
| 137 TEST_F('AriaUtilUnitTest', 'GetLiveRegions', function() { | |
| 138 this.loadDoc(function() {/*! | |
| 139 <div id="outer"> | |
| 140 <div id="progress" role="progressbar" aria-live="polite" aria-valuenow="1"> | |
| 141 <div id="ptext"> | |
| 142 1% complete. | |
| 143 </div> | |
| 144 </div> | |
| 145 <div id="progress2" role="progressbar" aria-live="polite" aria-valuenow="1"> | |
| 146 <div id="ptext2"> | |
| 147 1% complete. | |
| 148 </div> | |
| 149 </div> | |
| 150 </div> | |
| 151 */}); | |
| 152 | |
| 153 var progressLiveRegions = cvox.AriaUtil.getLiveRegions(progress); | |
| 154 assertEquals(1, progressLiveRegions.length); | |
| 155 assertNotEquals(-1, progressLiveRegions.indexOf(progress)); | |
| 156 | |
| 157 var outerLiveRegions = cvox.AriaUtil.getLiveRegions(outer); | |
| 158 assertEquals(2, outerLiveRegions.length); | |
| 159 assertNotEquals(-1, outerLiveRegions.indexOf(progress)); | |
| 160 assertNotEquals(-1, outerLiveRegions.indexOf(progress2)); | |
| 161 | |
| 162 // getLiveRegions works walking up the tree as well. | |
| 163 var ptextLiveRegions = cvox.AriaUtil.getLiveRegions(ptext); | |
| 164 assertEquals(1, ptextLiveRegions.length); | |
| 165 assertNotEquals(-1, ptextLiveRegions.indexOf(progress)); | |
| 166 }); | |
| OLD | NEW |