Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: chrome/browser/themes/theme_service_unittest.cc

Issue 19471005: Add custom default theme support and create a managed user default theme. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Define color constant for label background. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 8 #include "chrome/browser/extensions/extension_service_unittest.h"
9 #include "chrome/browser/themes/custom_theme_supplier.h"
9 #include "chrome/browser/themes/theme_service_factory.h" 10 #include "chrome/browser/themes/theme_service_factory.h"
10 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_manifest_constants.h" 12 #include "chrome/common/extensions/extension_manifest_constants.h"
13 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace { 17 namespace theme_service_internal {
16 18
17 class ThemeServiceTest : public ExtensionServiceTestBase { 19 class ThemeServiceTest : public ExtensionServiceTestBase {
18 public: 20 public:
19 ThemeServiceTest() {} 21 ThemeServiceTest() {}
20 virtual ~ThemeServiceTest() {} 22 virtual ~ThemeServiceTest() {}
21 23
22 scoped_refptr<extensions::Extension> MakeThemeExtension(base::FilePath path) { 24 scoped_refptr<extensions::Extension> MakeThemeExtension(base::FilePath path) {
23 DictionaryValue source; 25 DictionaryValue source;
24 source.SetString(extension_manifest_keys::kName, "theme"); 26 source.SetString(extension_manifest_keys::kName, "theme");
25 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); 27 source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
26 source.SetString(extension_manifest_keys::kUpdateURL, "http://foo.com"); 28 source.SetString(extension_manifest_keys::kUpdateURL, "http://foo.com");
27 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); 29 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
28 std::string error; 30 std::string error;
29 scoped_refptr<extensions::Extension> extension = 31 scoped_refptr<extensions::Extension> extension =
30 extensions::Extension::Create( 32 extensions::Extension::Create(
31 path, extensions::Manifest::EXTERNAL_PREF_DOWNLOAD, 33 path, extensions::Manifest::EXTERNAL_PREF_DOWNLOAD,
32 source, extensions::Extension::NO_FLAGS, &error); 34 source, extensions::Extension::NO_FLAGS, &error);
33 EXPECT_TRUE(extension.get()); 35 EXPECT_TRUE(extension.get());
34 EXPECT_EQ("", error); 36 EXPECT_EQ("", error);
35 return extension; 37 return extension;
36 } 38 }
37 39
38 virtual void SetUp() { 40 virtual void SetUp() {
39 ExtensionServiceTestBase::SetUp(); 41 ExtensionServiceTestBase::SetUp();
40 InitializeEmptyExtensionService(); 42 InitializeEmptyExtensionService();
41 } 43 }
44
45 const CustomThemeSupplier* GetThemeSupplier(ThemeService* theme_service) {
Elliot Glaysher 2013/07/23 19:57:31 unix_hacker_case().
Adrian Kuegel 2013/07/24 12:31:35 Done.
46 return theme_service->get_theme_supplier();
47 }
42 }; 48 };
43 49
44 // Installs then uninstalls a theme and makes sure that the ThemeService 50 // Installs then uninstalls a theme and makes sure that the ThemeService
45 // reverts to the default theme after the uninstall. 51 // reverts to the default theme after the uninstall.
46 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { 52 TEST_F(ThemeServiceTest, ThemeInstallUninstall) {
47 base::ScopedTempDir temp_dir; 53 base::ScopedTempDir temp_dir;
48 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 54 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
49 ThemeService* theme_service = 55 ThemeService* theme_service =
50 ThemeServiceFactory::GetForProfile(profile_.get()); 56 ThemeServiceFactory::GetForProfile(profile_.get());
51 theme_service->UseDefaultTheme(); 57 theme_service->UseDefaultTheme();
(...skipping 26 matching lines...) Expand all
78 base::MessageLoop::current()->RunUntilIdle(); 84 base::MessageLoop::current()->RunUntilIdle();
79 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 85 EXPECT_FALSE(theme_service->UsingDefaultTheme());
80 EXPECT_EQ(extension->id(), theme_service->GetThemeID()); 86 EXPECT_EQ(extension->id(), theme_service->GetThemeID());
81 87
82 // Now unload the extension, should revert to the default theme. 88 // Now unload the extension, should revert to the default theme.
83 service_->UnloadExtension(extension->id(), 89 service_->UnloadExtension(extension->id(),
84 extension_misc::UNLOAD_REASON_UPDATE); 90 extension_misc::UNLOAD_REASON_UPDATE);
85 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 91 EXPECT_FALSE(theme_service->UsingDefaultTheme());
86 } 92 }
87 93
88 }; // namespace 94 // Checks that managed users have their own default theme.
95 TEST_F(ThemeServiceTest, ManagedUserThemeReplacesDefaultTheme) {
96 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true);
97 ThemeService* theme_service =
98 ThemeServiceFactory::GetForProfile(profile_.get());
99 theme_service->UseDefaultTheme();
100 EXPECT_TRUE(theme_service->UsingDefaultTheme());
101 EXPECT_TRUE(GetThemeSupplier(theme_service));
102 EXPECT_EQ(GetThemeSupplier(theme_service)->GetThemeType(),
103 CustomThemeSupplier::MANAGED_USER_THEME);
104 }
105
106 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
107 // Checks that managed users don't use the system theme even if it is the
108 // default. The system theme is only available on Linux.
109 TEST_F(ThemeServiceTest, ManagedUserThemeReplacesNativeTheme) {
110 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true);
111 profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true);
112 ThemeService* theme_service =
113 ThemeServiceFactory::GetForProfile(profile_.get());
114 theme_service->UseDefaultTheme();
115 EXPECT_TRUE(theme_service->UsingDefaultTheme());
116 EXPECT_TRUE(GetThemeSupplier(theme_service));
117 EXPECT_EQ(GetThemeSupplier(theme_service)->GetThemeType(),
118 CustomThemeSupplier::MANAGED_USER_THEME);
119 }
120 #endif
121
122 }; // namespace theme_service_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698