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

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

Issue 22794012: Rename extension_manifest_keys namespace to extensions::manifest_keys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | 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 "chrome/browser/extensions/extension_prefs_unittest.h" 5 #include "chrome/browser/extensions/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/mock_pref_change_callback.h" 10 #include "base/prefs/mock_pref_change_callback.h"
11 #include "base/prefs/pref_change_registrar.h" 11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/extensions/extension_pref_value_map.h" 16 #include "chrome/browser/extensions/extension_pref_value_map.h"
17 #include "chrome/browser/extensions/extension_prefs.h" 17 #include "chrome/browser/extensions/extension_prefs.h"
18 #include "chrome/browser/prefs/pref_service_syncable.h" 18 #include "chrome/browser/prefs/pref_service_syncable.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 19 #include "chrome/browser/prefs/scoped_user_pref_update.h"
20 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/extensions/extension_manifest_constants.h"
22 #include "chrome/common/extensions/permissions/permission_set.h" 21 #include "chrome/common/extensions/permissions/permission_set.h"
23 #include "chrome/common/extensions/permissions/permissions_info.h" 22 #include "chrome/common/extensions/permissions/permissions_info.h"
24 #include "components/user_prefs/pref_registry_syncable.h" 23 #include "components/user_prefs/pref_registry_syncable.h"
25 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
27 #include "content/public/test/mock_notification_observer.h" 26 #include "content/public/test/mock_notification_observer.h"
27 #include "extensions/common/manifest_constants.h"
28 #include "sync/api/string_ordinal.h" 28 #include "sync/api/string_ordinal.h"
29 29
30 using base::Time; 30 using base::Time;
31 using base::TimeDelta; 31 using base::TimeDelta;
32 using content::BrowserThread; 32 using content::BrowserThread;
33 33
34 namespace extensions { 34 namespace extensions {
35 35
36 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 36 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
37 int schemes = URLPattern::SCHEME_ALL; 37 int schemes = URLPattern::SCHEME_ALL;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 std::string blacklisted_id_; 434 std::string blacklisted_id_;
435 }; 435 };
436 TEST_F(ExtensionPrefsAcknowledgment, Acknowledgment) {} 436 TEST_F(ExtensionPrefsAcknowledgment, Acknowledgment) {}
437 437
438 // Tests the idle install information functions. 438 // Tests the idle install information functions.
439 class ExtensionPrefsDelayedInstallInfo : public ExtensionPrefsTest { 439 class ExtensionPrefsDelayedInstallInfo : public ExtensionPrefsTest {
440 public: 440 public:
441 // Sets idle install information for one test extension. 441 // Sets idle install information for one test extension.
442 void SetIdleInfo(std::string id, int num) { 442 void SetIdleInfo(std::string id, int num) {
443 DictionaryValue manifest; 443 DictionaryValue manifest;
444 manifest.SetString(extension_manifest_keys::kName, "test"); 444 manifest.SetString(manifest_keys::kName, "test");
445 manifest.SetString(extension_manifest_keys::kVersion, 445 manifest.SetString(manifest_keys::kVersion,
446 "1." + base::IntToString(num)); 446 "1." + base::IntToString(num));
447 base::FilePath path = 447 base::FilePath path =
448 prefs_.extensions_dir().AppendASCII(base::IntToString(num)); 448 prefs_.extensions_dir().AppendASCII(base::IntToString(num));
449 std::string errors; 449 std::string errors;
450 scoped_refptr<Extension> extension = Extension::Create( 450 scoped_refptr<Extension> extension = Extension::Create(
451 path, Manifest::INTERNAL, manifest, Extension::NO_FLAGS, id, &errors); 451 path, Manifest::INTERNAL, manifest, Extension::NO_FLAGS, id, &errors);
452 ASSERT_TRUE(extension.get()) << errors; 452 ASSERT_TRUE(extension.get()) << errors;
453 ASSERT_EQ(id, extension->id()); 453 ASSERT_EQ(id, extension->id());
454 prefs()->SetDelayedInstallInfo(extension.get(), 454 prefs()->SetDelayedInstallInfo(extension.get(),
455 Extension::ENABLED, 455 Extension::ENABLED,
456 Blacklist::NOT_BLACKLISTED, 456 Blacklist::NOT_BLACKLISTED,
457 ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, 457 ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
458 syncer::StringOrdinal()); 458 syncer::StringOrdinal());
459 } 459 }
460 460
461 // Verifies that we get back expected idle install information previously 461 // Verifies that we get back expected idle install information previously
462 // set by SetIdleInfo. 462 // set by SetIdleInfo.
463 void VerifyIdleInfo(std::string id, int num) { 463 void VerifyIdleInfo(std::string id, int num) {
464 scoped_ptr<ExtensionInfo> info(prefs()->GetDelayedInstallInfo(id)); 464 scoped_ptr<ExtensionInfo> info(prefs()->GetDelayedInstallInfo(id));
465 ASSERT_TRUE(info); 465 ASSERT_TRUE(info);
466 std::string version; 466 std::string version;
467 ASSERT_TRUE(info->extension_manifest->GetString("version", &version)); 467 ASSERT_TRUE(info->extension_manifest->GetString("version", &version));
468 ASSERT_EQ("1." + base::IntToString(num), version); 468 ASSERT_EQ("1." + base::IntToString(num), version);
469 ASSERT_EQ(base::IntToString(num), 469 ASSERT_EQ(base::IntToString(num),
470 info->extension_path.BaseName().MaybeAsASCII()); 470 info->extension_path.BaseName().MaybeAsASCII());
471 } 471 }
472 472
473 bool HasInfoForId(extensions::ExtensionPrefs::ExtensionsInfo* info, 473 bool HasInfoForId(ExtensionPrefs::ExtensionsInfo* info,
474 const std::string& id) { 474 const std::string& id) {
475 for (size_t i = 0; i < info->size(); ++i) { 475 for (size_t i = 0; i < info->size(); ++i) {
476 if (info->at(i)->extension_id == id) 476 if (info->at(i)->extension_id == id)
477 return true; 477 return true;
478 } 478 }
479 return false; 479 return false;
480 } 480 }
481 481
482 virtual void Initialize() OVERRIDE { 482 virtual void Initialize() OVERRIDE {
483 PathService::Get(chrome::DIR_TEST_DATA, &basedir_); 483 PathService::Get(chrome::DIR_TEST_DATA, &basedir_);
484 now_ = Time::Now(); 484 now_ = Time::Now();
485 id1_ = prefs_.AddExtensionAndReturnId("1"); 485 id1_ = prefs_.AddExtensionAndReturnId("1");
486 id2_ = prefs_.AddExtensionAndReturnId("2"); 486 id2_ = prefs_.AddExtensionAndReturnId("2");
487 id3_ = prefs_.AddExtensionAndReturnId("3"); 487 id3_ = prefs_.AddExtensionAndReturnId("3");
488 id4_ = prefs_.AddExtensionAndReturnId("4"); 488 id4_ = prefs_.AddExtensionAndReturnId("4");
489 489
490 // Set info for two extensions, then remove it. 490 // Set info for two extensions, then remove it.
491 SetIdleInfo(id1_, 1); 491 SetIdleInfo(id1_, 1);
492 SetIdleInfo(id2_, 2); 492 SetIdleInfo(id2_, 2);
493 VerifyIdleInfo(id1_, 1); 493 VerifyIdleInfo(id1_, 1);
494 VerifyIdleInfo(id2_, 2); 494 VerifyIdleInfo(id2_, 2);
495 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info( 495 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
496 prefs()->GetAllDelayedInstallInfo()); 496 prefs()->GetAllDelayedInstallInfo());
497 EXPECT_EQ(2u, info->size()); 497 EXPECT_EQ(2u, info->size());
498 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); 498 EXPECT_TRUE(HasInfoForId(info.get(), id1_));
499 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); 499 EXPECT_TRUE(HasInfoForId(info.get(), id2_));
500 prefs()->RemoveDelayedInstallInfo(id1_); 500 prefs()->RemoveDelayedInstallInfo(id1_);
501 prefs()->RemoveDelayedInstallInfo(id2_); 501 prefs()->RemoveDelayedInstallInfo(id2_);
502 info = prefs()->GetAllDelayedInstallInfo(); 502 info = prefs()->GetAllDelayedInstallInfo();
503 EXPECT_TRUE(info->empty()); 503 EXPECT_TRUE(info->empty());
504 504
505 // Try getting/removing info for an id that used to have info set. 505 // Try getting/removing info for an id that used to have info set.
(...skipping 11 matching lines...) Expand all
517 SetIdleInfo(id4_, 4); 517 SetIdleInfo(id4_, 4);
518 VerifyIdleInfo(id1_, 1); 518 VerifyIdleInfo(id1_, 1);
519 VerifyIdleInfo(id2_, 2); 519 VerifyIdleInfo(id2_, 2);
520 VerifyIdleInfo(id3_, 3); 520 VerifyIdleInfo(id3_, 3);
521 VerifyIdleInfo(id4_, 4); 521 VerifyIdleInfo(id4_, 4);
522 prefs()->RemoveDelayedInstallInfo(id3_); 522 prefs()->RemoveDelayedInstallInfo(id3_);
523 } 523 }
524 524
525 virtual void Verify() OVERRIDE { 525 virtual void Verify() OVERRIDE {
526 // Make sure the info for the 3 extensions we expect is present. 526 // Make sure the info for the 3 extensions we expect is present.
527 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info( 527 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
528 prefs()->GetAllDelayedInstallInfo()); 528 prefs()->GetAllDelayedInstallInfo());
529 EXPECT_EQ(3u, info->size()); 529 EXPECT_EQ(3u, info->size());
530 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); 530 EXPECT_TRUE(HasInfoForId(info.get(), id1_));
531 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); 531 EXPECT_TRUE(HasInfoForId(info.get(), id2_));
532 EXPECT_TRUE(HasInfoForId(info.get(), id4_)); 532 EXPECT_TRUE(HasInfoForId(info.get(), id4_));
533 VerifyIdleInfo(id1_, 1); 533 VerifyIdleInfo(id1_, 1);
534 VerifyIdleInfo(id2_, 2); 534 VerifyIdleInfo(id2_, 2);
535 VerifyIdleInfo(id4_, 4); 535 VerifyIdleInfo(id4_, 4);
536 536
537 // Make sure there isn't info the for the one extension id we removed. 537 // Make sure there isn't info the for the one extension id we removed.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 private: 593 private:
594 scoped_refptr<Extension> extension_; 594 scoped_refptr<Extension> extension_;
595 }; 595 };
596 TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {} 596 TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {}
597 597
598 class ExtensionPrefsFlags : public ExtensionPrefsTest { 598 class ExtensionPrefsFlags : public ExtensionPrefsTest {
599 public: 599 public:
600 virtual void Initialize() OVERRIDE { 600 virtual void Initialize() OVERRIDE {
601 { 601 {
602 base::DictionaryValue dictionary; 602 base::DictionaryValue dictionary;
603 dictionary.SetString(extension_manifest_keys::kName, "from_webstore"); 603 dictionary.SetString(manifest_keys::kName, "from_webstore");
604 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); 604 dictionary.SetString(manifest_keys::kVersion, "0.1");
605 webstore_extension_ = prefs_.AddExtensionWithManifestAndFlags( 605 webstore_extension_ = prefs_.AddExtensionWithManifestAndFlags(
606 dictionary, Manifest::INTERNAL, Extension::FROM_WEBSTORE); 606 dictionary, Manifest::INTERNAL, Extension::FROM_WEBSTORE);
607 } 607 }
608 608
609 { 609 {
610 base::DictionaryValue dictionary; 610 base::DictionaryValue dictionary;
611 dictionary.SetString(extension_manifest_keys::kName, "from_bookmark"); 611 dictionary.SetString(manifest_keys::kName, "from_bookmark");
612 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); 612 dictionary.SetString(manifest_keys::kVersion, "0.1");
613 bookmark_extension_ = prefs_.AddExtensionWithManifestAndFlags( 613 bookmark_extension_ = prefs_.AddExtensionWithManifestAndFlags(
614 dictionary, Manifest::INTERNAL, Extension::FROM_BOOKMARK); 614 dictionary, Manifest::INTERNAL, Extension::FROM_BOOKMARK);
615 } 615 }
616 616
617 { 617 {
618 base::DictionaryValue dictionary; 618 base::DictionaryValue dictionary;
619 dictionary.SetString(extension_manifest_keys::kName, 619 dictionary.SetString(manifest_keys::kName,
620 "was_installed_by_default"); 620 "was_installed_by_default");
621 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); 621 dictionary.SetString(manifest_keys::kVersion, "0.1");
622 default_extension_ = prefs_.AddExtensionWithManifestAndFlags( 622 default_extension_ = prefs_.AddExtensionWithManifestAndFlags(
623 dictionary, 623 dictionary,
624 Manifest::INTERNAL, 624 Manifest::INTERNAL,
625 Extension::WAS_INSTALLED_BY_DEFAULT); 625 Extension::WAS_INSTALLED_BY_DEFAULT);
626 } 626 }
627 } 627 }
628 628
629 virtual void Verify() OVERRIDE { 629 virtual void Verify() OVERRIDE {
630 EXPECT_TRUE(prefs()->IsFromWebStore(webstore_extension_->id())); 630 EXPECT_TRUE(prefs()->IsFromWebStore(webstore_extension_->id()));
631 EXPECT_FALSE(prefs()->IsFromBookmark(webstore_extension_->id())); 631 EXPECT_FALSE(prefs()->IsFromBookmark(webstore_extension_->id()));
632 632
633 EXPECT_TRUE(prefs()->IsFromBookmark(bookmark_extension_->id())); 633 EXPECT_TRUE(prefs()->IsFromBookmark(bookmark_extension_->id()));
634 EXPECT_FALSE(prefs()->IsFromWebStore(bookmark_extension_->id())); 634 EXPECT_FALSE(prefs()->IsFromWebStore(bookmark_extension_->id()));
635 635
636 EXPECT_TRUE(prefs()->WasInstalledByDefault(default_extension_->id())); 636 EXPECT_TRUE(prefs()->WasInstalledByDefault(default_extension_->id()));
637 } 637 }
638 638
639 private: 639 private:
640 scoped_refptr<Extension> webstore_extension_; 640 scoped_refptr<Extension> webstore_extension_;
641 scoped_refptr<Extension> bookmark_extension_; 641 scoped_refptr<Extension> bookmark_extension_;
642 scoped_refptr<Extension> default_extension_; 642 scoped_refptr<Extension> default_extension_;
643 }; 643 };
644 TEST_F(ExtensionPrefsFlags, ExtensionPrefsFlags) {} 644 TEST_F(ExtensionPrefsFlags, ExtensionPrefsFlags) {}
645 645
646 PrefsPrepopulatedTestBase::PrefsPrepopulatedTestBase() 646 PrefsPrepopulatedTestBase::PrefsPrepopulatedTestBase()
647 : ExtensionPrefsTest() { 647 : ExtensionPrefsTest() {
648 DictionaryValue simple_dict; 648 DictionaryValue simple_dict;
649 std::string error; 649 std::string error;
650 650
651 simple_dict.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); 651 simple_dict.SetString(manifest_keys::kVersion, "1.0.0.0");
652 simple_dict.SetString(extension_manifest_keys::kName, "unused"); 652 simple_dict.SetString(manifest_keys::kName, "unused");
653 653
654 extension1_ = Extension::Create( 654 extension1_ = Extension::Create(
655 prefs_.temp_dir().AppendASCII("ext1_"), 655 prefs_.temp_dir().AppendASCII("ext1_"),
656 Manifest::EXTERNAL_PREF, 656 Manifest::EXTERNAL_PREF,
657 simple_dict, 657 simple_dict,
658 Extension::NO_FLAGS, 658 Extension::NO_FLAGS,
659 &error); 659 &error);
660 extension2_ = Extension::Create( 660 extension2_ = Extension::Create(
661 prefs_.temp_dir().AppendASCII("ext2_"), 661 prefs_.temp_dir().AppendASCII("ext2_"),
662 Manifest::EXTERNAL_PREF, 662 Manifest::EXTERNAL_PREF,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 756
757 private: 757 private:
758 scoped_refptr<const Extension> extension_a_; 758 scoped_refptr<const Extension> extension_a_;
759 scoped_refptr<const Extension> extension_b_; 759 scoped_refptr<const Extension> extension_b_;
760 scoped_refptr<const Extension> extension_c_; 760 scoped_refptr<const Extension> extension_c_;
761 }; 761 };
762 TEST_F(ExtensionPrefsBlacklistedExtensions, 762 TEST_F(ExtensionPrefsBlacklistedExtensions,
763 ExtensionPrefsBlacklistedExtensions) {} 763 ExtensionPrefsBlacklistedExtensions) {}
764 764
765 } // namespace extensions 765 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698