| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/speech/extension_api/tts_extension_api.h" | 10 #include "chrome/browser/speech/extension_api/tts_extension_api.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 MOCK_METHOD4(Speak, | 45 MOCK_METHOD4(Speak, |
| 46 bool(int utterance_id, | 46 bool(int utterance_id, |
| 47 const std::string& utterance, | 47 const std::string& utterance, |
| 48 const std::string& lang, | 48 const std::string& lang, |
| 49 const UtteranceContinuousParameters& params)); | 49 const UtteranceContinuousParameters& params)); |
| 50 MOCK_METHOD0(StopSpeaking, bool(void)); | 50 MOCK_METHOD0(StopSpeaking, bool(void)); |
| 51 | 51 |
| 52 MOCK_METHOD0(IsSpeaking, bool(void)); |
| 53 |
| 52 void SetErrorToEpicFail() { | 54 void SetErrorToEpicFail() { |
| 53 set_error("epic fail"); | 55 set_error("epic fail"); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void SendEndEvent(int utterance_id, | 58 void SendEndEvent(int utterance_id, |
| 57 const std::string& utterance, | 59 const std::string& utterance, |
| 58 const std::string& lang, | 60 const std::string& lang, |
| 59 const UtteranceContinuousParameters& params) { | 61 const UtteranceContinuousParameters& params) { |
| 60 MessageLoop::current()->PostDelayedTask( | 62 MessageLoop::current()->PostDelayedTask( |
| 61 FROM_HERE, base::Bind( | 63 FROM_HERE, base::Bind( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 127 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 126 ExtensionTtsController::GetInstance()->SetPlatformImpl( | 128 ExtensionTtsController::GetInstance()->SetPlatformImpl( |
| 127 &mock_platform_impl_); | 129 &mock_platform_impl_); |
| 128 } | 130 } |
| 129 | 131 |
| 130 protected: | 132 protected: |
| 131 StrictMock<MockExtensionTtsPlatformImpl> mock_platform_impl_; | 133 StrictMock<MockExtensionTtsPlatformImpl> mock_platform_impl_; |
| 132 }; | 134 }; |
| 133 | 135 |
| 134 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakOptionalArgs) { | 136 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakOptionalArgs) { |
| 137 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 138 |
| 135 InSequence s; | 139 InSequence s; |
| 136 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 140 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 137 .WillOnce(Return(true)); | 141 .WillOnce(Return(true)); |
| 138 EXPECT_CALL(mock_platform_impl_, Speak(_, "", _, _)) | 142 EXPECT_CALL(mock_platform_impl_, Speak(_, "", _, _)) |
| 139 .WillOnce(Return(true)); | 143 .WillOnce(Return(true)); |
| 140 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 144 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 141 .WillOnce(Return(true)); | 145 .WillOnce(Return(true)); |
| 142 EXPECT_CALL(mock_platform_impl_, Speak(_, "Alpha", _, _)) | 146 EXPECT_CALL(mock_platform_impl_, Speak(_, "Alpha", _, _)) |
| 143 .WillOnce(Return(true)); | 147 .WillOnce(Return(true)); |
| 144 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 148 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 145 .WillOnce(Return(true)); | 149 .WillOnce(Return(true)); |
| 146 EXPECT_CALL(mock_platform_impl_, Speak(_, "Bravo", _, _)) | 150 EXPECT_CALL(mock_platform_impl_, Speak(_, "Bravo", _, _)) |
| 147 .WillOnce(Return(true)); | 151 .WillOnce(Return(true)); |
| 148 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 152 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 149 .WillOnce(Return(true)); | 153 .WillOnce(Return(true)); |
| 150 EXPECT_CALL(mock_platform_impl_, Speak(_, "Charlie", _, _)) | 154 EXPECT_CALL(mock_platform_impl_, Speak(_, "Charlie", _, _)) |
| 151 .WillOnce(Return(true)); | 155 .WillOnce(Return(true)); |
| 152 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 156 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 153 .WillOnce(Return(true)); | 157 .WillOnce(Return(true)); |
| 154 EXPECT_CALL(mock_platform_impl_, Speak(_, "Echo", _, _)) | 158 EXPECT_CALL(mock_platform_impl_, Speak(_, "Echo", _, _)) |
| 155 .WillOnce(Return(true)); | 159 .WillOnce(Return(true)); |
| 156 ASSERT_TRUE(RunExtensionTest("tts/optional_args")) << message_; | 160 ASSERT_TRUE(RunExtensionTest("tts/optional_args")) << message_; |
| 157 } | 161 } |
| 158 | 162 |
| 159 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakFinishesImmediately) { | 163 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakFinishesImmediately) { |
| 160 InSequence s; | 164 InSequence s; |
| 165 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 161 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 166 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 162 .WillOnce(Return(true)); | 167 .WillOnce(Return(true)); |
| 163 EXPECT_CALL(mock_platform_impl_, Speak(_, _, _, _)) | 168 EXPECT_CALL(mock_platform_impl_, Speak(_, _, _, _)) |
| 164 .WillOnce(DoAll( | 169 .WillOnce(DoAll( |
| 165 Invoke(&mock_platform_impl_, | 170 Invoke(&mock_platform_impl_, |
| 166 &MockExtensionTtsPlatformImpl::SendEndEvent), | 171 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 167 Return(true))); | 172 Return(true))); |
| 168 ASSERT_TRUE(RunExtensionTest("tts/speak_once")) << message_; | 173 ASSERT_TRUE(RunExtensionTest("tts/speak_once")) << message_; |
| 169 } | 174 } |
| 170 | 175 |
| 171 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakInterrupt) { | 176 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakInterrupt) { |
| 177 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 178 |
| 172 // One utterance starts speaking, and then a second interrupts. | 179 // One utterance starts speaking, and then a second interrupts. |
| 173 InSequence s; | 180 InSequence s; |
| 174 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 181 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 175 .WillOnce(Return(true)); | 182 .WillOnce(Return(true)); |
| 176 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 1", _, _)) | 183 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 1", _, _)) |
| 177 .WillOnce(Return(true)); | 184 .WillOnce(Return(true)); |
| 178 // Expect the second utterance and allow it to finish. | 185 // Expect the second utterance and allow it to finish. |
| 179 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 186 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 180 .WillOnce(Return(true)); | 187 .WillOnce(Return(true)); |
| 181 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 2", _, _)) | 188 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 2", _, _)) |
| 182 .WillOnce(DoAll( | 189 .WillOnce(DoAll( |
| 183 Invoke(&mock_platform_impl_, | 190 Invoke(&mock_platform_impl_, |
| 184 &MockExtensionTtsPlatformImpl::SendEndEvent), | 191 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 185 Return(true))); | 192 Return(true))); |
| 186 ASSERT_TRUE(RunExtensionTest("tts/interrupt")) << message_; | 193 ASSERT_TRUE(RunExtensionTest("tts/interrupt")) << message_; |
| 187 } | 194 } |
| 188 | 195 |
| 189 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakQueueInterrupt) { | 196 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakQueueInterrupt) { |
| 197 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 198 |
| 190 // In this test, two utterances are queued, and then a third | 199 // In this test, two utterances are queued, and then a third |
| 191 // interrupts. Speak() never gets called on the second utterance. | 200 // interrupts. Speak() never gets called on the second utterance. |
| 192 InSequence s; | 201 InSequence s; |
| 193 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 202 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 194 .WillOnce(Return(true)); | 203 .WillOnce(Return(true)); |
| 195 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 1", _, _)) | 204 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 1", _, _)) |
| 196 .WillOnce(Return(true)); | 205 .WillOnce(Return(true)); |
| 197 // Don't expect the second utterance, because it's queued up and the | 206 // Don't expect the second utterance, because it's queued up and the |
| 198 // first never finishes. | 207 // first never finishes. |
| 199 // Expect the third utterance and allow it to finish successfully. | 208 // Expect the third utterance and allow it to finish successfully. |
| 200 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 209 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 201 .WillOnce(Return(true)); | 210 .WillOnce(Return(true)); |
| 202 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 3", _, _)) | 211 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 3", _, _)) |
| 203 .WillOnce(DoAll( | 212 .WillOnce(DoAll( |
| 204 Invoke(&mock_platform_impl_, | 213 Invoke(&mock_platform_impl_, |
| 205 &MockExtensionTtsPlatformImpl::SendEndEvent), | 214 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 206 Return(true))); | 215 Return(true))); |
| 207 ASSERT_TRUE(RunExtensionTest("tts/queue_interrupt")) << message_; | 216 ASSERT_TRUE(RunExtensionTest("tts/queue_interrupt")) << message_; |
| 208 } | 217 } |
| 209 | 218 |
| 210 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakEnqueue) { | 219 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakEnqueue) { |
| 220 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 221 |
| 211 InSequence s; | 222 InSequence s; |
| 212 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 223 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 213 .WillOnce(Return(true)); | 224 .WillOnce(Return(true)); |
| 214 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 1", _, _)) | 225 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 1", _, _)) |
| 215 .WillOnce(DoAll( | 226 .WillOnce(DoAll( |
| 216 Invoke(&mock_platform_impl_, | 227 Invoke(&mock_platform_impl_, |
| 217 &MockExtensionTtsPlatformImpl::SendEndEventWhenQueueNotEmpty), | 228 &MockExtensionTtsPlatformImpl::SendEndEventWhenQueueNotEmpty), |
| 218 Return(true))); | 229 Return(true))); |
| 219 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 2", _, _)) | 230 EXPECT_CALL(mock_platform_impl_, Speak(_, "text 2", _, _)) |
| 220 .WillOnce(DoAll( | 231 .WillOnce(DoAll( |
| 221 Invoke(&mock_platform_impl_, | 232 Invoke(&mock_platform_impl_, |
| 222 &MockExtensionTtsPlatformImpl::SendEndEvent), | 233 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 223 Return(true))); | 234 Return(true))); |
| 224 ASSERT_TRUE(RunExtensionTest("tts/enqueue")) << message_; | 235 ASSERT_TRUE(RunExtensionTest("tts/enqueue")) << message_; |
| 225 } | 236 } |
| 226 | 237 |
| 227 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakError) { | 238 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformSpeakError) { |
| 239 EXPECT_CALL(mock_platform_impl_, IsSpeaking()) |
| 240 .Times(AnyNumber()); |
| 241 |
| 228 InSequence s; | 242 InSequence s; |
| 229 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 243 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 230 .WillOnce(Return(true)); | 244 .WillOnce(Return(true)); |
| 231 EXPECT_CALL(mock_platform_impl_, Speak(_, "first try", _, _)) | 245 EXPECT_CALL(mock_platform_impl_, Speak(_, "first try", _, _)) |
| 232 .WillOnce(DoAll( | 246 .WillOnce(DoAll( |
| 233 InvokeWithoutArgs( | 247 InvokeWithoutArgs( |
| 234 CreateFunctor(&mock_platform_impl_, | 248 CreateFunctor(&mock_platform_impl_, |
| 235 &MockExtensionTtsPlatformImpl::SetErrorToEpicFail)), | 249 &MockExtensionTtsPlatformImpl::SetErrorToEpicFail)), |
| 236 Return(false))); | 250 Return(false))); |
| 237 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 251 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 238 .WillOnce(Return(true)); | 252 .WillOnce(Return(true)); |
| 239 EXPECT_CALL(mock_platform_impl_, Speak(_, "second try", _, _)) | 253 EXPECT_CALL(mock_platform_impl_, Speak(_, "second try", _, _)) |
| 240 .WillOnce(DoAll( | 254 .WillOnce(DoAll( |
| 241 Invoke(&mock_platform_impl_, | 255 Invoke(&mock_platform_impl_, |
| 242 &MockExtensionTtsPlatformImpl::SendEndEvent), | 256 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 243 Return(true))); | 257 Return(true))); |
| 244 ASSERT_TRUE(RunExtensionTest("tts/speak_error")) << message_; | 258 ASSERT_TRUE(RunExtensionTest("tts/speak_error")) << message_; |
| 245 } | 259 } |
| 246 | 260 |
| 247 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformWordCallbacks) { | 261 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformWordCallbacks) { |
| 262 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 263 |
| 248 InSequence s; | 264 InSequence s; |
| 249 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 265 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 250 .WillOnce(Return(true)); | 266 .WillOnce(Return(true)); |
| 251 EXPECT_CALL(mock_platform_impl_, Speak(_, "one two three", _, _)) | 267 EXPECT_CALL(mock_platform_impl_, Speak(_, "one two three", _, _)) |
| 252 .WillOnce(DoAll( | 268 .WillOnce(DoAll( |
| 253 Invoke(&mock_platform_impl_, | 269 Invoke(&mock_platform_impl_, |
| 254 &MockExtensionTtsPlatformImpl::SendWordEvents), | 270 &MockExtensionTtsPlatformImpl::SendWordEvents), |
| 255 Invoke(&mock_platform_impl_, | 271 Invoke(&mock_platform_impl_, |
| 256 &MockExtensionTtsPlatformImpl::SendEndEvent), | 272 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 257 Return(true))); | 273 Return(true))); |
| 258 ASSERT_TRUE(RunExtensionTest("tts/word_callbacks")) << message_; | 274 ASSERT_TRUE(RunExtensionTest("tts/word_callbacks")) << message_; |
| 259 } | 275 } |
| 260 | 276 |
| 261 IN_PROC_BROWSER_TEST_F(TtsApiTest, RegisterEngine) { | 277 IN_PROC_BROWSER_TEST_F(TtsApiTest, RegisterEngine) { |
| 278 EXPECT_CALL(mock_platform_impl_, IsSpeaking()) |
| 279 .Times(AnyNumber()); |
| 262 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 280 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 263 .WillRepeatedly(Return(true)); | 281 .WillRepeatedly(Return(true)); |
| 264 | 282 |
| 265 { | 283 { |
| 266 InSequence s; | 284 InSequence s; |
| 267 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech", _, _)) | 285 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech", _, _)) |
| 268 .WillOnce(DoAll( | 286 .WillOnce(DoAll( |
| 269 Invoke(&mock_platform_impl_, | 287 Invoke(&mock_platform_impl_, |
| 270 &MockExtensionTtsPlatformImpl::SendEndEvent), | 288 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 271 Return(true))); | 289 Return(true))); |
| 272 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech 2", _, _)) | 290 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech 2", _, _)) |
| 273 .WillOnce(DoAll( | 291 .WillOnce(DoAll( |
| 274 Invoke(&mock_platform_impl_, | 292 Invoke(&mock_platform_impl_, |
| 275 &MockExtensionTtsPlatformImpl::SendEndEvent), | 293 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 276 Return(true))); | 294 Return(true))); |
| 277 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech 3", _, _)) | 295 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech 3", _, _)) |
| 278 .WillOnce(DoAll( | 296 .WillOnce(DoAll( |
| 279 Invoke(&mock_platform_impl_, | 297 Invoke(&mock_platform_impl_, |
| 280 &MockExtensionTtsPlatformImpl::SendEndEvent), | 298 &MockExtensionTtsPlatformImpl::SendEndEvent), |
| 281 Return(true))); | 299 Return(true))); |
| 282 } | 300 } |
| 283 | 301 |
| 284 ASSERT_TRUE(RunExtensionTest("tts_engine/register_engine")) << message_; | 302 ASSERT_TRUE(RunExtensionTest("tts_engine/register_engine")) << message_; |
| 285 } | 303 } |
| 286 | 304 |
| 287 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineError) { | 305 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineError) { |
| 306 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 288 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 307 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 289 .WillRepeatedly(Return(true)); | 308 .WillRepeatedly(Return(true)); |
| 290 | 309 |
| 291 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_error")) << message_; | 310 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_error")) << message_; |
| 292 } | 311 } |
| 293 | 312 |
| 294 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineWordCallbacks) { | 313 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineWordCallbacks) { |
| 314 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); |
| 295 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 315 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 296 .WillRepeatedly(Return(true)); | 316 .WillRepeatedly(Return(true)); |
| 297 | 317 |
| 298 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_word_callbacks")) << message_; | 318 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_word_callbacks")) << message_; |
| 299 } | 319 } |
| 300 | 320 |
| 301 // http://crbug.com/122474 | 321 // http://crbug.com/122474 |
| 302 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { | 322 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { |
| 303 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; | 323 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; |
| 304 } | 324 } |
| OLD | NEW |