Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/speech/extension_api/tts_extension_apitest.cc

Issue 15108002: Add Pause and Resume to Web TTS & Extension TTS APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/speech/tts_controller.h" 11 #include "chrome/browser/speech/tts_controller.h"
12 #include "chrome/browser/speech/tts_platform.h" 12 #include "chrome/browser/speech/tts_platform.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 // Needed for CreateFunctor. 17 // Needed for CreateFunctor.
18 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING 18 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
19 #include "testing/gmock_mutant.h" 19 #include "testing/gmock_mutant.h"
20 20
21 using ::testing::AnyNumber; 21 using ::testing::AnyNumber;
22 using ::testing::CreateFunctor; 22 using ::testing::CreateFunctor;
23 using ::testing::DoAll; 23 using ::testing::DoAll;
24 using ::testing::InSequence; 24 using ::testing::InSequence;
25 using ::testing::InvokeWithoutArgs; 25 using ::testing::InvokeWithoutArgs;
26 using ::testing::Return; 26 using ::testing::Return;
27 using ::testing::SaveArg;
27 using ::testing::StrictMock; 28 using ::testing::StrictMock;
28 using ::testing::_; 29 using ::testing::_;
29 30
31 namespace {
32 int g_saved_utterance_id;
33 }
34
30 class MockTtsPlatformImpl : public TtsPlatformImpl { 35 class MockTtsPlatformImpl : public TtsPlatformImpl {
31 public: 36 public:
32 MockTtsPlatformImpl() 37 MockTtsPlatformImpl()
33 : ptr_factory_(this) {} 38 : ptr_factory_(this) {}
34 39
35 virtual bool PlatformImplAvailable() { 40 virtual bool PlatformImplAvailable() {
36 return true; 41 return true;
37 } 42 }
38 43
39 MOCK_METHOD5(Speak, 44 MOCK_METHOD5(Speak,
40 bool(int utterance_id, 45 bool(int utterance_id,
41 const std::string& utterance, 46 const std::string& utterance,
42 const std::string& lang, 47 const std::string& lang,
43 const VoiceData& voice, 48 const VoiceData& voice,
44 const UtteranceContinuousParameters& params)); 49 const UtteranceContinuousParameters& params));
45 50
46 MOCK_METHOD0(StopSpeaking, bool(void)); 51 MOCK_METHOD0(StopSpeaking, bool(void));
47 52
53 MOCK_METHOD0(Pause, void(void));
54
55 MOCK_METHOD0(Resume, void(void));
56
48 MOCK_METHOD0(IsSpeaking, bool(void)); 57 MOCK_METHOD0(IsSpeaking, bool(void));
49 58
50 MOCK_METHOD1(GetVoices, void(std::vector<VoiceData>*)); 59 MOCK_METHOD1(GetVoices, void(std::vector<VoiceData>*));
51 60
52 void SetErrorToEpicFail() { 61 void SetErrorToEpicFail() {
53 set_error("epic fail"); 62 set_error("epic fail");
54 } 63 }
55 64
65 void SendEndEventOnSavedUtteranceId() {
66 MessageLoop::current()->PostDelayedTask(
67 FROM_HERE, base::Bind(
68 &MockTtsPlatformImpl::SendEvent,
69 ptr_factory_.GetWeakPtr(),
70 false, g_saved_utterance_id, TTS_EVENT_END, 0, std::string()),
71 base::TimeDelta());
72 }
73
56 void SendEndEvent(int utterance_id, 74 void SendEndEvent(int utterance_id,
57 const std::string& utterance, 75 const std::string& utterance,
58 const std::string& lang, 76 const std::string& lang,
59 const VoiceData& voice, 77 const VoiceData& voice,
60 const UtteranceContinuousParameters& params) { 78 const UtteranceContinuousParameters& params) {
61 base::MessageLoop::current()->PostDelayedTask( 79 base::MessageLoop::current()->PostDelayedTask(
62 FROM_HERE, base::Bind( 80 FROM_HERE, base::Bind(
63 &MockTtsPlatformImpl::SendEvent, 81 &MockTtsPlatformImpl::SendEvent,
64 ptr_factory_.GetWeakPtr(), 82 ptr_factory_.GetWeakPtr(),
65 false, utterance_id, TTS_EVENT_END, utterance.size(), 83 false, utterance_id, TTS_EVENT_END, utterance.size(),
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_CALL(mock_platform_impl_, Speak(_, "one two three", _, _, _)) 287 EXPECT_CALL(mock_platform_impl_, Speak(_, "one two three", _, _, _))
270 .WillOnce(DoAll( 288 .WillOnce(DoAll(
271 Invoke(&mock_platform_impl_, 289 Invoke(&mock_platform_impl_,
272 &MockTtsPlatformImpl::SendWordEvents), 290 &MockTtsPlatformImpl::SendWordEvents),
273 Invoke(&mock_platform_impl_, 291 Invoke(&mock_platform_impl_,
274 &MockTtsPlatformImpl::SendEndEvent), 292 &MockTtsPlatformImpl::SendEndEvent),
275 Return(true))); 293 Return(true)));
276 ASSERT_TRUE(RunExtensionTest("tts/word_callbacks")) << message_; 294 ASSERT_TRUE(RunExtensionTest("tts/word_callbacks")) << message_;
277 } 295 }
278 296
297 IN_PROC_BROWSER_TEST_F(TtsApiTest, PlatformPauseResume) {
298 EXPECT_CALL(mock_platform_impl_, IsSpeaking())
299 .Times(AnyNumber());
300
301 InSequence s;
302 EXPECT_CALL(mock_platform_impl_, Speak(_, "test 1", _, _, _))
303 .WillOnce(DoAll(
304 Invoke(&mock_platform_impl_,
305 &MockTtsPlatformImpl::SendEndEvent),
306 Return(true)));
307 EXPECT_CALL(mock_platform_impl_, StopSpeaking())
308 .WillOnce(Return(true));
309 EXPECT_CALL(mock_platform_impl_, Speak(_, "test 2", _, _, _))
310 .WillOnce(DoAll(
311 SaveArg<0>(&g_saved_utterance_id),
312 Return(true)));
313 EXPECT_CALL(mock_platform_impl_, Pause());
314 EXPECT_CALL(mock_platform_impl_, Resume())
315 .WillOnce(
316 InvokeWithoutArgs(
317 &mock_platform_impl_,
318 &MockTtsPlatformImpl::SendEndEventOnSavedUtteranceId));
319 ASSERT_TRUE(RunExtensionTest("tts/pause_resume")) << message_;
320 }
321
322 //
323 // TTS Engine tests.
324 //
325
279 IN_PROC_BROWSER_TEST_F(TtsApiTest, RegisterEngine) { 326 IN_PROC_BROWSER_TEST_F(TtsApiTest, RegisterEngine) {
280 EXPECT_CALL(mock_platform_impl_, IsSpeaking()) 327 EXPECT_CALL(mock_platform_impl_, IsSpeaking())
281 .Times(AnyNumber()); 328 .Times(AnyNumber());
282 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) 329 EXPECT_CALL(mock_platform_impl_, StopSpeaking())
283 .WillRepeatedly(Return(true)); 330 .WillRepeatedly(Return(true));
284 331
285 { 332 {
286 InSequence s; 333 InSequence s;
287 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech", _, _, _)) 334 EXPECT_CALL(mock_platform_impl_, Speak(_, "native speech", _, _, _))
288 .WillOnce(DoAll( 335 .WillOnce(DoAll(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) 372 EXPECT_CALL(mock_platform_impl_, StopSpeaking())
326 .WillRepeatedly(Return(true)); 373 .WillRepeatedly(Return(true));
327 374
328 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_; 375 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_;
329 } 376 }
330 377
331 // http://crbug.com/122474 378 // http://crbug.com/122474
332 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { 379 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) {
333 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; 380 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_;
334 } 381 }
OLDNEW
« no previous file with comments | « chrome/browser/speech/extension_api/tts_extension_api_constants.cc ('k') | chrome/browser/speech/tts_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698