Chromium Code Reviews| Index: chrome/browser/themes/theme_service_unittest.cc |
| diff --git a/chrome/browser/themes/theme_service_unittest.cc b/chrome/browser/themes/theme_service_unittest.cc |
| index a74c4b6695a72a10d773a69b03e5036bb6399631..2ba0703c95561e01d90ab1df3bb37b3b3e7b8de1 100644 |
| --- a/chrome/browser/themes/theme_service_unittest.cc |
| +++ b/chrome/browser/themes/theme_service_unittest.cc |
| @@ -5,9 +5,42 @@ |
| #include "chrome/browser/themes/theme_service.h" |
| #include "base/json/json_reader.h" |
| +#include "chrome/browser/extensions/extension_service_unittest.h" |
| +#include "chrome/browser/themes/theme_service_factory.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/extensions/extension_manifest_constants.h" |
| +#include "chrome/test/base/testing_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -TEST(ThemeServiceTest, AlignmentConversion) { |
| +namespace { |
| + |
| +class ThemeServiceTest : public ExtensionServiceTestBase { |
| + public: |
| + ThemeServiceTest() {} |
| + virtual ~ThemeServiceTest() {} |
| + |
| + scoped_refptr<extensions::Extension> MakeThemeExtension(FilePath path) { |
| + DictionaryValue source; |
| + source.SetString(extension_manifest_keys::kName, "theme"); |
| + source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); |
| + source.SetString(extension_manifest_keys::kUpdateURL, "http://foo.com"); |
| + source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); |
| + std::string error; |
| + scoped_refptr<extensions::Extension> extension = |
| + extensions::Extension::Create( |
| + path, extensions::Extension::EXTERNAL_PREF_DOWNLOAD, |
| + source, extensions::Extension::NO_FLAGS, &error); |
| + EXPECT_TRUE(extension); |
| + EXPECT_EQ("", error); |
| + return extension; |
| + } |
| + |
| + void SetUp() { |
| + InitializeEmptyExtensionService(); |
| + } |
| +}; |
| + |
| +TEST_F(ThemeServiceTest, AlignmentConversion) { |
| // Verify that we get out what we put in. |
| std::string top_left = "left top"; |
| int alignment = ThemeService::StringToAlignment(top_left); |
| @@ -33,7 +66,7 @@ TEST(ThemeServiceTest, AlignmentConversion) { |
| EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); |
| } |
| -TEST(ThemeServiceTest, AlignmentConversionInput) { |
| +TEST_F(ThemeServiceTest, AlignmentConversionInput) { |
| // Verify that we output in an expected format. |
| int alignment = ThemeService::StringToAlignment("bottom right"); |
| EXPECT_EQ("right bottom", ThemeService::AlignmentToString(alignment)); |
| @@ -50,3 +83,49 @@ TEST(ThemeServiceTest, AlignmentConversionInput) { |
| alignment = ThemeService::StringToAlignment("new zealandtop"); |
| EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); |
| } |
| + |
| +TEST_F(ThemeServiceTest, ThemeInstallUninstall) { |
| + // Installs then uninstalls a theme and makes sure that the ThemeService |
|
akalin
2012/11/30 18:25:25
comment above TEST_F line?
Andrew T Wilson (Slow)
2012/12/03 12:34:58
Done.
|
| + // reverts to the default theme after the uninstall. |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + ThemeService* theme_service = |
| + ThemeServiceFactory::GetForProfile(profile_.get()); |
| + theme_service->UseDefaultTheme(); |
| + scoped_refptr<extensions::Extension> extension = |
| + MakeThemeExtension(temp_dir.path()); |
| + service_->AddExtension(extension); |
| + // Let ThemeService finish creating the theme pack. |
| + MessageLoop::current()->RunUntilIdle(); |
| + EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| + EXPECT_EQ(extension->id(), theme_service->GetThemeID()); |
|
akalin
2012/11/30 18:25:25
GetThemeIDForProfile
Andrew T Wilson (Slow)
2012/12/03 12:34:58
Done.
|
| + |
| + // Now unload the extension, should revert to the default theme. |
| + service_->UnloadExtension(extension->id(), |
| + extension_misc::UNLOAD_REASON_UNINSTALL); |
| + EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
| +} |
| + |
| +TEST_F(ThemeServiceTest, ThemeUpgrade) { |
| + // Upgrades a theme and ensures that the ThemeService does not revert to the |
| + // default theme. |
|
akalin
2012/11/30 18:25:25
here too
Andrew T Wilson (Slow)
2012/12/03 12:34:58
Done.
|
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + ThemeService* theme_service = |
| + ThemeServiceFactory::GetForProfile(profile_.get()); |
| + theme_service->UseDefaultTheme(); |
| + scoped_refptr<extensions::Extension> extension = |
| + MakeThemeExtension(temp_dir.path()); |
| + service_->AddExtension(extension); |
| + // Let ThemeService finish creating the theme pack. |
| + MessageLoop::current()->RunUntilIdle(); |
| + EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| + EXPECT_EQ(extension->id(), theme_service->GetThemeID()); |
|
akalin
2012/11/30 18:25:25
GetThemeIDForProfile
Andrew T Wilson (Slow)
2012/12/03 12:34:58
Done.
|
| + |
| + // Now unload the extension, should revert to the default theme. |
| + service_->UnloadExtension(extension->id(), |
| + extension_misc::UNLOAD_REASON_UPDATE); |
| + EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| +} |
| + |
| +}; // namespace |