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