Commit 740d6dec authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

Settings WebUI: use system theme when theme id is specified and system theme setting is true

Bug: 810636
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ie72810052b3b379f2b5d6bc26d5c6e08a00c330b
Reviewed-on: https://chromium-review.googlesource.com/959238Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544097}
parent b2d52381
......@@ -274,7 +274,7 @@ Polymer({
* @private
*/
themeChanged_: function(themeId, useSystemTheme) {
if (themeId) {
if (themeId.length > 0) {
assert(!useSystemTheme);
this.browserProxy_.getThemeInfo(themeId).then(info => {
......
......@@ -566,7 +566,10 @@ void ThemeService::ClearAllThemeData() {
weak_ptr_factory_.GetWeakPtr(), true));
}
void ThemeService::FixInconsistentPreferencesIfNeeded() {}
void ThemeService::LoadThemePrefs() {
FixInconsistentPreferencesIfNeeded();
PrefService* prefs = profile_->GetPrefs();
std::string current_id = GetThemeID();
......
......@@ -171,6 +171,10 @@ class ThemeService : public content::NotificationObserver, public KeyedService {
virtual bool ShouldUseNativeFrame() const;
bool HasCustomImage(int id) const;
// If there is an inconsistency in preferences, change preferences to a
// consistent state.
virtual void FixInconsistentPreferencesIfNeeded();
Profile* profile() const { return profile_; }
void set_ready() { ready_ = true; }
......
......@@ -101,3 +101,14 @@ bool ThemeServiceAuraX11::UsingSystemTheme() const {
return theme_supplier &&
theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;
}
void ThemeServiceAuraX11::FixInconsistentPreferencesIfNeeded() {
PrefService* prefs = profile()->GetPrefs();
// When using the system theme, the theme ID should match the default. Give
// precedence to the non-default theme specified.
if (GetThemeID() != ThemeService::kDefaultThemeID &&
prefs->GetBoolean(prefs::kUsesSystemTheme)) {
prefs->SetBoolean(prefs::kUsesSystemTheme, false);
}
}
......@@ -21,6 +21,7 @@ class ThemeServiceAuraX11 : public ThemeService {
bool IsSystemThemeDistinctFromDefaultTheme() const override;
bool UsingDefaultTheme() const override;
bool UsingSystemTheme() const override;
void FixInconsistentPreferencesIfNeeded() override;
private:
DISALLOW_COPY_AND_ASSIGN(ThemeServiceAuraX11);
......
......@@ -400,6 +400,26 @@ TEST_F(ThemeServiceSupervisedUserTest, SupervisedUserThemeReplacesNativeTheme) {
EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
CustomThemeSupplier::SUPERVISED_USER_THEME);
}
TEST_F(ThemeServiceTest, UserThemeTakesPrecedenceOverSystemTheme) {
ThemeService* theme_service =
ThemeServiceFactory::GetForProfile(profile_.get());
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
const std::string& extension_id = LoadUnpackedThemeAt(temp_dir.GetPath());
ASSERT_EQ(extension_id, theme_service->GetThemeID());
// Set preference |prefs::kUsesSystemTheme| to true which conflicts with
// having a user theme selected.
profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true);
EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme));
// Initialization should fix the preference inconsistency.
theme_service->Init(profile_.get());
ASSERT_EQ(extension_id, theme_service->GetThemeID());
EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme));
}
#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment