| 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 // Include test fixture. | 5 // Include test fixture. |
| 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']); | 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']); |
| 7 | 7 |
| 8 GEN_INCLUDE(['../../testing/mock_tts.js']); | 8 GEN_INCLUDE(['../../testing/mock_tts.js']); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Test fixture for Background. | 11 * Test fixture for Background. |
| 12 * @constructor | 12 * @constructor |
| 13 * @extends {ChromeVoxNextE2ETest} | 13 * @extends {ChromeVoxNextE2ETest} |
| 14 */ | 14 */ |
| 15 function BackgroundTest() {} | 15 function BackgroundTest() {} |
| 16 | 16 |
| 17 BackgroundTest.prototype = { | 17 BackgroundTest.prototype = { |
| 18 __proto__: ChromeVoxNextE2ETest.prototype, | 18 __proto__: ChromeVoxNextE2ETest.prototype, |
| 19 | 19 |
| 20 /** @override */ | 20 /** @override */ |
| 21 setUp: function() { | 21 setUp: function() { |
| 22 this.mockTts = new MockTts(); | 22 this.mockTts = new MockTts(); |
| 23 cvox.ChromeVox.tts = this.mockTts; | 23 cvox.ChromeVox.tts = this.mockTts; |
| 24 } | 24 }, |
| 25 |
| 26 /** |
| 27 * Create a function which perform the command |cmd|. |
| 28 * @param {string} cmd |
| 29 * @return {function() : void} |
| 30 */ |
| 31 doCmd: function(cmd) { |
| 32 return function() { |
| 33 global.backgroundObj.onGotCommand(cmd); |
| 34 }; |
| 35 }, |
| 36 |
| 37 linksAndHeadingsDoc: function() {/*! |
| 38 <p>start</p> |
| 39 <a href='#a'>alpha</a> |
| 40 <a href='#b'>beta</a> |
| 41 <p> |
| 42 <h1>charlie</h1> |
| 43 <a href='foo'>delta</a> |
| 44 </p> |
| 45 <a href='#bar'>echo</a> |
| 46 <h2>foxtraut</h2> |
| 47 <p>end<span>of test</span></p> |
| 48 */} |
| 25 }; | 49 }; |
| 26 | 50 |
| 27 /** Tests that ChromeVox classic is in this context. */ | 51 /** Tests that ChromeVox classic is in this context. */ |
| 28 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { | 52 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { |
| 29 assertEquals('object', typeof(cvox)); | 53 assertEquals('object', typeof(cvox)); |
| 30 assertEquals('function', typeof(cvox.ChromeVoxBackground)); | 54 assertEquals('function', typeof(cvox.ChromeVoxBackground)); |
| 31 }); | 55 }); |
| 32 | 56 |
| 33 /** Tests that ChromeVox next is in this context. */ | 57 /** Tests that ChromeVox next is in this context. */ |
| 34 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { | 58 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 function() { | 91 function() { |
| 68 cvox.ChromeVox.tts.expectSpeech('start', function() { | 92 cvox.ChromeVox.tts.expectSpeech('start', function() { |
| 69 global.backgroundObj.onGotCommand('nextLine'); | 93 global.backgroundObj.onGotCommand('nextLine'); |
| 70 }); | 94 }); |
| 71 cvox.ChromeVox.tts.expectSpeech('end', testDone); | 95 cvox.ChromeVox.tts.expectSpeech('end', testDone); |
| 72 }.bind(this)); | 96 }.bind(this)); |
| 73 }); | 97 }); |
| 74 | 98 |
| 75 /** Tests consistency of navigating forward and backward. */ | 99 /** Tests consistency of navigating forward and backward. */ |
| 76 TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() { | 100 TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() { |
| 77 this.runWithDocument(function() {/*! | 101 this.runWithDocument(this.linksAndHeadingsDoc, function() { |
| 78 <p>start</p> | 102 var doCmd = this.doCmd.bind(this); |
| 79 <a href='#a'>alpha</a> | 103 var expectAfter = |
| 80 <a href='#b'>beta</a> | 104 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts); |
| 81 <p> | |
| 82 <h1>charlie</h1> | |
| 83 <a href='foo'>delta</a> | |
| 84 </p> | |
| 85 <a href='#bar'>echo</a> | |
| 86 <h2>foxtraut</h2> | |
| 87 <p>end<span>of test</span></p> | |
| 88 */}, | |
| 89 function() { | |
| 90 var doCmd = function(cmd) { | |
| 91 return function() { | |
| 92 global.backgroundObj.onGotCommand(cmd); | |
| 93 }; | |
| 94 }; | |
| 95 | 105 |
| 96 var expectAfter = | 106 cvox.ChromeVox.tts.expectSpeech('start'); |
| 97 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts); | 107 expectAfter('alpha', doCmd('nextLink')); |
| 108 expectAfter('beta', doCmd('nextLink')); |
| 109 expectAfter('delta', doCmd('nextLink')); |
| 110 expectAfter('beta', doCmd('previousLink')); |
| 98 | 111 |
| 99 cvox.ChromeVox.tts.expectSpeech('start'); | 112 expectAfter('charlie', doCmd('nextHeading')); |
| 100 expectAfter('alpha', doCmd('nextLink')); | 113 expectAfter('foxtraut', doCmd('nextHeading')); |
| 101 expectAfter('beta', doCmd('nextLink')); | 114 expectAfter('charlie', doCmd('previousHeading')); |
| 102 expectAfter('delta', doCmd('nextLink')); | |
| 103 expectAfter('beta', doCmd('previousLink')); | |
| 104 | 115 |
| 105 expectAfter('charlie', doCmd('nextHeading')); | 116 expectAfter('delta', doCmd('nextElement')); |
| 106 expectAfter('foxtraut', doCmd('nextHeading')); | 117 expectAfter('echo', doCmd('nextElement')); |
| 107 expectAfter('charlie', doCmd('previousHeading')); | 118 expectAfter('foxtraut', doCmd('nextElement')); |
| 119 expectAfter('end', doCmd('nextElement')); |
| 120 expectAfter('foxtraut', doCmd('previousElement')); |
| 108 | 121 |
| 109 expectAfter('delta', doCmd('nextElement')); | 122 // TODO(dtseng): cleanup these utterances. |
| 110 expectAfter('echo', doCmd('nextElement')); | 123 expectAfter(', end, paragraph, of test, paragraph', doCmd('nextLine')); |
| 111 expectAfter('foxtraut', doCmd('nextElement')); | |
| 112 expectAfter('end', doCmd('nextElement')); | |
| 113 expectAfter('foxtraut', doCmd('previousElement')); | |
| 114 | 124 |
| 115 // TODO(dtseng): cleanup these utterances. | 125 expectAfter('start', doCmd('goToBeginning')); |
| 116 expectAfter(', end, paragraph, of test, paragraph', doCmd('nextLine')); | 126 expectAfter('of test', doCmd('goToEnd')); |
| 117 | 127 |
| 118 expectAfter('start', doCmd('goToBeginning')); | 128 cvox.ChromeVox.tts.finishExpectations(); |
| 119 expectAfter('of test', doCmd('goToEnd')); | 129 }.bind(this) |
| 130 ); |
| 131 }); |
| 120 | 132 |
| 121 cvox.ChromeVox.tts.finishExpectations(); | 133 TEST_F('BackgroundTest', 'CaretNavigation', function() { |
| 134 this.runWithDocument(this.linksAndHeadingsDoc, function() { |
| 135 var doCmd = this.doCmd.bind(this); |
| 136 var expectAfter = |
| 137 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts); |
| 138 |
| 139 cvox.ChromeVox.tts.expectSpeech('start'); |
| 140 expectAfter('t', doCmd('nextCharacter'), true); |
| 141 expectAfter('a', doCmd('nextCharacter'), true); |
| 142 expectAfter('alpha', doCmd('nextWord'), true); |
| 143 expectAfter('beta', doCmd('nextWord'), true); |
| 144 expectAfter('charlie', doCmd('nextWord'), true); |
| 145 expectAfter('delta', doCmd('nextLine'), true); |
| 146 expectAfter('echo', doCmd('nextLine'), true); |
| 147 expectAfter('foxtraut', doCmd('nextLine'), true); |
| 148 expectAfter( |
| 149 ', end, paragraph, of test, paragraph', doCmd('nextLine'), true); |
| 150 expectAfter('n', doCmd('nextCharacter'), true); |
| 151 expectAfter('e', doCmd('previousCharacter'), true); |
| 152 expectAfter('t', doCmd('previousCharacter'), true); |
| 153 expectAfter('foxtraut', doCmd('previousWord'), true); |
| 154 expectAfter('echo', doCmd('previousWord'), true); |
| 155 expectAfter('a', doCmd('previousCharacter'), true); |
| 156 expectAfter('t', doCmd('previousCharacter'), true); |
| 157 expectAfter('echo', doCmd('nextWord'), true); |
| 158 |
| 159 cvox.ChromeVox.tts.finishExpectations(); |
| 122 }.bind(this)); | 160 }.bind(this)); |
| 123 }); | 161 }); |
| OLD | NEW |