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.
5 // Unit tests for the TTS Controller.
7 #include "base/values.h"
8 #include "chrome/browser/speech/tts_controller.h"
9 #include "chrome/browser/speech/tts_platform.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 class TtsApiControllerTest
: public testing::Test
{
15 // Platform Tts implementation that does nothing.
16 class DummyTtsPlatformImpl
: public TtsPlatformImpl
{
18 DummyTtsPlatformImpl() {}
19 virtual ~DummyTtsPlatformImpl() {}
20 virtual bool PlatformImplAvailable() OVERRIDE
{ return true; }
23 const std::string
& utterance
,
24 const std::string
& lang
,
25 const UtteranceContinuousParameters
& params
) OVERRIDE
{
28 virtual bool IsSpeaking() OVERRIDE
{ return false; }
29 virtual bool StopSpeaking() OVERRIDE
{ return true; }
30 virtual bool SendsEvent(TtsEventType event_type
) OVERRIDE
{ return false; }
31 virtual std::string
gender() OVERRIDE
{ return std::string(); }
32 virtual std::string
error() OVERRIDE
{ return std::string(); }
33 virtual void clear_error() OVERRIDE
{}
34 virtual void set_error(const std::string
& error
) OVERRIDE
{}
37 // Subclass of TtsController with a public ctor and dtor.
38 class TestableTtsController
: public TtsController
{
40 TestableTtsController() {}
41 virtual ~TestableTtsController() {}
44 TEST_F(TtsApiControllerTest
, TestTtsControllerShutdown
) {
45 DummyTtsPlatformImpl platform_impl
;
46 TestableTtsController
* controller
=
47 new TestableTtsController();
48 controller
->SetPlatformImpl(&platform_impl
);
50 Utterance
* utterance1
= new Utterance(NULL
);
51 utterance1
->set_can_enqueue(true);
52 utterance1
->set_src_id(1);
53 controller
->SpeakOrEnqueue(utterance1
);
55 Utterance
* utterance2
= new Utterance(NULL
);
56 utterance2
->set_can_enqueue(true);
57 utterance2
->set_src_id(2);
58 controller
->SpeakOrEnqueue(utterance2
);
60 // Make sure that deleting the controller when there are pending
61 // utterances doesn't cause a crash.