| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Include test fixture. | 5 // Include test fixture. |
| 6 GEN_INCLUDE(['../../testing/chromevox_unittest_base.js']); | 6 GEN_INCLUDE(['../../testing/chromevox_unittest_base.js']); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Test fixture. | 9 * Test fixture. |
| 10 * @constructor | 10 * @constructor |
| 11 * @extends {ChromeVoxUnitTestBase} | 11 * @extends {ChromeVoxUnitTestBase} |
| 12 */ | 12 */ |
| 13 function CvoxLiveRegionsUnitTest() {} | 13 function CvoxLiveRegionsUnitTest() { |
| 14 ChromeVoxUnitTestBase.call(this); |
| 15 } |
| 14 | 16 |
| 15 CvoxLiveRegionsUnitTest.prototype = { | 17 CvoxLiveRegionsUnitTest.prototype = { |
| 16 __proto__: ChromeVoxUnitTestBase.prototype, | 18 __proto__: ChromeVoxUnitTestBase.prototype, |
| 17 | 19 |
| 18 /** @override */ | 20 /** @override */ |
| 19 isAsync: true, | 21 isAsync: true, |
| 20 | 22 |
| 21 /** @override */ | 23 /** @override */ |
| 22 closureModuleDeps: [ | 24 closureModuleDeps: [ |
| 23 'cvox.ChromeVoxTester', | 25 'cvox.ChromeVoxTester', |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 } | 37 } |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 TEST_F('CvoxLiveRegionsUnitTest', 'InsertNonLiveRegion', function() { | 40 TEST_F('CvoxLiveRegionsUnitTest', 'InsertNonLiveRegion', function() { |
| 39 var region = document.createElement('div'); | 41 var region = document.createElement('div'); |
| 40 region.innerHTML = '<div role="button">Alpha</div>'; | 42 region.innerHTML = '<div role="button">Alpha</div>'; |
| 41 document.body.appendChild(region); | 43 document.body.appendChild(region); |
| 42 | 44 |
| 43 this.waitForCalm(function() { | 45 this.waitForCalm(function() { |
| 44 assertEquals(0, cvox.ChromeVoxTester.getUtteranceList().length); | 46 assertEquals(0, cvox.ChromeVoxTester.getUtteranceList().length); |
| 45 testDone(); | |
| 46 }); | 47 }); |
| 47 }); | 48 }); |
| 48 | 49 |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * Test inserting an 'alert' live region. | 52 * Test inserting an 'alert' live region. |
| 52 */ | 53 */ |
| 53 TEST_F('CvoxLiveRegionsUnitTest', 'InsertAlertLiveRegion', function() { | 54 TEST_F('CvoxLiveRegionsUnitTest', 'InsertAlertLiveRegion', function() { |
| 54 var region = document.createElement('div'); | 55 var region = document.createElement('div'); |
| 55 region.innerHTML = '<div role="alert">Alpha</div>'; | 56 region.innerHTML = '<div role="alert">Alpha</div>'; |
| 56 document.body.appendChild(region); | 57 document.body.appendChild(region); |
| 57 | 58 |
| 58 this.waitForCalm(function() { | 59 this.waitForCalm(function() { |
| 59 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 60 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 60 assertEquals('Alpha', utterances[0]); | 61 assertEquals('Alpha', utterances[0]); |
| 61 assertEquals('Alert', utterances[1]); | 62 assertEquals('Alert', utterances[1]); |
| 62 testDone(); | |
| 63 }); | 63 }); |
| 64 }); | 64 }); |
| 65 | 65 |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Test making text appear inside an 'alert' live region by setting its | 68 * Test making text appear inside an 'alert' live region by setting its |
| 69 * display to something other than 'none'. | 69 * display to something other than 'none'. |
| 70 */ | 70 */ |
| 71 TEST_F('CvoxLiveRegionsUnitTest', 'RevealAlertLiveRegion', function() { | 71 TEST_F('CvoxLiveRegionsUnitTest', 'RevealAlertLiveRegion', function() { |
| 72 this.loadDoc(function() {/*! | 72 this.loadDoc(function() {/*! |
| 73 <div role="alert"> | 73 <div role="alert"> |
| 74 <style> | 74 <style> |
| 75 .invisible { | 75 .invisible { |
| 76 display: none; | 76 display: none; |
| 77 } | 77 } |
| 78 </style> | 78 </style> |
| 79 <div id="mymessage" class="invisible"> | 79 <div id="mymessage" class="invisible"> |
| 80 I just appeared! | 80 I just appeared! |
| 81 </div> | 81 </div> |
| 82 </div> | 82 </div> |
| 83 */}); | 83 */}); |
| 84 $('mymessage').className = ''; | 84 $('mymessage').className = ''; |
| 85 | 85 |
| 86 this.waitForCalm(function() { | 86 this.waitForCalm(function() { |
| 87 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 87 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 88 assertEquals('I just appeared!', utterances[0]); | 88 assertEquals('I just appeared!', utterances[0]); |
| 89 testDone(); | |
| 90 }); | 89 }); |
| 91 }); | 90 }); |
| 92 | 91 |
| 93 | 92 |
| 94 /** | 93 /** |
| 95 * Test inserting a 'polite' live region. | 94 * Test inserting a 'polite' live region. |
| 96 */ | 95 */ |
| 97 TEST_F('CvoxLiveRegionsUnitTest', 'InsertPoliteLiveRegion', function() { | 96 TEST_F('CvoxLiveRegionsUnitTest', 'InsertPoliteLiveRegion', function() { |
| 98 var region = document.createElement('div'); | 97 var region = document.createElement('div'); |
| 99 region.innerHTML = '<div aria-live="polite">Beta</div>'; | 98 region.innerHTML = '<div aria-live="polite">Beta</div>'; |
| 100 document.body.appendChild(region); | 99 document.body.appendChild(region); |
| 101 | 100 |
| 102 this.waitForCalm(function() { | 101 this.waitForCalm(function() { |
| 103 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 102 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 104 assertEquals('Beta', utterances[0]); | 103 assertEquals('Beta', utterances[0]); |
| 105 testDone(); | |
| 106 }); | 104 }); |
| 107 }); | 105 }); |
| 108 | 106 |
| 109 | 107 |
| 110 /** | 108 /** |
| 111 * Test modifying an existing status live region. | 109 * Test modifying an existing status live region. |
| 112 */ | 110 */ |
| 113 TEST_F('CvoxLiveRegionsUnitTest', 'ModifyStatusLiveRegion', function() { | 111 TEST_F('CvoxLiveRegionsUnitTest', 'ModifyStatusLiveRegion', function() { |
| 114 var region = document.createElement('div'); | 112 var region = document.createElement('div'); |
| 115 region.innerHTML = '<div id="status" role="status">Gamma</div>'; | 113 region.innerHTML = '<div id="status" role="status">Gamma</div>'; |
| 116 document.body.appendChild(region); | 114 document.body.appendChild(region); |
| 117 | 115 |
| 118 this.waitForCalm(function() { | 116 this.waitForCalm(function() { |
| 119 $('status').innerText = 'Delta'; | 117 $('status').innerText = 'Delta'; |
| 120 // Wait for this to make it through the event queue and | 118 // Wait for this to make it through the event queue and |
| 121 // trigger the live region change announcement. | 119 // trigger the live region change announcement. |
| 122 this.waitForCalm(function() { | 120 this.waitForCalm(function() { |
| 123 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 121 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 124 assertEquals('Delta', utterances[utterances.length - 1]); | 122 assertEquals('Delta', utterances[utterances.length - 1]); |
| 125 testDone(); | |
| 126 }); | 123 }); |
| 127 }); | 124 }); |
| 128 }); | 125 }); |
| 129 | 126 |
| 130 | 127 |
| 131 /** | 128 /** |
| 132 * Test adding element to a atomic and non-atomic live regions. | 129 * Test adding element to a atomic and non-atomic live regions. |
| 133 */ | 130 */ |
| 134 TEST_F('CvoxLiveRegionsUnitTest', 'AddToLiveRegion', function() { | 131 TEST_F('CvoxLiveRegionsUnitTest', 'AddToLiveRegion', function() { |
| 135 this.loadDoc(function() {/*! | 132 this.loadDoc(function() {/*! |
| (...skipping 13 matching lines...) Expand all Loading... |
| 149 var eric1 = document.createElement('div'); | 146 var eric1 = document.createElement('div'); |
| 150 eric1.innerHTML = 'Eric'; | 147 eric1.innerHTML = 'Eric'; |
| 151 $('non_atomic_buddylist').appendChild(eric1); | 148 $('non_atomic_buddylist').appendChild(eric1); |
| 152 var eric2 = document.createElement('div'); | 149 var eric2 = document.createElement('div'); |
| 153 eric2.innerHTML = 'Eric'; | 150 eric2.innerHTML = 'Eric'; |
| 154 $('atomic_buddylist').appendChild(eric2); | 151 $('atomic_buddylist').appendChild(eric2); |
| 155 this.waitForCalm(function() { | 152 this.waitForCalm(function() { |
| 156 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 153 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 157 assertEquals('Eric', utterances[utterances.length - 2]); | 154 assertEquals('Eric', utterances[utterances.length - 2]); |
| 158 assertEquals('Larry Sergey Eric', utterances[utterances.length - 1]); | 155 assertEquals('Larry Sergey Eric', utterances[utterances.length - 1]); |
| 159 testDone(); | |
| 160 }); | 156 }); |
| 161 }); | 157 }); |
| 162 }); | 158 }); |
| 163 | 159 |
| 164 /** | 160 /** |
| 165 * Test removing elements from live regions. | 161 * Test removing elements from live regions. |
| 166 */ | 162 */ |
| 167 TEST_F('CvoxLiveRegionsUnitTest', 'RemoveFromLiveRegion', function() { | 163 TEST_F('CvoxLiveRegionsUnitTest', 'RemoveFromLiveRegion', function() { |
| 168 this.loadDoc(function() {/*! | 164 this.loadDoc(function() {/*! |
| 169 <div> | 165 <div> |
| 170 <div id="buddylist2" aria-relevant="removals"> | 166 <div id="buddylist2" aria-relevant="removals"> |
| 171 <div id="jack">Jack</div> | 167 <div id="jack">Jack</div> |
| 172 <div id="janet">Janet</div> | 168 <div id="janet">Janet</div> |
| 173 <div id="chrissy">Chrissy</div> | 169 <div id="chrissy">Chrissy</div> |
| 174 </div> | 170 </div> |
| 175 </div> | 171 </div> |
| 176 */}); | 172 */}); |
| 177 | 173 |
| 178 $('buddylist2').setAttribute('aria-live', 'polite'); | 174 $('buddylist2').setAttribute('aria-live', 'polite'); |
| 179 $('buddylist2').removeChild($('jack')); | 175 $('buddylist2').removeChild($('jack')); |
| 180 this.waitForCalm(function() { | 176 this.waitForCalm(function() { |
| 181 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 177 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 182 assertEquals(1, utterances.length); | 178 assertEquals(1, utterances.length); |
| 183 assertEquals('removed:, Jack', utterances[0]); | 179 assertEquals('removed:, Jack', utterances[0]); |
| 184 testDone(); | |
| 185 }); | 180 }); |
| 186 }); | 181 }); |
| 187 | 182 |
| 188 | 183 |
| 189 /** | 184 /** |
| 190 * Test live region that's a progress bar through the event watcher. | 185 * Test live region that's a progress bar through the event watcher. |
| 191 */ | 186 */ |
| 192 TEST_F('CvoxLiveRegionsUnitTest', 'ProgressBarLiveRegionEvents', function() { | 187 TEST_F('CvoxLiveRegionsUnitTest', 'ProgressBarLiveRegionEvents', function() { |
| 193 this.loadDoc(function() {/*! | 188 this.loadDoc(function() {/*! |
| 194 <div id="progress" role="progressbar" aria-live="polite" aria-valuenow="1"> | 189 <div id="progress" role="progressbar" aria-live="polite" aria-valuenow="1"> |
| 195 <div id="ptext"> | 190 <div id="ptext"> |
| 196 1% complete. | 191 1% complete. |
| 197 </div> | 192 </div> |
| 198 </div> | 193 </div> |
| 199 */}); | 194 */}); |
| 200 | 195 |
| 201 $('progress').setAttribute('aria-valuenow', '2'); | 196 $('progress').setAttribute('aria-valuenow', '2'); |
| 202 $('ptext').innerText = '2% complete'; | 197 $('ptext').innerText = '2% complete'; |
| 203 this.waitForCalm(function() { | 198 this.waitForCalm(function() { |
| 204 var utterances = cvox.ChromeVoxTester.getUtteranceList(); | 199 var utterances = cvox.ChromeVoxTester.getUtteranceList(); |
| 205 assertEquals('Progress bar 2', utterances[utterances.length - 1]); | 200 assertEquals('Progress bar 2', utterances[utterances.length - 1]); |
| 206 testDone(); | |
| 207 }); | 201 }); |
| 208 }); | 202 }); |
| 209 | 203 |
| 210 | 204 |
| 211 /** | 205 /** |
| 212 * Test 'alert' live region inserted as a result of focus change, like | 206 * Test 'alert' live region inserted as a result of focus change, like |
| 213 * when there's an error message when filling out a form. | 207 * when there's an error message when filling out a form. |
| 214 */ | 208 */ |
| 215 TEST_F('CvoxLiveRegionsUnitTest', 'FocusTriggeredAlertLiveRegion', function() { | 209 TEST_F('CvoxLiveRegionsUnitTest', 'FocusTriggeredAlertLiveRegion', function() { |
| 216 this.loadDoc(function() {/*! | 210 this.loadDoc(function() {/*! |
| (...skipping 27 matching lines...) Expand all Loading... |
| 244 | 238 |
| 245 this.waitForCalm(function() { name.focus(); }) | 239 this.waitForCalm(function() { name.focus(); }) |
| 246 .waitForCalm(function() { address.focus(); }) | 240 .waitForCalm(function() { address.focus(); }) |
| 247 .waitForCalm(this.assertSpokenList, | 241 .waitForCalm(this.assertSpokenList, |
| 248 new cvox.SpokenListBuilder() | 242 new cvox.SpokenListBuilder() |
| 249 .categoryFlush('Name') | 243 .categoryFlush('Name') |
| 250 .queue('Edit text') | 244 .queue('Edit text') |
| 251 .categoryFlush('Address') | 245 .categoryFlush('Address') |
| 252 .queue('Edit text') | 246 .queue('Edit text') |
| 253 .categoryFlush('Not a valid name!') | 247 .categoryFlush('Not a valid name!') |
| 254 .queue('Alert')) | 248 .queue('Alert')); |
| 255 .waitForCalm(testDone); | |
| 256 }); | 249 }); |
| 257 | 250 |
| 258 | 251 |
| 259 /** | 252 /** |
| 260 * Test focus followed by live region change, make sure both are spoken. | 253 * Test focus followed by live region change, make sure both are spoken. |
| 261 */ | 254 */ |
| 262 TEST_F('CvoxLiveRegionsUnitTest', 'FocusThenLiveRegion', function() { | 255 TEST_F('CvoxLiveRegionsUnitTest', 'FocusThenLiveRegion', function() { |
| 263 this.loadDoc(function() {/*! | 256 this.loadDoc(function() {/*! |
| 264 <button id="button_to_focus">Button To Focus</button> | 257 <button id="button_to_focus">Button To Focus</button> |
| 265 <div id="live" aria-live="polite"></div> | 258 <div id="live" aria-live="polite"></div> |
| 266 */}); | 259 */}); |
| 267 | 260 |
| 268 $('button_to_focus').focus(); | 261 $('button_to_focus').focus(); |
| 269 $('live').innerText = 'Live region text'; | 262 $('live').innerText = 'Live region text'; |
| 270 | 263 |
| 271 this.waitForCalm(this.assertSpokenList, | 264 this.waitForCalm(this.assertSpokenList, |
| 272 new cvox.SpokenListBuilder() | 265 new cvox.SpokenListBuilder() |
| 273 .categoryFlush('Button To Focus') | 266 .categoryFlush('Button To Focus') |
| 274 .queue('Button') | 267 .queue('Button') |
| 275 .categoryFlush('Live region text')) | 268 .categoryFlush('Live region text')); |
| 276 .waitForCalm(testDone); | |
| 277 }); | 269 }); |
| 278 | 270 |
| 279 | 271 |
| 280 /** | 272 /** |
| 281 * Test live region change followed by focus, make sure both are spoken. | 273 * Test live region change followed by focus, make sure both are spoken. |
| 282 */ | 274 */ |
| 283 TEST_F('CvoxLiveRegionsUnitTest', 'LiveRegionThenFocus', function() { | 275 TEST_F('CvoxLiveRegionsUnitTest', 'LiveRegionThenFocus', function() { |
| 284 this.loadDoc(function() {/*! | 276 this.loadDoc(function() {/*! |
| 285 <button id="button_to_focus">Button To Focus</button> | 277 <button id="button_to_focus">Button To Focus</button> |
| 286 <div id="live" aria-live="polite"></div> | 278 <div id="live" aria-live="polite"></div> |
| 287 */}); | 279 */}); |
| 288 | 280 |
| 289 $('live').innerText = 'Live region text'; | 281 $('live').innerText = 'Live region text'; |
| 290 | 282 |
| 291 this.waitForCalm(function() { | 283 this.waitForCalm(function() { |
| 292 $('button_to_focus').focus(); | 284 $('button_to_focus').focus(); |
| 293 }) | 285 }) |
| 294 .waitForCalm(this.assertSpokenList, | 286 .waitForCalm(this.assertSpokenList, |
| 295 new cvox.SpokenListBuilder() | 287 new cvox.SpokenListBuilder() |
| 296 .categoryFlush('Live region text') | 288 .categoryFlush('Live region text') |
| 297 .categoryFlush('Button To Focus') | 289 .categoryFlush('Button To Focus') |
| 298 .queue('Button')) | 290 .queue('Button')); |
| 299 .waitForCalm(testDone); | |
| 300 }); | 291 }); |
| 301 | 292 |
| 302 | 293 |
| 303 /** | 294 /** |
| 304 * Two elements inside a live region. These are all combined into | 295 * Two elements inside a live region. These are all combined into |
| 305 * one utterance until this bug is fixed: http://crbug.com/415679 | 296 * one utterance until this bug is fixed: http://crbug.com/415679 |
| 306 */ | 297 */ |
| 307 TEST_F('CvoxLiveRegionsUnitTest', 'TwoElementsInLiveRegion', function() { | 298 TEST_F('CvoxLiveRegionsUnitTest', 'TwoElementsInLiveRegion', function() { |
| 308 this.loadDoc(function() {/*! | 299 this.loadDoc(function() {/*! |
| 309 <div id="live" aria-live="polite"> | 300 <div id="live" aria-live="polite"> |
| 310 <div id="hidden" style="display:none"> | 301 <div id="hidden" style="display:none"> |
| 311 <button>L1</button> | 302 <button>L1</button> |
| 312 <button>L2</button> | 303 <button>L2</button> |
| 313 </div> | 304 </div> |
| 314 </div> | 305 </div> |
| 315 */}); | 306 */}); |
| 316 | 307 |
| 317 $('hidden').style.display = 'block'; | 308 $('hidden').style.display = 'block'; |
| 318 this.waitForCalm(this.assertSpokenList, | 309 this.waitForCalm(this.assertSpokenList, |
| 319 new cvox.SpokenListBuilder() | 310 new cvox.SpokenListBuilder() |
| 320 .categoryFlush('L1, L2')) | 311 .categoryFlush('L1, L2')); |
| 321 .waitForCalm(testDone); | |
| 322 }); | 312 }); |
| OLD | NEW |