OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 GEN_INCLUDE([ | 5 GEN_INCLUDE([ |
6 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']); | 6 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']); |
7 | 7 |
8 /** | 8 /** |
9 * Shortcut for document.getElementById. | 9 * Shortcut for document.getElementById. |
10 * @param {string} id of the element. | 10 * @param {string} id of the element. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 * * /}); | 112 * * /}); |
113 * | 113 * |
114 * @param {Function} commentEncodedHtml The html , embedded as a | 114 * @param {Function} commentEncodedHtml The html , embedded as a |
115 * comment inside an anonymous function - see example, above. | 115 * comment inside an anonymous function - see example, above. |
116 @ @return {String} The html text. | 116 @ @return {String} The html text. |
117 */ | 117 */ |
118 extractHtmlFromCommentEncodedString_: function(commentEncodedHtml) { | 118 extractHtmlFromCommentEncodedString_: function(commentEncodedHtml) { |
119 return commentEncodedHtml.toString(). | 119 return commentEncodedHtml.toString(). |
120 replace(/^[^\/]+\/\*!?/, ''). | 120 replace(/^[^\/]+\/\*!?/, ''). |
121 replace(/\*\/[^\/]+$/, ''); | 121 replace(/\*\/[^\/]+$/, ''); |
| 122 }, |
| 123 |
| 124 /** |
| 125 * Waits for the queued events in ChromeVoxEventWatcher to be |
| 126 * handled, then calls a callback function with provided arguments |
| 127 * in the test case scope. Very useful for asserting the results of events. |
| 128 * |
| 129 * @param {function()} func A function to call when ChromeVox is ready. |
| 130 * @param {*} var_args Additional arguments to pass through to the function. |
| 131 * @return {ChromeVoxUnitTestBase} this. |
| 132 */ |
| 133 waitForCalm: function(func, var_args) { |
| 134 var me = this; |
| 135 var calmArguments = Array.prototype.slice.call(arguments); |
| 136 calmArguments.shift(); |
| 137 cvox.ChromeVoxEventWatcher.addReadyCallback(function() { |
| 138 func.apply(me, calmArguments); |
| 139 }); |
| 140 return this; // for chaining. |
| 141 }, |
| 142 |
| 143 /** |
| 144 * Asserts a list of utterances are in the correct queue mode. |
| 145 * @param {cvox.SpokenListBuilder|Array} expectedList A list |
| 146 * of [text, queueMode] tuples OR a SpokenListBuilder with the expected |
| 147 * utterances. |
| 148 * @return {ChromeVoxUnitTestBase} this. |
| 149 */ |
| 150 assertSpokenList: function(expectedList) { |
| 151 if (expectedList instanceof cvox.SpokenListBuilder) { |
| 152 expectedList = expectedList.build(); |
| 153 } |
| 154 |
| 155 var ulist = cvox.ChromeVoxTester.testTts().getUtteranceInfoList(); |
| 156 for (var i = 0; i < expectedList.length; i++) { |
| 157 var text = expectedList[i][0]; |
| 158 var queueMode = expectedList[i][1]; |
| 159 this.assertSingleUtterance_(text, queueMode, |
| 160 ulist[i].text, ulist[i].queueMode); |
| 161 } |
| 162 cvox.ChromeVoxTester.clearUtterances(); |
| 163 return this; // for chaining. |
| 164 }, |
| 165 |
| 166 assertSingleUtterance_: function( |
| 167 expectedText, expectedQueueMode, text, queueMode) { |
| 168 assertEquals(expectedQueueMode, queueMode); |
| 169 assertEquals(expectedText, text); |
122 } | 170 } |
123 }; | 171 }; |
OLD | NEW |