| Index: chrome/browser/chromeos/extensions/speech_synthesis_loader_unittest.cc
|
| diff --git a/chrome/browser/chromeos/extensions/speech_synthesis_loader_unittest.cc b/chrome/browser/chromeos/extensions/speech_synthesis_loader_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cc033420f7bc3e719a52b40c7adaa2d6d4e5b896
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/extensions/speech_synthesis_loader_unittest.cc
|
| @@ -0,0 +1,149 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/extensions/speech_synthesis_loader.h"
|
| +
|
| +#include "base/values.h"
|
| +#include "chrome/browser/chromeos/login/user_manager_impl.h"
|
| +#include "chrome/browser/chromeos/settings/cros_settings.h"
|
| +#include "chrome/browser/chromeos/settings/device_settings_service.h"
|
| +#include "chrome/browser/extensions/external_provider_impl.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/speech/tts_platform.h"
|
| +#include "chrome/common/extensions/extension_constants.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "content/public/test/test_browser_thread.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using content::BrowserThread;
|
| +using extensions::ExternalProviderImpl;
|
| +using extensions::ExternalProviderInterface;
|
| +using extensions::Manifest;
|
| +using extensions::ProviderCollection;
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +class FakeVisitorInterface
|
| + : public ExternalProviderInterface::VisitorInterface {
|
| + public:
|
| + FakeVisitorInterface() {}
|
| + virtual ~FakeVisitorInterface() {}
|
| +
|
| + virtual bool OnExternalExtensionFileFound(
|
| + const std::string& id,
|
| + const base::Version* version,
|
| + const base::FilePath& path,
|
| + Manifest::Location location,
|
| + int creation_flags,
|
| + bool mark_acknowledged) OVERRIDE {
|
| + return true;
|
| + }
|
| +
|
| + virtual bool OnExternalExtensionUpdateUrlFound(
|
| + const std::string& id,
|
| + const GURL& update_url,
|
| + Manifest::Location location,
|
| + int creation_flags,
|
| + bool mark_acknowledged) OVERRIDE {
|
| + return true;
|
| + }
|
| +
|
| + virtual void OnExternalProviderReady(
|
| + const ExternalProviderInterface* provider) {}
|
| +};
|
| +} // anonymous namespace
|
| +
|
| +class SpeechSynthesisLoaderTest : public testing::Test {
|
| + public:
|
| + SpeechSynthesisLoaderTest()
|
| + : ui_thread_(BrowserThread::UI, &message_loop_),
|
| + user_manager_enabler_(new UserManagerImpl()) {
|
| + }
|
| +
|
| + virtual ~SpeechSynthesisLoaderTest() {}
|
| +
|
| + // testing::Test overrides:
|
| + virtual void SetUp() OVERRIDE {
|
| + testing_profile_.reset(new TestingProfile());
|
| + ExternalProviderImpl::CreateExternalProviders(
|
| + &service_, testing_profile_.get(), &providers_);
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + }
|
| +
|
| + bool IsHighQualityEnglishSpeechExtensionInstalled() {
|
| + const std::string& id = extension_misc::kHighQuality_en_US_ExtensionId;
|
| + for (size_t i = 0; i < providers_.size(); ++i) {
|
| + if (!providers_[i]->IsReady())
|
| + continue;
|
| + if (providers_[i]->HasExtension(id))
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + protected:
|
| + base::MessageLoop message_loop_;
|
| + content::TestBrowserThread ui_thread_;
|
| + ScopedTestDeviceSettingsService test_device_settings_service_;
|
| + ScopedTestCrosSettings test_cros_settings_;
|
| + ScopedUserManagerEnabler user_manager_enabler_;
|
| + scoped_ptr<Profile> testing_profile_;
|
| + FakeVisitorInterface service_;
|
| + ProviderCollection providers_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(SpeechSynthesisLoaderTest);
|
| +};
|
| +
|
| +TEST_F(SpeechSynthesisLoaderTest, Speaking100TimesInstallsExtension) {
|
| + ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +
|
| + TtsPlatformImpl* tts_platform = TtsPlatformImpl::GetInstance();
|
| + Utterance utterance(testing_profile_.get());
|
| + VoiceData voice_data;
|
| + voice_data.lang = "en-US";
|
| + voice_data.extension_id = extension_misc::kSpeechSynthesisExtensionId;
|
| +
|
| + // 99 times should not be sufficient.
|
| + for (int i = 0; i < 99; i++)
|
| + tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data);
|
| + ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +
|
| + // The 100th time should install it.
|
| + tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data);
|
| + ASSERT_TRUE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +}
|
| +
|
| +TEST_F(SpeechSynthesisLoaderTest, UsingOtherVoiceDoesNotTriggerInstall) {
|
| + ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +
|
| + TtsPlatformImpl* tts_platform = TtsPlatformImpl::GetInstance();
|
| + Utterance utterance(testing_profile_.get());
|
| + VoiceData voice_data;
|
| + voice_data.lang = "en-US";
|
| + voice_data.extension_id = "dummy"; // Some other extension id.
|
| +
|
| + for (int i = 0; i < 100; i++)
|
| + tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data);
|
| + ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +}
|
| +
|
| +TEST_F(SpeechSynthesisLoaderTest, UnsupportedLangDoesNotTriggerInstall) {
|
| + ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +
|
| + TtsPlatformImpl* tts_platform = TtsPlatformImpl::GetInstance();
|
| + Utterance utterance(testing_profile_.get());
|
| + VoiceData voice_data;
|
| + voice_data.lang = "tlh"; // Klingon
|
| + voice_data.extension_id = extension_misc::kSpeechSynthesisExtensionId;
|
| +
|
| + for (int i = 0; i < 100; i++)
|
| + tts_platform->WillSpeakUtteranceWithVoice(&utterance, voice_data);
|
| + ASSERT_FALSE(IsHighQualityEnglishSpeechExtensionInstalled());
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|