Index: chrome/browser/speech/tts_controller_unittest.cc |
diff --git a/chrome/browser/speech/tts_controller_unittest.cc b/chrome/browser/speech/tts_controller_unittest.cc |
index 9aa8450f71909e40c77459f22cabd3355baacc2c..0df30c7993335158e68e8bd2fb459870c3eaf8bc 100644 |
--- a/chrome/browser/speech/tts_controller_unittest.cc |
+++ b/chrome/browser/speech/tts_controller_unittest.cc |
@@ -9,7 +9,7 @@ |
#include "chrome/browser/speech/tts_platform.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-class TtsApiControllerTest : public testing::Test { |
+class TtsControllerTest : public testing::Test { |
}; |
// Platform Tts implementation that does nothing. |
@@ -42,7 +42,7 @@ class TestableTtsController : public TtsControllerImpl { |
~TestableTtsController() override {} |
}; |
-TEST_F(TtsApiControllerTest, TestTtsControllerShutdown) { |
+TEST_F(TtsControllerTest, TestTtsControllerShutdown) { |
DummyTtsPlatformImpl platform_impl; |
TestableTtsController* controller = |
new TestableTtsController(); |
@@ -62,3 +62,90 @@ TEST_F(TtsApiControllerTest, TestTtsControllerShutdown) { |
// utterances doesn't cause a crash. |
delete controller; |
} |
+ |
+TEST_F(TtsControllerTest, TestGetMatchingVoice) { |
+ TtsControllerImpl* tts_controller = TtsControllerImpl::GetInstance(); |
+ |
+ { |
+ // Calling GetMatchingVoice with no voices returns -1 |
+ Utterance utterance(nullptr); |
+ std::vector<VoiceData> voices; |
+ EXPECT_EQ(-1, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ } |
+ |
+ { |
+ // 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
|
+ // even if there are no criteria that match. |
+ Utterance utterance(nullptr); |
+ std::vector<VoiceData> voices; |
+ voices.push_back(VoiceData()); |
+ voices.push_back(VoiceData()); |
+ EXPECT_EQ(0, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ } |
+ |
+ { |
+ // If nothing else matches, the English voice is returned. |
+ // (In tests the language will always be English.) |
+ Utterance utterance(nullptr); |
+ std::vector<VoiceData> voices; |
+ VoiceData fr_voice; |
+ fr_voice.lang = "fr"; |
+ voices.push_back(fr_voice); |
+ VoiceData en_voice; |
+ en_voice.lang = "en"; |
+ voices.push_back(en_voice); |
+ VoiceData de_voice; |
+ de_voice.lang = "de"; |
+ voices.push_back(de_voice); |
+ EXPECT_EQ(1, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ } |
+ |
+ { |
+ // Check precedence of various matching criteria. |
+ std::vector<VoiceData> voices; |
+ VoiceData voice0; |
+ voices.push_back(voice0); |
+ VoiceData voice1; |
+ voice1.gender = TTS_GENDER_FEMALE; |
+ voices.push_back(voice1); |
+ VoiceData voice2; |
+ voice2.events.insert(TTS_EVENT_WORD); |
+ voices.push_back(voice2); |
+ VoiceData voice3; |
+ voice3.lang = "de-DE"; |
+ voices.push_back(voice3); |
+ VoiceData voice4; |
+ voice4.lang = "fr-CA"; |
+ voices.push_back(voice4); |
+ VoiceData voice5; |
+ voice5.name = "Voice5"; |
+ voices.push_back(voice5); |
+ VoiceData voice6; |
+ voice6.extension_id = "id6"; |
+ voices.push_back(voice6); |
+ |
+ Utterance utterance(nullptr); |
+ EXPECT_EQ(0, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ |
+ utterance.set_gender(TTS_GENDER_FEMALE); |
+ EXPECT_EQ(1, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ |
+ std::set<TtsEventType> types; |
+ types.insert(TTS_EVENT_WORD); |
+ utterance.set_required_event_types(types); |
+ EXPECT_EQ(2, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ |
+ utterance.set_lang("de-DE"); |
+ EXPECT_EQ(3, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ |
+ utterance.set_lang("fr-FR"); |
+ EXPECT_EQ(4, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ |
+ utterance.set_voice_name("Voice5"); |
+ EXPECT_EQ(5, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ |
+ utterance.set_voice_name(""); |
+ utterance.set_extension_id("id6"); |
+ EXPECT_EQ(6, tts_controller->GetMatchingVoice(&utterance, voices)); |
+ } |
+} |