OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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_next_e2e_test_base.js', |
| 7 '../../testing/assert_additions.js']); |
| 8 |
| 9 GEN_INCLUDE(['../../testing/mock_feedback.js']); |
| 10 |
| 11 /** |
| 12 * Test fixture for Live Regions. |
| 13 * @constructor |
| 14 * @extends {ChromeVoxNextE2ETest} |
| 15 */ |
| 16 function LiveRegionsTest() { |
| 17 ChromeVoxNextE2ETest.call(this); |
| 18 } |
| 19 |
| 20 LiveRegionsTest.prototype = { |
| 21 __proto__: ChromeVoxNextE2ETest.prototype, |
| 22 |
| 23 /** @override */ |
| 24 setUp: function() { |
| 25 global.backgroundObj.forceChromeVoxNextActive(); |
| 26 window.RoleType = chrome.automation.RoleType; |
| 27 }, |
| 28 |
| 29 /** |
| 30 * @return {!MockFeedback} |
| 31 */ |
| 32 createMockFeedback: function() { |
| 33 var mockFeedback = new MockFeedback(this.newCallback(), |
| 34 this.newCallback.bind(this)); |
| 35 mockFeedback.install(); |
| 36 return mockFeedback; |
| 37 }, |
| 38 |
| 39 /** |
| 40 * Create a function which performs the command |cmd|. |
| 41 * @param {string} cmd |
| 42 * @return {function() : void} |
| 43 */ |
| 44 doCmd: function(cmd) { |
| 45 return function() { |
| 46 global.backgroundObj.onGotCommand(cmd); |
| 47 }; |
| 48 }, |
| 49 }; |
| 50 |
| 51 TEST_F('LiveRegionsTest', 'LiveRegionAddElement', function() { |
| 52 var mockFeedback = this.createMockFeedback(); |
| 53 this.runWithLoadedTree( |
| 54 function() {/*! |
| 55 <h1>Document with live region</h1> |
| 56 <p id="live" aria-live="polite"></p> |
| 57 <button id="go">Go</button> |
| 58 <script> |
| 59 document.getElementById('go').addEventListener('click', function() { |
| 60 document.getElementById('live').innerHTML = 'Hello, world'; |
| 61 }, false); |
| 62 </script> |
| 63 */}, |
| 64 function(rootNode) { |
| 65 var go = rootNode.find({ role: RoleType.button }); |
| 66 mockFeedback.call(go.doDefault.bind(go)) |
| 67 .expectCategoryFlushSpeech('Hello, world'); |
| 68 mockFeedback.replay(); |
| 69 }); |
| 70 }); |
| 71 |
| 72 TEST_F('LiveRegionsTest', 'LiveRegionRemoveElement', function() { |
| 73 var mockFeedback = this.createMockFeedback(); |
| 74 this.runWithLoadedTree( |
| 75 function() {/*! |
| 76 <h1>Document with live region</h1> |
| 77 <p id="live" aria-live="polite" aria-relevant="removals">Hello, world</p> |
| 78 <button id="go">Go</button> |
| 79 <script> |
| 80 document.getElementById('go').addEventListener('click', function() { |
| 81 document.getElementById('live').innerHTML = ''; |
| 82 }, false); |
| 83 </script> |
| 84 */}, |
| 85 function(rootNode) { |
| 86 var go = rootNode.find({ role: RoleType.button }); |
| 87 go.doDefault(); |
| 88 mockFeedback.expectCategoryFlushSpeech('removed:') |
| 89 .expectQueuedSpeech('Hello, world'); |
| 90 mockFeedback.replay(); |
| 91 }); |
| 92 }); |
| 93 |
| 94 TEST_F('LiveRegionsTest', 'LiveRegionChangeAtomic', function() { |
| 95 var mockFeedback = this.createMockFeedback(); |
| 96 this.runWithLoadedTree( |
| 97 function() {/*! |
| 98 <div id="live" aria-live="polite" aria-atomic="true"> |
| 99 <div id="a"></div><div id="b">Bravo</div><div id="c"></div> |
| 100 </div> |
| 101 <button id="go">Go</button> |
| 102 <script> |
| 103 document.getElementById('go').addEventListener('click', function() { |
| 104 document.getElementById('c').textContent = 'Charlie'; |
| 105 document.getElementById('a').textContent = 'Alpha'; |
| 106 }, false); |
| 107 </script> |
| 108 */}, |
| 109 function(rootNode) { |
| 110 var go = rootNode.find({ role: RoleType.button }); |
| 111 mockFeedback.call(go.doDefault.bind(go)) |
| 112 .expectQueuedSpeech('Alpha') |
| 113 .expectQueuedSpeech('Bravo') |
| 114 .expectQueuedSpeech('Charlie'); |
| 115 mockFeedback.replay(); |
| 116 }); |
| 117 }); |
| 118 |
| 119 TEST_F('LiveRegionsTest', 'LiveRegionChangeImageAlt', function() { |
| 120 var mockFeedback = this.createMockFeedback(); |
| 121 this.runWithLoadedTree( |
| 122 function() {/*! |
| 123 <div id="live" aria-live="polite"> |
| 124 <img id="img" src="#" alt="Before"> |
| 125 </div> |
| 126 <button id="go">Go</button> |
| 127 <script> |
| 128 document.getElementById('go').addEventListener('click', function() { |
| 129 document.getElementById('img').setAttribute('alt', 'After'); |
| 130 }, false); |
| 131 </script> |
| 132 */}, |
| 133 function(rootNode) { |
| 134 var go = rootNode.find({ role: RoleType.button }); |
| 135 mockFeedback.call(go.doDefault.bind(go)) |
| 136 .expectCategoryFlushSpeech('After') |
| 137 .expectQueuedSpeech('Image'); |
| 138 mockFeedback.replay(); |
| 139 }); |
| 140 }); |
| 141 |
| 142 TEST_F('LiveRegionsTest', 'LiveRegionThenFocus', function() { |
| 143 var mockFeedback = this.createMockFeedback(); |
| 144 this.runWithLoadedTree( |
| 145 function() {/*! |
| 146 <div id="live" aria-live="polite"></div> |
| 147 <button id="go">Go</button> |
| 148 <button id="focus">Focus</button> |
| 149 <script> |
| 150 document.getElementById('go').addEventListener('click', function() { |
| 151 document.getElementById('live').textContent = 'Live'; |
| 152 window.setTimeout(function() { |
| 153 document.getElementById('focus').focus(); |
| 154 }, 50); |
| 155 }, false); |
| 156 </script> |
| 157 */}, |
| 158 function(rootNode) { |
| 159 var go = rootNode.find({ role: RoleType.button }); |
| 160 mockFeedback.call(go.doDefault.bind(go)) |
| 161 .expectCategoryFlushSpeech('Live') |
| 162 .expectQueuedSpeech('Focus'); |
| 163 mockFeedback.replay(); |
| 164 }); |
| 165 }); |
| 166 |
| 167 TEST_F('LiveRegionsTest', 'FocusThenLiveRegion', function() { |
| 168 var mockFeedback = this.createMockFeedback(); |
| 169 this.runWithLoadedTree( |
| 170 function() {/*! |
| 171 <div id="live" aria-live="polite"></div> |
| 172 <button id="go">Go</button> |
| 173 <button id="focus">Focus</button> |
| 174 <script> |
| 175 document.getElementById('go').addEventListener('click', function() { |
| 176 document.getElementById('focus').focus(); |
| 177 window.setTimeout(function() { |
| 178 document.getElementById('live').textContent = 'Live'; |
| 179 }, 50); |
| 180 }, false); |
| 181 </script> |
| 182 */}, |
| 183 function(rootNode) { |
| 184 var go = rootNode.find({ role: RoleType.button }); |
| 185 mockFeedback.call(go.doDefault.bind(go)) |
| 186 .expectQueuedSpeech('Focus') |
| 187 .expectCategoryFlushSpeech('Live'); |
| 188 mockFeedback.replay(); |
| 189 }); |
| 190 }); |
| 191 |
| 192 TEST_F('LiveRegionsTest', 'LiveRegionCategoryFlush', function() { |
| 193 var mockFeedback = this.createMockFeedback(); |
| 194 this.runWithLoadedTree( |
| 195 function() {/*! |
| 196 <div id="live1" aria-live="polite"></div> |
| 197 <div id="live2" aria-live="polite"></div> |
| 198 <button id="go">Go</button> |
| 199 <button id="focus">Focus</button> |
| 200 <script> |
| 201 document.getElementById('go').addEventListener('click', function() { |
| 202 document.getElementById('live1').textContent = 'Live1'; |
| 203 window.setTimeout(function() { |
| 204 document.getElementById('live2').textContent = 'Live2'; |
| 205 }, 1000); |
| 206 }, false); |
| 207 </script> |
| 208 */}, |
| 209 function(rootNode) { |
| 210 var go = rootNode.find({ role: RoleType.button }); |
| 211 mockFeedback.call(go.doDefault.bind(go)) |
| 212 .expectCategoryFlushSpeech('Live1') |
| 213 .expectCategoryFlushSpeech('Live2'); |
| 214 mockFeedback.replay(); |
| 215 }); |
| 216 }); |
OLD | NEW |