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 20386f733401266f9203c6bcca6bbb0f3bfbf622..89848b089ae980c9a95c8ac65693993f919d9c3a 100644 |
--- a/chrome/browser/extensions/extension_service_unittest.cc |
+++ b/chrome/browser/extensions/extension_service_unittest.cc |
@@ -246,7 +246,6 @@ class MockExtensionProvider : public ExternalExtensionProviderInterface { |
class MockProviderVisitor |
: public ExternalExtensionProviderInterface::VisitorInterface { |
public: |
- |
// The provider will return |fake_base_path| from |
// GetBaseCrxFilePath(). User can test the behavior with |
// and without an empty path using this parameter. |
@@ -1014,7 +1013,6 @@ void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
FAIL() << "Packing should not fail."; |
else |
FAIL() << "Existing CRX should have been overwritten."; |
- |
} |
// Test loading good extensions from the profile directory. |
@@ -1158,7 +1156,7 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
UTF16ToUTF8(GetErrors()[3]); |
}; |
-// Test that partially deleted extensions are cleaned up during startup |
+// Test that partially deleted extensions are cleaned up during startup. |
Yoyo Zhou
2012/03/21 22:55:37
This test seems to be testing that extensions who
|
// Test loading bad extensions from the profile directory. |
TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
PluginService::GetInstance()->Init(); |
@@ -1199,6 +1197,93 @@ TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
ASSERT_FALSE(file_util::PathExists(extension_dir)); |
} |
+// Test that internal extensions which are referenced in the preferences but |
+// had their content deleted are cleaned up during startup. |
+TEST_F(ExtensionServiceTest, CleanupInternalExtensionsMissingLocalContent) { |
+ PluginService::GetInstance()->Init(); |
+ |
+ FilePath source_dir = data_dir_.AppendASCII("good").AppendASCII("Extensions"); |
+ FilePath pref_path = source_dir.DirName().AppendASCII("Preferences"); |
+ |
+ InitializeInstalledExtensionService(pref_path, source_dir); |
+ |
+ // Delete the extension's directory. |
+ FilePath extension_dir = extensions_install_dir_ |
+ .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); |
+ ASSERT_TRUE(file_util::Delete(extension_dir, true)); |
+ |
+ // Run GarbageCollectExtensions. |
+ service_->Init(); |
+ loop_.RunAllPending(); |
+ |
+ file_util::FileEnumerator dirs(extensions_install_dir_, false, |
+ file_util::FileEnumerator::DIRECTORIES); |
+ size_t count = 0; |
+ while (!dirs.Next().empty()) |
+ count++; |
+ |
+ // We should have only gotten two extensions now. |
+ EXPECT_EQ(2u, count); |
+ |
+ DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
+ DictionaryValue* dictionary = update.Get(); |
+ ASSERT_TRUE(dictionary != NULL); |
Yoyo Zhou
2012/03/21 22:55:37
nit: usually written as just ASSERT_TRUE(dictionar
|
+ ASSERT_FALSE(dictionary->HasKey("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
+} |
+ |
+// Test that external extensions which are referenced in the preferences but |
Yoyo Zhou
2012/03/21 22:55:37
nit: write 'unpacked' instead of 'external'
|
+// had their content deleted are cleaned up during startup. |
+TEST_F(ExtensionServiceTest, CleanupUnpackedExtensionsMissingLocalContent) { |
+ InitializeEmptyExtensionService(); |
+ |
+ ScopedTempDir temp; |
+ ASSERT_TRUE(temp.CreateUniqueTempDir()); |
+ |
+ // Write the manifest dynamically, since we have to delete the file anyway. |
+ FilePath extension_path = temp.path(); |
+ FilePath manifest_path = extension_path.Append(Extension::kManifestFilename); |
+ ASSERT_FALSE(file_util::PathExists(manifest_path)); |
+ |
+ // Construct a simple manifest and install it. |
+ DictionaryValue manifest; |
+ manifest.SetString("version", "1.0"); |
+ manifest.SetString("name", "Cleanup Unpacked Extensions Missing Content"); |
+ manifest.SetInteger("manifest_version", 2); |
+ |
+ JSONFileValueSerializer serializer(manifest_path); |
+ ASSERT_TRUE(serializer.Serialize(manifest)); |
+ |
+ extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
+ loop_.RunAllPending(); |
+ |
+ // Make sure it installed correctly. |
+ EXPECT_EQ(0u, GetErrors().size()); |
+ ASSERT_EQ(1u, loaded_.size()); |
+ EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); |
+ EXPECT_EQ(1u, service_->extensions()->size()); |
+ |
+ std::string extension_id = loaded_[0]->id(); |
+ |
+ // Make sure it is in the preferences at this point. |
+ DictionaryPrefUpdate initial_update( |
+ profile_->GetPrefs(), "extensions.settings"); |
+ DictionaryValue* initial_dictionary = initial_update.Get(); |
+ ASSERT_TRUE(initial_dictionary != NULL); |
+ ASSERT_TRUE(initial_dictionary->HasKey(extension_id)); |
+ |
+ // Delete local content, GarbageCollectExtensions, and test whether the key |
+ // is still in the preferences. |
+ ASSERT_TRUE(file_util::Delete(extension_path, true)); |
+ service_->GarbageCollectExtensions(); |
+ loop_.RunAllPending(); |
+ |
+ DictionaryPrefUpdate final_update( |
+ profile_->GetPrefs(), "extensions.settings"); |
+ DictionaryValue* final_dictionary = final_update.Get(); |
+ ASSERT_TRUE(final_dictionary != NULL); |
+ ASSERT_FALSE(final_dictionary->HasKey(extension_id)); |
+} |
+ |
// Test installing extensions. This test tries to install few extensions using |
// crx files. If you need to change those crx files, feel free to repackage |
// them, throw away the key used and change the id's above. |