Chromium Code Reviews| 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 #include "chrome/browser/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "chrome/browser/extensions/extension_service_unittest.h" | |
| 9 #include "chrome/browser/themes/theme_service_factory.h" | |
| 10 #include "chrome/common/extensions/extension.h" | |
| 11 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 12 #include "chrome/test/base/testing_profile.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 14 |
| 10 TEST(ThemeServiceTest, AlignmentConversion) { | 15 namespace { |
| 16 | |
| 17 class ThemeServiceTest : public ExtensionServiceTestBase { | |
| 18 public: | |
| 19 ThemeServiceTest() {} | |
| 20 virtual ~ThemeServiceTest() {} | |
| 21 | |
| 22 scoped_refptr<extensions::Extension> MakeThemeExtension(FilePath path) { | |
| 23 DictionaryValue source; | |
| 24 source.SetString(extension_manifest_keys::kName, "theme"); | |
| 25 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | |
| 26 source.SetString(extension_manifest_keys::kUpdateURL, "http://foo.com"); | |
| 27 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | |
| 28 std::string error; | |
| 29 scoped_refptr<extensions::Extension> extension = | |
| 30 extensions::Extension::Create( | |
| 31 path, extensions::Extension::EXTERNAL_PREF_DOWNLOAD, | |
| 32 source, extensions::Extension::NO_FLAGS, &error); | |
| 33 EXPECT_TRUE(extension); | |
| 34 EXPECT_EQ("", error); | |
| 35 return extension; | |
| 36 } | |
| 37 | |
| 38 void SetUp() { | |
| 39 InitializeEmptyExtensionService(); | |
| 40 } | |
| 41 }; | |
| 42 | |
| 43 TEST_F(ThemeServiceTest, AlignmentConversion) { | |
| 11 // Verify that we get out what we put in. | 44 // Verify that we get out what we put in. |
| 12 std::string top_left = "left top"; | 45 std::string top_left = "left top"; |
| 13 int alignment = ThemeService::StringToAlignment(top_left); | 46 int alignment = ThemeService::StringToAlignment(top_left); |
| 14 EXPECT_EQ(ThemeService::ALIGN_TOP | ThemeService::ALIGN_LEFT, | 47 EXPECT_EQ(ThemeService::ALIGN_TOP | ThemeService::ALIGN_LEFT, |
| 15 alignment); | 48 alignment); |
| 16 EXPECT_EQ(top_left, ThemeService::AlignmentToString(alignment)); | 49 EXPECT_EQ(top_left, ThemeService::AlignmentToString(alignment)); |
| 17 | 50 |
| 18 // We get back a normalized version of what we put in. | 51 // We get back a normalized version of what we put in. |
| 19 alignment = ThemeService::StringToAlignment("top"); | 52 alignment = ThemeService::StringToAlignment("top"); |
| 20 EXPECT_EQ(ThemeService::ALIGN_TOP, alignment); | 53 EXPECT_EQ(ThemeService::ALIGN_TOP, alignment); |
| 21 EXPECT_EQ("center top", ThemeService::AlignmentToString(alignment)); | 54 EXPECT_EQ("center top", ThemeService::AlignmentToString(alignment)); |
| 22 | 55 |
| 23 alignment = ThemeService::StringToAlignment("left"); | 56 alignment = ThemeService::StringToAlignment("left"); |
| 24 EXPECT_EQ(ThemeService::ALIGN_LEFT, alignment); | 57 EXPECT_EQ(ThemeService::ALIGN_LEFT, alignment); |
| 25 EXPECT_EQ("left center", ThemeService::AlignmentToString(alignment)); | 58 EXPECT_EQ("left center", ThemeService::AlignmentToString(alignment)); |
| 26 | 59 |
| 27 alignment = ThemeService::StringToAlignment("right"); | 60 alignment = ThemeService::StringToAlignment("right"); |
| 28 EXPECT_EQ(ThemeService::ALIGN_RIGHT, alignment); | 61 EXPECT_EQ(ThemeService::ALIGN_RIGHT, alignment); |
| 29 EXPECT_EQ("right center", ThemeService::AlignmentToString(alignment)); | 62 EXPECT_EQ("right center", ThemeService::AlignmentToString(alignment)); |
| 30 | 63 |
| 31 alignment = ThemeService::StringToAlignment("righttopbottom"); | 64 alignment = ThemeService::StringToAlignment("righttopbottom"); |
| 32 EXPECT_EQ(ThemeService::ALIGN_CENTER, alignment); | 65 EXPECT_EQ(ThemeService::ALIGN_CENTER, alignment); |
| 33 EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); | 66 EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); |
| 34 } | 67 } |
| 35 | 68 |
| 36 TEST(ThemeServiceTest, AlignmentConversionInput) { | 69 TEST_F(ThemeServiceTest, AlignmentConversionInput) { |
| 37 // Verify that we output in an expected format. | 70 // Verify that we output in an expected format. |
| 38 int alignment = ThemeService::StringToAlignment("bottom right"); | 71 int alignment = ThemeService::StringToAlignment("bottom right"); |
| 39 EXPECT_EQ("right bottom", ThemeService::AlignmentToString(alignment)); | 72 EXPECT_EQ("right bottom", ThemeService::AlignmentToString(alignment)); |
| 40 | 73 |
| 41 // Verify that bad strings don't cause explosions. | 74 // Verify that bad strings don't cause explosions. |
| 42 alignment = ThemeService::StringToAlignment("new zealand"); | 75 alignment = ThemeService::StringToAlignment("new zealand"); |
| 43 EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); | 76 EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); |
| 44 | 77 |
| 45 // Verify that bad strings don't cause explosions. | 78 // Verify that bad strings don't cause explosions. |
| 46 alignment = ThemeService::StringToAlignment("new zealand top"); | 79 alignment = ThemeService::StringToAlignment("new zealand top"); |
| 47 EXPECT_EQ("center top", ThemeService::AlignmentToString(alignment)); | 80 EXPECT_EQ("center top", ThemeService::AlignmentToString(alignment)); |
| 48 | 81 |
| 49 // Verify that bad strings don't cause explosions. | 82 // Verify that bad strings don't cause explosions. |
| 50 alignment = ThemeService::StringToAlignment("new zealandtop"); | 83 alignment = ThemeService::StringToAlignment("new zealandtop"); |
| 51 EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); | 84 EXPECT_EQ("center center", ThemeService::AlignmentToString(alignment)); |
| 52 } | 85 } |
| 86 | |
| 87 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { | |
| 88 // 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.
| |
| 89 // reverts to the default theme after the uninstall. | |
| 90 base::ScopedTempDir temp_dir; | |
| 91 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 92 ThemeService* theme_service = | |
| 93 ThemeServiceFactory::GetForProfile(profile_.get()); | |
| 94 theme_service->UseDefaultTheme(); | |
| 95 scoped_refptr<extensions::Extension> extension = | |
| 96 MakeThemeExtension(temp_dir.path()); | |
| 97 service_->AddExtension(extension); | |
| 98 // Let ThemeService finish creating the theme pack. | |
| 99 MessageLoop::current()->RunUntilIdle(); | |
| 100 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | |
| 101 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.
| |
| 102 | |
| 103 // Now unload the extension, should revert to the default theme. | |
| 104 service_->UnloadExtension(extension->id(), | |
| 105 extension_misc::UNLOAD_REASON_UNINSTALL); | |
| 106 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | |
| 107 } | |
| 108 | |
| 109 TEST_F(ThemeServiceTest, ThemeUpgrade) { | |
| 110 // Upgrades a theme and ensures that the ThemeService does not revert to the | |
| 111 // default theme. | |
|
akalin
2012/11/30 18:25:25
here too
Andrew T Wilson (Slow)
2012/12/03 12:34:58
Done.
| |
| 112 base::ScopedTempDir temp_dir; | |
| 113 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 114 ThemeService* theme_service = | |
| 115 ThemeServiceFactory::GetForProfile(profile_.get()); | |
| 116 theme_service->UseDefaultTheme(); | |
| 117 scoped_refptr<extensions::Extension> extension = | |
| 118 MakeThemeExtension(temp_dir.path()); | |
| 119 service_->AddExtension(extension); | |
| 120 // Let ThemeService finish creating the theme pack. | |
| 121 MessageLoop::current()->RunUntilIdle(); | |
| 122 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | |
| 123 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.
| |
| 124 | |
| 125 // Now unload the extension, should revert to the default theme. | |
| 126 service_->UnloadExtension(extension->id(), | |
| 127 extension_misc::UNLOAD_REASON_UPDATE); | |
| 128 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | |
| 129 } | |
| 130 | |
| 131 }; // namespace | |
| OLD | NEW |