| 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 // Unit tests for the TTS Controller. | 5 // Unit tests for the TTS Controller. |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/speech/tts_controller_impl.h" | 8 #include "chrome/browser/speech/tts_controller_impl.h" |
| 9 #include "chrome/browser/speech/tts_platform.h" | 9 #include "chrome/browser/speech/tts_platform.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 class TtsApiControllerTest : public testing::Test { | 12 class TtsApiControllerTest : public testing::Test { |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 // Platform Tts implementation that does nothing. | 15 // Platform Tts implementation that does nothing. |
| 16 class DummyTtsPlatformImpl : public TtsPlatformImpl { | 16 class DummyTtsPlatformImpl : public TtsPlatformImpl { |
| 17 public: | 17 public: |
| 18 DummyTtsPlatformImpl() {} | 18 DummyTtsPlatformImpl() {} |
| 19 virtual ~DummyTtsPlatformImpl() {} | 19 ~DummyTtsPlatformImpl() override {} |
| 20 virtual bool PlatformImplAvailable() override { return true; } | 20 bool PlatformImplAvailable() override { return true; } |
| 21 virtual bool Speak( | 21 bool Speak(int utterance_id, |
| 22 int utterance_id, | 22 const std::string& utterance, |
| 23 const std::string& utterance, | 23 const std::string& lang, |
| 24 const std::string& lang, | 24 const VoiceData& voice, |
| 25 const VoiceData& voice, | 25 const UtteranceContinuousParameters& params) override { |
| 26 const UtteranceContinuousParameters& params) override { | |
| 27 return true; | 26 return true; |
| 28 } | 27 } |
| 29 virtual bool IsSpeaking() override { return false; } | 28 bool IsSpeaking() override { return false; } |
| 30 virtual bool StopSpeaking() override { return true; } | 29 bool StopSpeaking() override { return true; } |
| 31 virtual void Pause() override {} | 30 void Pause() override {} |
| 32 virtual void Resume() override {} | 31 void Resume() override {} |
| 33 virtual void GetVoices(std::vector<VoiceData>* out_voices) override {} | 32 void GetVoices(std::vector<VoiceData>* out_voices) override {} |
| 34 virtual std::string error() override { return std::string(); } | 33 std::string error() override { return std::string(); } |
| 35 virtual void clear_error() override {} | 34 void clear_error() override {} |
| 36 virtual void set_error(const std::string& error) override {} | 35 void set_error(const std::string& error) override {} |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 // Subclass of TtsController with a public ctor and dtor. | 38 // Subclass of TtsController with a public ctor and dtor. |
| 40 class TestableTtsController : public TtsControllerImpl { | 39 class TestableTtsController : public TtsControllerImpl { |
| 41 public: | 40 public: |
| 42 TestableTtsController() {} | 41 TestableTtsController() {} |
| 43 virtual ~TestableTtsController() {} | 42 ~TestableTtsController() override {} |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 TEST_F(TtsApiControllerTest, TestTtsControllerShutdown) { | 45 TEST_F(TtsApiControllerTest, TestTtsControllerShutdown) { |
| 47 DummyTtsPlatformImpl platform_impl; | 46 DummyTtsPlatformImpl platform_impl; |
| 48 TestableTtsController* controller = | 47 TestableTtsController* controller = |
| 49 new TestableTtsController(); | 48 new TestableTtsController(); |
| 50 controller->SetPlatformImpl(&platform_impl); | 49 controller->SetPlatformImpl(&platform_impl); |
| 51 | 50 |
| 52 Utterance* utterance1 = new Utterance(NULL); | 51 Utterance* utterance1 = new Utterance(NULL); |
| 53 utterance1->set_can_enqueue(true); | 52 utterance1->set_can_enqueue(true); |
| 54 utterance1->set_src_id(1); | 53 utterance1->set_src_id(1); |
| 55 controller->SpeakOrEnqueue(utterance1); | 54 controller->SpeakOrEnqueue(utterance1); |
| 56 | 55 |
| 57 Utterance* utterance2 = new Utterance(NULL); | 56 Utterance* utterance2 = new Utterance(NULL); |
| 58 utterance2->set_can_enqueue(true); | 57 utterance2->set_can_enqueue(true); |
| 59 utterance2->set_src_id(2); | 58 utterance2->set_src_id(2); |
| 60 controller->SpeakOrEnqueue(utterance2); | 59 controller->SpeakOrEnqueue(utterance2); |
| 61 | 60 |
| 62 // Make sure that deleting the controller when there are pending | 61 // Make sure that deleting the controller when there are pending |
| 63 // utterances doesn't cause a crash. | 62 // utterances doesn't cause a crash. |
| 64 delete controller; | 63 delete controller; |
| 65 } | 64 } |
| OLD | NEW |