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

Side by Side Diff: chrome/browser/extensions/extensions_service_unittest.cc

Issue 174036: Get rid of the extension's "Current Version" file. (Closed)
Patch Set: merge conflicts Created 11 years, 4 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
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; 629 extension_manifest_errors::kMissingFile)) << GetErrors()[2];
630 630
631 EXPECT_TRUE(MatchPattern(GetErrors()[3], 631 EXPECT_TRUE(MatchPattern(GetErrors()[3],
632 std::string("Could not load extension from '*'. ") + 632 std::string("Could not load extension from '*'. ") +
633 extension_manifest_errors::kInvalidManifest)) << GetErrors()[3]; 633 extension_manifest_errors::kInvalidManifest)) << GetErrors()[3];
634 }; 634 };
635 635
636 // Test that partially deleted extensions are cleaned up during startup 636 // Test that partially deleted extensions are cleaned up during startup
637 // Test loading bad extensions from the profile directory. 637 // Test loading bad extensions from the profile directory.
638 TEST_F(ExtensionsServiceTest, CleanupOnStartup) { 638 TEST_F(ExtensionsServiceTest, CleanupOnStartup) {
639 InitializeEmptyExtensionsService(); 639 FilePath source_install_dir;
640 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
641 source_install_dir = source_install_dir
642 .AppendASCII("extensions")
643 .AppendASCII("good")
644 .AppendASCII("Extensions");
645 FilePath pref_path = source_install_dir
646 .DirName()
647 .AppendASCII("Preferences");
640 648
641 FilePath source_path; 649 InitializeInstalledExtensionsService(pref_path, source_install_dir);
642 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_path));
643 source_path = source_path.AppendASCII("extensions")
644 .AppendASCII("good")
645 .AppendASCII("Extensions");
646 650
647 file_util::Delete(extensions_install_dir_, true); 651 // Simulate that one of them got partially deleted by clearing its pref.
648 652 prefs_->GetMutableDictionary(L"extensions.settings")->
649 // Recursive. 653 Remove(L"behllobkkfkfnphdnhnkndlbkcpglgmj", NULL);
650 file_util::CopyDirectory(source_path, extensions_install_dir_, true);
651
652 // Simulate that one of them got partially deleted by deling the
653 // Current Version file.
654 FilePath vers = extensions_install_dir_
655 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
656 .AppendASCII(ExtensionsService::kCurrentVersionFileName);
657 ASSERT_TRUE(file_util::Delete(vers, false)); // not recursive
658 654
659 service_->Init(); 655 service_->Init();
660 loop_.RunAllPending(); 656 loop_.RunAllPending();
661 657
662 file_util::FileEnumerator dirs(extensions_install_dir_, false, 658 file_util::FileEnumerator dirs(extensions_install_dir_, false,
663 file_util::FileEnumerator::DIRECTORIES); 659 file_util::FileEnumerator::DIRECTORIES);
664 size_t count = 0; 660 size_t count = 0;
665 while (!dirs.Next().empty()) 661 while (!dirs.Next().empty())
666 count++; 662 count++;
667 663
668 // We should have only gotten two extensions now. 664 // We should have only gotten two extensions now.
669 EXPECT_EQ(2u, count); 665 EXPECT_EQ(2u, count);
670 666
671 // And extension1 dir should now be toast. 667 // And extension1 dir should now be toast.
672 vers = vers.DirName(); 668 FilePath extension_dir = extensions_install_dir_
673 ASSERT_FALSE(file_util::PathExists(vers)); 669 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj");
670 ASSERT_FALSE(file_util::PathExists(extension_dir));
674 } 671 }
675 672
676 // Test installing extensions. This test tries to install few extensions using 673 // Test installing extensions. This test tries to install few extensions using
677 // crx files. If you need to change those crx files, feel free to repackage 674 // crx files. If you need to change those crx files, feel free to repackage
678 // them, throw away the key used and change the id's above. 675 // them, throw away the key used and change the id's above.
679 TEST_F(ExtensionsServiceTest, InstallExtension) { 676 TEST_F(ExtensionsServiceTest, InstallExtension) {
680 InitializeEmptyExtensionsService(); 677 InitializeEmptyExtensionsService();
681 678
682 FilePath extensions_path; 679 FilePath extensions_path;
683 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 680 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 EXPECT_EQ(extension_id, unloaded_id_); 1138 EXPECT_EQ(extension_id, unloaded_id_);
1142 1139
1143 ValidatePrefKeyCount(0); 1140 ValidatePrefKeyCount(0);
1144 1141
1145 // The extension should not be in the service anymore. 1142 // The extension should not be in the service anymore.
1146 ASSERT_FALSE(service_->GetExtensionById(extension_id)); 1143 ASSERT_FALSE(service_->GetExtensionById(extension_id));
1147 loop_.RunAllPending(); 1144 loop_.RunAllPending();
1148 1145
1149 // The directory should be gone. 1146 // The directory should be gone.
1150 EXPECT_FALSE(file_util::PathExists(extension_path)); 1147 EXPECT_FALSE(file_util::PathExists(extension_path));
1151
1152 // Try uinstalling one that doesn't have a Current Version file for some
1153 // reason.
1154 unloaded_id_.clear();
1155 InstallExtension(path, true);
1156 FilePath current_version_file =
1157 extension_path.AppendASCII(ExtensionsService::kCurrentVersionFileName);
1158 EXPECT_TRUE(file_util::Delete(current_version_file, true));
1159 service_->UninstallExtension(extension_id, false);
1160 loop_.RunAllPending();
1161 EXPECT_FALSE(file_util::PathExists(extension_path));
1162
1163 ValidatePrefKeyCount(0);
1164 } 1148 }
1165 1149
1166 // Tests loading single extensions (like --load-extension) 1150 // Tests loading single extensions (like --load-extension)
1167 TEST_F(ExtensionsServiceTest, LoadExtension) { 1151 TEST_F(ExtensionsServiceTest, LoadExtension) {
1168 InitializeEmptyExtensionsService(); 1152 InitializeEmptyExtensionsService();
1169 FilePath extensions_path; 1153 FilePath extensions_path;
1170 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1154 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1171 extensions_path = extensions_path.AppendASCII("extensions"); 1155 extensions_path = extensions_path.AppendASCII("extensions");
1172 1156
1173 FilePath ext1 = extensions_path 1157 FilePath ext1 = extensions_path
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 1567
1584 recorder.set_ready(false); 1568 recorder.set_ready(false);
1585 command_line.reset(new CommandLine(L"")); 1569 command_line.reset(new CommandLine(L""));
1586 service = new ExtensionsService(&profile, command_line.get(), 1570 service = new ExtensionsService(&profile, command_line.get(),
1587 profile.GetPrefs(), install_dir, &loop, &loop, false); 1571 profile.GetPrefs(), install_dir, &loop, &loop, false);
1588 EXPECT_TRUE(service->extensions_enabled()); 1572 EXPECT_TRUE(service->extensions_enabled());
1589 service->Init(); 1573 service->Init();
1590 loop.RunAllPending(); 1574 loop.RunAllPending();
1591 EXPECT_TRUE(recorder.ready()); 1575 EXPECT_TRUE(recorder.ready());
1592 } 1576 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698