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

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

Issue 11419307: Garbage Collect the Storage directory on next profile start after an extension uninstall. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done done Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extension_prefs_unittest.h" 5 #include "extension_prefs_unittest.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/prefs/public/pref_change_registrar.h" 10 #include "base/prefs/public/pref_change_registrar.h"
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter)); 587 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter));
588 } 588 }
589 } 589 }
590 590
591 private: 591 private:
592 ExtensionList extensions_; 592 ExtensionList extensions_;
593 }; 593 };
594 TEST_F(ExtensionPrefsHidingBrowserActions, ForceHide) {} 594 TEST_F(ExtensionPrefsHidingBrowserActions, ForceHide) {}
595 595
596 // Tests the idle install information functions. 596 // Tests the idle install information functions.
597 class ExtensionPrefsIdleInstallInfo : public ExtensionPrefsTest { 597 class ExtensionPrefsDelayedInstallInfo : public ExtensionPrefsTest {
598 public: 598 public:
599 // Sets idle install information for one test extension. 599 // Sets idle install information for one test extension.
600 void SetIdleInfo(std::string id, int num) { 600 void SetIdleInfo(std::string id, int num) {
601 DictionaryValue manifest; 601 DictionaryValue manifest;
602 manifest.SetString(extension_manifest_keys::kName, "test"); 602 manifest.SetString(extension_manifest_keys::kName, "test");
603 manifest.SetString(extension_manifest_keys::kVersion, 603 manifest.SetString(extension_manifest_keys::kVersion,
604 "1." + base::IntToString(num)); 604 "1." + base::IntToString(num));
605 FilePath path = prefs_.extensions_dir().AppendASCII(base::IntToString(num)); 605 FilePath path = prefs_.extensions_dir().AppendASCII(base::IntToString(num));
606 std::string errors; 606 std::string errors;
607 scoped_refptr<Extension> extension = Extension::Create( 607 scoped_refptr<Extension> extension = Extension::Create(
608 path, Extension::INTERNAL, manifest, Extension::NO_FLAGS, id, &errors); 608 path, Extension::INTERNAL, manifest, Extension::NO_FLAGS, id, &errors);
609 ASSERT_TRUE(extension) << errors; 609 ASSERT_TRUE(extension) << errors;
610 ASSERT_EQ(id, extension->id()); 610 ASSERT_EQ(id, extension->id());
611 prefs()->SetIdleInstallInfo(extension.get(), Extension::ENABLED, 611 prefs()->SetDelayedInstallInfo(extension.get(), Extension::ENABLED,
612 syncer::StringOrdinal()); 612 syncer::StringOrdinal());
613 } 613 }
614 614
615 // Verifies that we get back expected idle install information previously 615 // Verifies that we get back expected idle install information previously
616 // set by SetIdleInfo. 616 // set by SetIdleInfo.
617 void VerifyIdleInfo(std::string id, int num) { 617 void VerifyIdleInfo(std::string id, int num) {
618 scoped_ptr<ExtensionInfo> info(prefs()->GetIdleInstallInfo(id)); 618 scoped_ptr<ExtensionInfo> info(prefs()->GetDelayedInstallInfo(id));
619 ASSERT_TRUE(info); 619 ASSERT_TRUE(info);
620 std::string version; 620 std::string version;
621 ASSERT_TRUE(info->extension_manifest->GetString("version", &version)); 621 ASSERT_TRUE(info->extension_manifest->GetString("version", &version));
622 ASSERT_EQ("1." + base::IntToString(num), version); 622 ASSERT_EQ("1." + base::IntToString(num), version);
623 ASSERT_EQ(base::IntToString(num), 623 ASSERT_EQ(base::IntToString(num),
624 info->extension_path.BaseName().MaybeAsASCII()); 624 info->extension_path.BaseName().MaybeAsASCII());
625 } 625 }
626 626
627 bool HasInfoForId(extensions::ExtensionPrefs::ExtensionsInfo* info, 627 bool HasInfoForId(extensions::ExtensionPrefs::ExtensionsInfo* info,
628 const std::string& id) { 628 const std::string& id) {
(...skipping 11 matching lines...) Expand all
640 id2_ = prefs_.AddExtensionAndReturnId("2"); 640 id2_ = prefs_.AddExtensionAndReturnId("2");
641 id3_ = prefs_.AddExtensionAndReturnId("3"); 641 id3_ = prefs_.AddExtensionAndReturnId("3");
642 id4_ = prefs_.AddExtensionAndReturnId("4"); 642 id4_ = prefs_.AddExtensionAndReturnId("4");
643 643
644 // Set info for two extensions, then remove it. 644 // Set info for two extensions, then remove it.
645 SetIdleInfo(id1_, 1); 645 SetIdleInfo(id1_, 1);
646 SetIdleInfo(id2_, 2); 646 SetIdleInfo(id2_, 2);
647 VerifyIdleInfo(id1_, 1); 647 VerifyIdleInfo(id1_, 1);
648 VerifyIdleInfo(id2_, 2); 648 VerifyIdleInfo(id2_, 2);
649 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info( 649 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
650 prefs()->GetAllIdleInstallInfo()); 650 prefs()->GetAllDelayedInstallInfo());
651 EXPECT_EQ(2u, info->size()); 651 EXPECT_EQ(2u, info->size());
652 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); 652 EXPECT_TRUE(HasInfoForId(info.get(), id1_));
653 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); 653 EXPECT_TRUE(HasInfoForId(info.get(), id2_));
654 prefs()->RemoveIdleInstallInfo(id1_); 654 prefs()->RemoveDelayedInstallInfo(id1_);
655 prefs()->RemoveIdleInstallInfo(id2_); 655 prefs()->RemoveDelayedInstallInfo(id2_);
656 info = prefs()->GetAllIdleInstallInfo(); 656 info = prefs()->GetAllDelayedInstallInfo();
657 EXPECT_TRUE(info->empty()); 657 EXPECT_TRUE(info->empty());
658 658
659 // Try getting/removing info for an id that used to have info set. 659 // Try getting/removing info for an id that used to have info set.
660 EXPECT_FALSE(prefs()->GetIdleInstallInfo(id1_)); 660 EXPECT_FALSE(prefs()->GetDelayedInstallInfo(id1_));
661 EXPECT_FALSE(prefs()->RemoveIdleInstallInfo(id1_)); 661 EXPECT_FALSE(prefs()->RemoveDelayedInstallInfo(id1_));
662 662
663 // Try getting/removing info for an id that has not yet had any info set. 663 // Try getting/removing info for an id that has not yet had any info set.
664 EXPECT_FALSE(prefs()->GetIdleInstallInfo(id3_)); 664 EXPECT_FALSE(prefs()->GetDelayedInstallInfo(id3_));
665 EXPECT_FALSE(prefs()->RemoveIdleInstallInfo(id3_)); 665 EXPECT_FALSE(prefs()->RemoveDelayedInstallInfo(id3_));
666 666
667 // Set info for 4 extensions, then remove for one of them. 667 // Set info for 4 extensions, then remove for one of them.
668 SetIdleInfo(id1_, 1); 668 SetIdleInfo(id1_, 1);
669 SetIdleInfo(id2_, 2); 669 SetIdleInfo(id2_, 2);
670 SetIdleInfo(id3_, 3); 670 SetIdleInfo(id3_, 3);
671 SetIdleInfo(id4_, 4); 671 SetIdleInfo(id4_, 4);
672 VerifyIdleInfo(id1_, 1); 672 VerifyIdleInfo(id1_, 1);
673 VerifyIdleInfo(id2_, 2); 673 VerifyIdleInfo(id2_, 2);
674 VerifyIdleInfo(id3_, 3); 674 VerifyIdleInfo(id3_, 3);
675 VerifyIdleInfo(id4_, 4); 675 VerifyIdleInfo(id4_, 4);
676 prefs()->RemoveIdleInstallInfo(id3_); 676 prefs()->RemoveDelayedInstallInfo(id3_);
677 } 677 }
678 678
679 virtual void Verify() { 679 virtual void Verify() {
680 // Make sure the info for the 3 extensions we expect is present. 680 // Make sure the info for the 3 extensions we expect is present.
681 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info( 681 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
682 prefs()->GetAllIdleInstallInfo()); 682 prefs()->GetAllDelayedInstallInfo());
683 EXPECT_EQ(3u, info->size()); 683 EXPECT_EQ(3u, info->size());
684 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); 684 EXPECT_TRUE(HasInfoForId(info.get(), id1_));
685 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); 685 EXPECT_TRUE(HasInfoForId(info.get(), id2_));
686 EXPECT_TRUE(HasInfoForId(info.get(), id4_)); 686 EXPECT_TRUE(HasInfoForId(info.get(), id4_));
687 VerifyIdleInfo(id1_, 1); 687 VerifyIdleInfo(id1_, 1);
688 VerifyIdleInfo(id2_, 2); 688 VerifyIdleInfo(id2_, 2);
689 VerifyIdleInfo(id4_, 4); 689 VerifyIdleInfo(id4_, 4);
690 690
691 // Make sure there isn't info the for the one extension id we removed. 691 // Make sure there isn't info the for the one extension id we removed.
692 EXPECT_FALSE(prefs()->GetIdleInstallInfo(id3_)); 692 EXPECT_FALSE(prefs()->GetDelayedInstallInfo(id3_));
693 } 693 }
694 694
695 protected: 695 protected:
696 Time now_; 696 Time now_;
697 FilePath basedir_; 697 FilePath basedir_;
698 std::string id1_; 698 std::string id1_;
699 std::string id2_; 699 std::string id2_;
700 std::string id3_; 700 std::string id3_;
701 std::string id4_; 701 std::string id4_;
702 }; 702 };
703 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} 703 TEST_F(ExtensionPrefsDelayedInstallInfo, DelayedInstallInfo) {}
704 704
705 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { 705 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest {
706 public: 706 public:
707 virtual void Initialize() { 707 virtual void Initialize() {
708 extension_ = prefs_.AddExtension("on_extension_installed"); 708 extension_ = prefs_.AddExtension("on_extension_installed");
709 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); 709 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id()));
710 prefs()->OnExtensionInstalled( 710 prefs()->OnExtensionInstalled(
711 extension_.get(), Extension::DISABLED, 711 extension_.get(), Extension::DISABLED,
712 syncer::StringOrdinal()); 712 syncer::StringOrdinal());
713 } 713 }
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 1262
1263 private: 1263 private:
1264 scoped_refptr<const Extension> extension_a_; 1264 scoped_refptr<const Extension> extension_a_;
1265 scoped_refptr<const Extension> extension_b_; 1265 scoped_refptr<const Extension> extension_b_;
1266 scoped_refptr<const Extension> extension_c_; 1266 scoped_refptr<const Extension> extension_c_;
1267 }; 1267 };
1268 TEST_F(ExtensionPrefsBlacklistedExtensions, 1268 TEST_F(ExtensionPrefsBlacklistedExtensions,
1269 ExtensionPrefsBlacklistedExtensions) {} 1269 ExtensionPrefsBlacklistedExtensions) {}
1270 1270
1271 } // namespace extensions 1271 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.cc ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698