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 TtsControllerTest : 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 ~DummyTtsPlatformImpl() override {} | 19 ~DummyTtsPlatformImpl() override {} |
20 bool PlatformImplAvailable() override { return true; } | 20 bool PlatformImplAvailable() override { return true; } |
21 bool Speak(int utterance_id, | 21 bool Speak(int utterance_id, |
22 const std::string& utterance, | 22 const std::string& utterance, |
(...skipping 12 matching lines...) Expand all Loading... | |
35 void set_error(const std::string& error) override {} | 35 void set_error(const std::string& error) override {} |
36 }; | 36 }; |
37 | 37 |
38 // Subclass of TtsController with a public ctor and dtor. | 38 // Subclass of TtsController with a public ctor and dtor. |
39 class TestableTtsController : public TtsControllerImpl { | 39 class TestableTtsController : public TtsControllerImpl { |
40 public: | 40 public: |
41 TestableTtsController() {} | 41 TestableTtsController() {} |
42 ~TestableTtsController() override {} | 42 ~TestableTtsController() override {} |
43 }; | 43 }; |
44 | 44 |
45 TEST_F(TtsApiControllerTest, TestTtsControllerShutdown) { | 45 TEST_F(TtsControllerTest, TestTtsControllerShutdown) { |
46 DummyTtsPlatformImpl platform_impl; | 46 DummyTtsPlatformImpl platform_impl; |
47 TestableTtsController* controller = | 47 TestableTtsController* controller = |
48 new TestableTtsController(); | 48 new TestableTtsController(); |
49 controller->SetPlatformImpl(&platform_impl); | 49 controller->SetPlatformImpl(&platform_impl); |
50 | 50 |
51 Utterance* utterance1 = new Utterance(NULL); | 51 Utterance* utterance1 = new Utterance(NULL); |
52 utterance1->set_can_enqueue(true); | 52 utterance1->set_can_enqueue(true); |
53 utterance1->set_src_id(1); | 53 utterance1->set_src_id(1); |
54 controller->SpeakOrEnqueue(utterance1); | 54 controller->SpeakOrEnqueue(utterance1); |
55 | 55 |
56 Utterance* utterance2 = new Utterance(NULL); | 56 Utterance* utterance2 = new Utterance(NULL); |
57 utterance2->set_can_enqueue(true); | 57 utterance2->set_can_enqueue(true); |
58 utterance2->set_src_id(2); | 58 utterance2->set_src_id(2); |
59 controller->SpeakOrEnqueue(utterance2); | 59 controller->SpeakOrEnqueue(utterance2); |
60 | 60 |
61 // Make sure that deleting the controller when there are pending | 61 // Make sure that deleting the controller when there are pending |
62 // utterances doesn't cause a crash. | 62 // utterances doesn't cause a crash. |
63 delete controller; | 63 delete controller; |
64 } | 64 } |
65 | |
66 TEST_F(TtsControllerTest, TestGetMatchingVoice) { | |
67 TtsControllerImpl* tts_controller = TtsControllerImpl::GetInstance(); | |
68 | |
69 { | |
70 // Calling GetMatchingVoice with no voices returns -1 | |
71 Utterance utterance(nullptr); | |
72 std::vector<VoiceData> voices; | |
73 EXPECT_EQ(-1, tts_controller->GetMatchingVoice(&utterance, voices)); | |
74 } | |
75 | |
76 { | |
77 // Calling GetMatchingVoice with any voices returns the first one if | |
David Tseng
2016/09/23 22:10:50
nit: remove if
dmazzoni
2016/09/26 19:26:12
Done
| |
78 // even if there are no criteria that match. | |
79 Utterance utterance(nullptr); | |
80 std::vector<VoiceData> voices; | |
81 voices.push_back(VoiceData()); | |
82 voices.push_back(VoiceData()); | |
83 EXPECT_EQ(0, tts_controller->GetMatchingVoice(&utterance, voices)); | |
84 } | |
85 | |
86 { | |
87 // If nothing else matches, the English voice is returned. | |
88 // (In tests the language will always be English.) | |
89 Utterance utterance(nullptr); | |
90 std::vector<VoiceData> voices; | |
91 VoiceData fr_voice; | |
92 fr_voice.lang = "fr"; | |
93 voices.push_back(fr_voice); | |
94 VoiceData en_voice; | |
95 en_voice.lang = "en"; | |
96 voices.push_back(en_voice); | |
97 VoiceData de_voice; | |
98 de_voice.lang = "de"; | |
99 voices.push_back(de_voice); | |
100 EXPECT_EQ(1, tts_controller->GetMatchingVoice(&utterance, voices)); | |
101 } | |
102 | |
103 { | |
104 // Check precedence of various matching criteria. | |
105 std::vector<VoiceData> voices; | |
106 VoiceData voice0; | |
107 voices.push_back(voice0); | |
108 VoiceData voice1; | |
109 voice1.gender = TTS_GENDER_FEMALE; | |
110 voices.push_back(voice1); | |
111 VoiceData voice2; | |
112 voice2.events.insert(TTS_EVENT_WORD); | |
113 voices.push_back(voice2); | |
114 VoiceData voice3; | |
115 voice3.lang = "de-DE"; | |
116 voices.push_back(voice3); | |
117 VoiceData voice4; | |
118 voice4.lang = "fr-CA"; | |
119 voices.push_back(voice4); | |
120 VoiceData voice5; | |
121 voice5.name = "Voice5"; | |
122 voices.push_back(voice5); | |
123 VoiceData voice6; | |
124 voice6.extension_id = "id6"; | |
125 voices.push_back(voice6); | |
126 | |
127 Utterance utterance(nullptr); | |
128 EXPECT_EQ(0, tts_controller->GetMatchingVoice(&utterance, voices)); | |
129 | |
130 utterance.set_gender(TTS_GENDER_FEMALE); | |
131 EXPECT_EQ(1, tts_controller->GetMatchingVoice(&utterance, voices)); | |
132 | |
133 std::set<TtsEventType> types; | |
134 types.insert(TTS_EVENT_WORD); | |
135 utterance.set_required_event_types(types); | |
136 EXPECT_EQ(2, tts_controller->GetMatchingVoice(&utterance, voices)); | |
137 | |
138 utterance.set_lang("de-DE"); | |
139 EXPECT_EQ(3, tts_controller->GetMatchingVoice(&utterance, voices)); | |
140 | |
141 utterance.set_lang("fr-FR"); | |
142 EXPECT_EQ(4, tts_controller->GetMatchingVoice(&utterance, voices)); | |
143 | |
144 utterance.set_voice_name("Voice5"); | |
145 EXPECT_EQ(5, tts_controller->GetMatchingVoice(&utterance, voices)); | |
146 | |
147 utterance.set_voice_name(""); | |
148 utterance.set_extension_id("id6"); | |
149 EXPECT_EQ(6, tts_controller->GetMatchingVoice(&utterance, voices)); | |
150 } | |
151 } | |
OLD | NEW |