1 // Copyright (c) 2011 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.
5 // TTS api test for Chrome on ChromeOS.
6 // browser_tests.exe --gtest_filter="TtsApiTest.*"
9 function testNoListeners() {
10 // This call should go to native speech because we haven't registered
15 'onEvent': function(event
) {
16 if (event
.type
== 'end') {
17 chrome
.test
.succeed();
21 chrome
.test
.assertNoLastError();
24 function testTtsEngine() {
25 var calledOurEngine
= false;
27 // Register listeners for speech functions, enabling this extension
28 // to be a TTS engine.
29 var speakListener = function(utterance
, options
, sendTtsEvent
) {
30 chrome
.test
.assertNoLastError();
31 chrome
.test
.assertEq('extension speech', utterance
);
32 calledOurEngine
= true;
33 sendTtsEvent({'type': 'end', 'charIndex': utterance
.length
});
35 var stopListener = function() {};
36 chrome
.ttsEngine
.onSpeak
.addListener(speakListener
);
37 chrome
.ttsEngine
.onStop
.addListener(stopListener
);
39 // This call should go to our own speech engine.
43 'onEvent': function(event
) {
44 if (event
.type
== 'end') {
45 chrome
.test
.assertEq(true, calledOurEngine
);
46 chrome
.ttsEngine
.onSpeak
.removeListener(speakListener
);
47 chrome
.ttsEngine
.onStop
.removeListener(stopListener
);
48 chrome
.test
.succeed();
53 chrome
.test
.assertNoLastError();
56 function testVoiceMatching() {
57 // Count the number of times our callback functions have been called.
59 // Count the number of times our TTS engine has been called.
60 var speakListenerCalls
= 0;
62 // Register listeners for speech functions.
63 var speakListener = function(utterance
, options
, sendTtsEvent
) {
65 sendTtsEvent({'type': 'end', 'charIndex': utterance
.length
});
67 var stopListener = function() {};
68 chrome
.ttsEngine
.onSpeak
.addListener(speakListener
);
69 chrome
.ttsEngine
.onStop
.addListener(stopListener
);
71 // These don't match the voices in the manifest, so they should
72 // go to native speech. The gmock assertions in TtsApiTest::RegisterEngine
73 // enforce that the native TTS handlers are called.
77 'voiceName': 'George',
79 'onEvent': function(event
) {
80 if (event
.type
== 'end') {
85 chrome
.test
.assertNoLastError();
92 'onEvent': function(event
) {
93 if (event
.type
== 'end') {
98 chrome
.test
.assertNoLastError();
101 // These do match the voices in the manifest, so they should go to our
104 'extension speech 2',
106 'voiceName': 'Alice',
108 'onEvent': function(event
) {
109 if (event
.type
== 'end') {
114 chrome
.test
.assertNoLastError();
117 'extension speech 3',
122 'onEvent': function(event
) {
123 if (event
.type
== 'end') {
125 chrome
.ttsEngine
.onSpeak
.removeListener(speakListener
);
126 chrome
.ttsEngine
.onStop
.removeListener(stopListener
);
127 if (callbacks
== 4 && speakListenerCalls
== 2) {
128 chrome
.test
.succeed();
133 chrome
.test
.assertNoLastError();
136 function testGetVoices() {
137 // We have to register listeners, or the voices provided
138 // by this extension won't be returned.
139 var speakListener = function(utterance
, options
, sendTtsEvent
) {
140 chrome
.test
.assertNoLastError();
141 chrome
.test
.assertEq('extension speech', utterance
);
142 sendTtsEvent({'type': 'end', 'charIndex': utterance
.length
});
144 var stopListener = function() {};
145 chrome
.ttsEngine
.onSpeak
.addListener(speakListener
);
146 chrome
.ttsEngine
.onStop
.addListener(stopListener
);
148 chrome
.tts
.getVoices(function(voices
) {
149 chrome
.test
.assertEq(3, voices
.length
);
151 chrome
.test
.assertEq('Alice', voices
[0].voiceName
);
152 chrome
.test
.assertEq('en-US', voices
[0].lang
);
153 chrome
.test
.assertEq('female', voices
[0].gender
);
155 chrome
.test
.assertEq('Pat', voices
[1].voiceName
);
156 chrome
.test
.assertEq('en-US', voices
[1].lang
);
158 chrome
.test
.assertEq('TestNativeVoice', voices
[2].voiceName
);
159 chrome
.test
.assertEq('en-GB', voices
[2].lang
);
160 chrome
.test
.succeed();