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

Unified Diff: chrome/browser/themes/theme_service_unittest.cc

Issue 1319073005: Make ThemeService not disable uninstalled themes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_build
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/themes/theme_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c1eb7cf0bdca8c0b7c590b97ef9f32ab853d7f5f..4ea081cef6846114feee6b3fa20293a3dc737f29 100644
--- a/chrome/browser/themes/theme_service_unittest.cc
+++ b/chrome/browser/themes/theme_service_unittest.cc
@@ -17,6 +17,8 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/test_extension_registry_observer.h"
@@ -237,6 +239,72 @@ TEST_F(ThemeServiceTest, ThemeUpgrade) {
ExtensionRegistry::DISABLED));
}
+namespace {
+
+// NotificationObserver which emulates an infobar getting destroyed when the
+// theme changes.
+class InfobarDestroyerOnThemeChange : public content::NotificationObserver {
+ public:
+ InfobarDestroyerOnThemeChange(Profile* profile)
+ : theme_service_(ThemeServiceFactory::GetForProfile(profile)) {
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
+ content::Source<ThemeService>(theme_service_));
+ }
+
+ ~InfobarDestroyerOnThemeChange() override {}
+
+ private:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override {
+ theme_service_->OnInfobarDestroyed();
+ }
+
+ // Not owned.
+ ThemeService* theme_service_;
+
+ content::NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(InfobarDestroyerOnThemeChange);
+};
+
+} // namespace
+
+// crbug.com/468280
+TEST_F(ThemeServiceTest, UninstallThemeOnThemeChangeNotification) {
+ // Setup.
+ ThemeService* theme_service =
+ ThemeServiceFactory::GetForProfile(profile_.get());
+ theme_service->UseDefaultTheme();
+ // Let the ThemeService uninstall unused themes.
+ base::MessageLoop::current()->RunUntilIdle();
+
+ base::ScopedTempDir temp_dir1;
+ ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
+ base::ScopedTempDir temp_dir2;
+ ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
+
+ const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path());
+ ASSERT_EQ(extension1_id, theme_service->GetThemeID());
+
+ // Show an infobar.
+ theme_service->OnInfobarDisplayed();
+
+ // Install another theme. Emulate the infobar destroying itself (and
+ // causing unused themes to be uninstalled) as a result of the
+ // NOTIFICATION_BROWSER_THEME_CHANGED notification.
+ {
+ InfobarDestroyerOnThemeChange destroyer(profile_.get());
+ const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path());
+ ASSERT_EQ(extension2_id, theme_service->GetThemeID());
+ ASSERT_FALSE(service_->GetInstalledExtension(extension1_id));
+ }
+
+ // Check that it is possible to reinstall extension1.
+ ASSERT_EQ(extension1_id, LoadUnpackedThemeAt(temp_dir1.path()));
+ EXPECT_EQ(extension1_id, theme_service->GetThemeID());
+}
+
#if defined(ENABLE_SUPERVISED_USERS)
class ThemeServiceSupervisedUserTest : public ThemeServiceTest {
public:
« no previous file with comments | « chrome/browser/themes/theme_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698