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

Unified Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 217233004: Revert of Remove ExtensionService Garbage-Collecting methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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/extensions/extension_service.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_service_unittest.cc
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index b88d74f4dfa7e3ec3085d505dd2e37b4e8d9fa6a..3834a7c619a88357fe36fdafa20032af9b593694 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -1465,6 +1465,118 @@
base::UTF16ToUTF8(GetErrors()[3]);
};
+// Test that partially deleted extensions are cleaned up during startup
+// Test loading bad extensions from the profile directory.
+TEST_F(ExtensionServiceTest, CleanupOnStartup) {
+ InitPluginService();
+ InitializeGoodInstalledExtensionService();
+
+ // Simulate that one of them got partially deleted by clearing its pref.
+ {
+ DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings");
+ base::DictionaryValue* dict = update.Get();
+ ASSERT_TRUE(dict != NULL);
+ dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL);
+ }
+
+ service_->Init();
+ // A delayed task to call GarbageCollectExtensions is posted by
+ // ExtensionService::Init. As the test won't wait for the delayed task to
+ // be called, call it manually instead.
+ service_->GarbageCollectExtensions();
+ // Wait for GarbageCollectExtensions task to complete.
+ base::RunLoop().RunUntilIdle();
+
+ base::FileEnumerator dirs(extensions_install_dir_, false,
+ base::FileEnumerator::DIRECTORIES);
+ size_t count = 0;
+ while (!dirs.Next().empty())
+ count++;
+
+ // We should have only gotten two extensions now.
+ EXPECT_EQ(2u, count);
+
+ // And extension1 dir should now be toast.
+ base::FilePath extension_dir = extensions_install_dir_
+ .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj");
+ ASSERT_FALSE(base::PathExists(extension_dir));
+}
+
+// Test that GarbageCollectExtensions deletes the right versions of an
+// extension.
+TEST_F(ExtensionServiceTest, GarbageCollectWithPendingUpdates) {
+ InitPluginService();
+
+ base::FilePath source_install_dir = data_dir_
+ .AppendASCII("pending_updates")
+ .AppendASCII("Extensions");
+ base::FilePath pref_path =
+ source_install_dir.DirName().Append(chrome::kPreferencesFilename);
+
+ InitializeInstalledExtensionService(pref_path, source_install_dir);
+
+ // This is the directory that is going to be deleted, so make sure it actually
+ // is there before the garbage collection.
+ ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "hpiknbiabeeppbpihjehijgoemciehgk/3")));
+
+ service_->GarbageCollectExtensions();
+ // Wait for GarbageCollectExtensions task to complete.
+ base::RunLoop().RunUntilIdle();
+
+ // Verify that the pending update for the first extension didn't get
+ // deleted.
+ EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
+ EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0")));
+ EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "hpiknbiabeeppbpihjehijgoemciehgk/2")));
+ EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "hpiknbiabeeppbpihjehijgoemciehgk/3")));
+}
+
+// Test that pending updates are properly handled on startup.
+TEST_F(ExtensionServiceTest, UpdateOnStartup) {
+ InitPluginService();
+
+ base::FilePath source_install_dir = data_dir_
+ .AppendASCII("pending_updates")
+ .AppendASCII("Extensions");
+ base::FilePath pref_path =
+ source_install_dir.DirName().Append(chrome::kPreferencesFilename);
+
+ InitializeInstalledExtensionService(pref_path, source_install_dir);
+
+ // This is the directory that is going to be deleted, so make sure it actually
+ // is there before the garbage collection.
+ ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "hpiknbiabeeppbpihjehijgoemciehgk/3")));
+
+ service_->Init();
+ // A delayed task to call GarbageCollectExtensions is posted by
+ // ExtensionService::Init. As the test won't wait for the delayed task to
+ // be called, call it manually instead.
+ service_->GarbageCollectExtensions();
+ // Wait for GarbageCollectExtensions task to complete.
+ base::RunLoop().RunUntilIdle();
+
+ // Verify that the pending update for the first extension got installed.
+ EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
+ EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0")));
+ EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "hpiknbiabeeppbpihjehijgoemciehgk/2")));
+ EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII(
+ "hpiknbiabeeppbpihjehijgoemciehgk/3")));
+
+ // Make sure update information got deleted.
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get());
+ EXPECT_FALSE(
+ prefs->GetDelayedInstallInfo("bjafgdebaacbbbecmhlhpofkepfkgcpa"));
+}
+
// Test various cases for delayed install because of missing imports.
TEST_F(ExtensionServiceTest, PendingImports) {
InitPluginService();
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698