OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 #include "chrome/browser/chromeos/extensions/speech_synthesis_loader.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 9 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 10 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 11 #include "chrome/browser/extensions/external_provider_impl.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/speech/tts_platform.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" |
| 15 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 using content::BrowserThread; |
| 20 using extensions::ExternalProviderImpl; |
| 21 using extensions::ExternalProviderInterface; |
| 22 using extensions::Manifest; |
| 23 using extensions::ProviderCollection; |
| 24 |
| 25 namespace chromeos { |
| 26 |
| 27 namespace { |
| 28 class FakeVisitorInterface |
| 29 : public ExternalProviderInterface::VisitorInterface { |
| 30 public: |
| 31 FakeVisitorInterface() {} |
| 32 virtual ~FakeVisitorInterface() {} |
| 33 |
| 34 virtual bool OnExternalExtensionFileFound( |
| 35 const std::string& id, |
| 36 const base::Version* version, |
| 37 const base::FilePath& path, |
| 38 Manifest::Location location, |
| 39 int creation_flags, |
| 40 bool mark_acknowledged) OVERRIDE { |
| 41 return true; |
| 42 } |
| 43 |
| 44 virtual bool OnExternalExtensionUpdateUrlFound( |
| 45 const std::string& id, |
| 46 const GURL& update_url, |
| 47 Manifest::Location location, |
| 48 int creation_flags, |
| 49 bool mark_acknowledged) OVERRIDE { |
| 50 return true; |
| 51 } |
| 52 |
| 53 virtual void OnExternalProviderReady( |
| 54 const ExternalProviderInterface* provider) {} |
| 55 }; |
| 56 } // anonymous namespace |
| 57 |
| 58 class SpeechSynthesisLoaderTest : public testing::Test { |
| 59 public: |
| 60 SpeechSynthesisLoaderTest() |
| 61 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 62 user_manager_enabler_(new UserManagerImpl()) { |
| 63 } |
| 64 |
| 65 virtual ~SpeechSynthesisLoaderTest() {} |
| 66 |
| 67 // testing::Test overrides: |
| 68 virtual void SetUp() OVERRIDE { |
| 69 testing_profile_.reset(new TestingProfile()); |
| 70 ExternalProviderImpl::CreateExternalProviders( |
| 71 &service_, testing_profile_.get(), &providers_); |
| 72 } |
| 73 |
| 74 virtual void TearDown() OVERRIDE { |
| 75 } |
| 76 |
| 77 bool IsHighQualityEnglishSpeechExtensionInstalled() { |
| 78 const std::string& id = extension_misc::kHighQuality_en_US_ExtensionId; |
| 79 for (size_t i = 0; i < providers_.size(); ++i) { |
| 80 if (!providers_[i]->IsReady()) |
| 81 continue; |
| 82 if (providers_[i]->HasExtension(id)) |
| 83 return true; |
| 84 } |
| 85 return false; |
| 86 } |
| 87 |
| 88 protected: |
| 89 base::MessageLoop message_loop_; |
| 90 content::TestBrowserThread ui_thread_; |
| 91 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 92 ScopedTestCrosSettings test_cros_settings_; |
| 93 ScopedUserManagerEnabler user_manager_enabler_; |
| 94 scoped_ptr<Profile> testing_profile_; |
| 95 FakeVisitorInterface service_; |
| 96 ProviderCollection providers_; |
| 97 |
| 98 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(SpeechSynthesisLoaderTest); |
| 100 }; |
| 101 |
| 102 TEST_F(SpeechSynthesisLoaderTest, Speaking100TimesInstallsExtension) { |
| 103 ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 104 |
| 105 TtsPlatformImpl* tts_platform = TtsPlatformImpl::GetInstance(); |
| 106 Utterance utterance(testing_profile_.get()); |
| 107 VoiceData voice_data; |
| 108 voice_data.lang = "en-US"; |
| 109 voice_data.extension_id = extension_misc::kSpeechSynthesisExtensionId; |
| 110 |
| 111 // 99 times should not be sufficient. |
| 112 for (int i = 0; i < 99; i++) |
| 113 tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data); |
| 114 ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 115 |
| 116 // The 100th time should install it. |
| 117 tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data); |
| 118 ASSERT_TRUE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 119 } |
| 120 |
| 121 TEST_F(SpeechSynthesisLoaderTest, UsingOtherVoiceDoesNotTriggerInstall) { |
| 122 ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 123 |
| 124 TtsPlatformImpl* tts_platform = TtsPlatformImpl::GetInstance(); |
| 125 Utterance utterance(testing_profile_.get()); |
| 126 VoiceData voice_data; |
| 127 voice_data.lang = "en-US"; |
| 128 voice_data.extension_id = "dummy"; // Some other extension id. |
| 129 |
| 130 for (int i = 0; i < 100; i++) |
| 131 tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data); |
| 132 ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 133 } |
| 134 |
| 135 TEST_F(SpeechSynthesisLoaderTest, UnsupportedLangDoesNotTriggerInstall) { |
| 136 ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 137 |
| 138 TtsPlatformImpl* tts_platform = TtsPlatformImpl::GetInstance(); |
| 139 Utterance utterance(testing_profile_.get()); |
| 140 VoiceData voice_data; |
| 141 voice_data.lang = "tlh"; // Klingon |
| 142 voice_data.extension_id = extension_misc::kSpeechSynthesisExtensionId; |
| 143 |
| 144 for (int i = 0; i < 100; i++) |
| 145 tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data); |
| 146 ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled()); |
| 147 } |
| 148 |
| 149 } // namespace chromeos |
OLD | NEW |