OLD | NEW |
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/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/prefs/public/pref_change_registrar.h" | 9 #include "base/prefs/public/pref_change_registrar.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 scoped_refptr<PermissionSet> active( | 436 scoped_refptr<PermissionSet> active( |
437 prefs()->GetActivePermissions(extension_id_)); | 437 prefs()->GetActivePermissions(extension_id_)); |
438 EXPECT_TRUE(active->IsEmpty()); | 438 EXPECT_TRUE(active->IsEmpty()); |
439 | 439 |
440 // Set the active permissions. | 440 // Set the active permissions. |
441 prefs()->SetActivePermissions(extension_id_, active_perms_.get()); | 441 prefs()->SetActivePermissions(extension_id_, active_perms_.get()); |
442 active = prefs()->GetActivePermissions(extension_id_); | 442 active = prefs()->GetActivePermissions(extension_id_); |
443 EXPECT_EQ(active_perms_->apis(), active->apis()); | 443 EXPECT_EQ(active_perms_->apis(), active->apis()); |
444 EXPECT_EQ(active_perms_->explicit_hosts(), active->explicit_hosts()); | 444 EXPECT_EQ(active_perms_->explicit_hosts(), active->explicit_hosts()); |
445 EXPECT_EQ(active_perms_->scriptable_hosts(), active->scriptable_hosts()); | 445 EXPECT_EQ(active_perms_->scriptable_hosts(), active->scriptable_hosts()); |
446 EXPECT_EQ(*active_perms_, *active); | 446 EXPECT_EQ(*active_perms_.get(), *active.get()); |
447 } | 447 } |
448 | 448 |
449 virtual void Verify() { | 449 virtual void Verify() { |
450 scoped_refptr<PermissionSet> permissions( | 450 scoped_refptr<PermissionSet> permissions( |
451 prefs()->GetActivePermissions(extension_id_)); | 451 prefs()->GetActivePermissions(extension_id_)); |
452 EXPECT_EQ(*active_perms_, *permissions); | 452 EXPECT_EQ(*active_perms_.get(), *permissions.get()); |
453 } | 453 } |
454 | 454 |
455 private: | 455 private: |
456 std::string extension_id_; | 456 std::string extension_id_; |
457 scoped_refptr<PermissionSet> active_perms_; | 457 scoped_refptr<PermissionSet> active_perms_; |
458 }; | 458 }; |
459 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} | 459 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} |
460 | 460 |
461 // Tests the GetVersionString function. | 461 // Tests the GetVersionString function. |
462 class ExtensionPrefsVersionString : public ExtensionPrefsTest { | 462 class ExtensionPrefsVersionString : public ExtensionPrefsTest { |
(...skipping 22 matching lines...) Expand all Loading... |
485 | 485 |
486 // Install 5 extensions. | 486 // Install 5 extensions. |
487 for (int i = 0; i < 5; i++) { | 487 for (int i = 0; i < 5; i++) { |
488 std::string name = "test" + base::IntToString(i); | 488 std::string name = "test" + base::IntToString(i); |
489 extensions_.push_back(prefs_.AddExtension(name)); | 489 extensions_.push_back(prefs_.AddExtension(name)); |
490 } | 490 } |
491 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); | 491 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); |
492 | 492 |
493 ExtensionList::const_iterator iter; | 493 ExtensionList::const_iterator iter; |
494 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { | 494 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { |
495 EXPECT_TRUE(prefs()->UserMayLoad(*iter, NULL)); | 495 EXPECT_TRUE(prefs()->UserMayLoad(*iter.get(), NULL)); |
496 } | 496 } |
497 // Blacklist one installed and one not-installed extension id. | 497 // Blacklist one installed and one not-installed extension id. |
498 std::set<std::string> blacklisted_ids; | 498 std::set<std::string> blacklisted_ids; |
499 blacklisted_ids.insert(extensions_[0]->id()); | 499 blacklisted_ids.insert(extensions_[0]->id()); |
500 blacklisted_ids.insert(not_installed_id_); | 500 blacklisted_ids.insert(not_installed_id_); |
501 prefs()->UpdateBlacklist(blacklisted_ids); | 501 prefs()->UpdateBlacklist(blacklisted_ids); |
502 } | 502 } |
503 | 503 |
504 virtual void Verify() { | 504 virtual void Verify() { |
505 // Make sure the id we expect to be blacklisted is. | 505 // Make sure the id we expect to be blacklisted is. |
506 EXPECT_FALSE(prefs()->UserMayLoad(extensions_[0], NULL)); | 506 EXPECT_FALSE(prefs()->UserMayLoad(extensions_[0].get(), NULL)); |
507 | 507 |
508 // Make sure the other id's are not blacklisted. | 508 // Make sure the other id's are not blacklisted. |
509 ExtensionList::const_iterator iter; | 509 ExtensionList::const_iterator iter; |
510 for (iter = extensions_.begin() + 1; iter != extensions_.end(); ++iter) | 510 for (iter = extensions_.begin() + 1; iter != extensions_.end(); ++iter) |
511 EXPECT_TRUE(prefs()->UserMayLoad(*iter, NULL)); | 511 EXPECT_TRUE(prefs()->UserMayLoad(*iter.get(), NULL)); |
512 | 512 |
513 // Make sure GetInstalledExtensionsInfo returns only the non-blacklisted | 513 // Make sure GetInstalledExtensionsInfo returns only the non-blacklisted |
514 // extensions data. | 514 // extensions data. |
515 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( | 515 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
516 prefs()->GetInstalledExtensionsInfo()); | 516 prefs()->GetInstalledExtensionsInfo()); |
517 EXPECT_EQ(4u, info->size()); | 517 EXPECT_EQ(4u, info->size()); |
518 ExtensionPrefs::ExtensionsInfo::iterator info_iter; | 518 ExtensionPrefs::ExtensionsInfo::iterator info_iter; |
519 for (info_iter = info->begin(); info_iter != info->end(); ++info_iter) { | 519 for (info_iter = info->begin(); info_iter != info->end(); ++info_iter) { |
520 ExtensionInfo* extension_info = info_iter->get(); | 520 ExtensionInfo* extension_info = info_iter->get(); |
521 EXPECT_NE(extensions_[0]->id(), extension_info->extension_id); | 521 EXPECT_NE(extensions_[0]->id(), extension_info->extension_id); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 public: | 611 public: |
612 virtual void Initialize() { | 612 virtual void Initialize() { |
613 // Install 5 extensions. | 613 // Install 5 extensions. |
614 for (int i = 0; i < 5; i++) { | 614 for (int i = 0; i < 5; i++) { |
615 std::string name = "test" + base::IntToString(i); | 615 std::string name = "test" + base::IntToString(i); |
616 extensions_.push_back(prefs_.AddExtension(name)); | 616 extensions_.push_back(prefs_.AddExtension(name)); |
617 } | 617 } |
618 | 618 |
619 ExtensionList::const_iterator iter; | 619 ExtensionList::const_iterator iter; |
620 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) | 620 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) |
621 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter)); | 621 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter.get())); |
622 | 622 |
623 prefs()->SetBrowserActionVisibility(extensions_[0], false); | 623 prefs()->SetBrowserActionVisibility(extensions_[0].get(), false); |
624 prefs()->SetBrowserActionVisibility(extensions_[1], true); | 624 prefs()->SetBrowserActionVisibility(extensions_[1].get(), true); |
625 } | 625 } |
626 | 626 |
627 virtual void Verify() { | 627 virtual void Verify() { |
628 // Make sure the one we hid is hidden. | 628 // Make sure the one we hid is hidden. |
629 EXPECT_FALSE(prefs()->GetBrowserActionVisibility(extensions_[0])); | 629 EXPECT_FALSE(prefs()->GetBrowserActionVisibility(extensions_[0].get())); |
630 | 630 |
631 // Make sure the other id's are not hidden. | 631 // Make sure the other id's are not hidden. |
632 ExtensionList::const_iterator iter = extensions_.begin() + 1; | 632 ExtensionList::const_iterator iter = extensions_.begin() + 1; |
633 for (; iter != extensions_.end(); ++iter) { | 633 for (; iter != extensions_.end(); ++iter) { |
634 SCOPED_TRACE(base::StringPrintf("Loop %d ", | 634 SCOPED_TRACE(base::StringPrintf("Loop %d ", |
635 static_cast<int>(iter - extensions_.begin()))); | 635 static_cast<int>(iter - extensions_.begin()))); |
636 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter)); | 636 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter.get())); |
637 } | 637 } |
638 } | 638 } |
639 | 639 |
640 private: | 640 private: |
641 ExtensionList extensions_; | 641 ExtensionList extensions_; |
642 }; | 642 }; |
643 TEST_F(ExtensionPrefsHidingBrowserActions, ForceHide) {} | 643 TEST_F(ExtensionPrefsHidingBrowserActions, ForceHide) {} |
644 | 644 |
645 // Tests the idle install information functions. | 645 // Tests the idle install information functions. |
646 class ExtensionPrefsIdleInstallInfo : public ExtensionPrefsTest { | 646 class ExtensionPrefsIdleInstallInfo : public ExtensionPrefsTest { |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 EXPECT_EQ(string16(), error16); | 1282 EXPECT_EQ(string16(), error16); |
1283 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); | 1283 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); |
1284 EXPECT_EQ(string16(), error16); | 1284 EXPECT_EQ(string16(), error16); |
1285 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); | 1285 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); |
1286 EXPECT_EQ(string16(), error16); | 1286 EXPECT_EQ(string16(), error16); |
1287 } | 1287 } |
1288 }; | 1288 }; |
1289 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} | 1289 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} |
1290 | 1290 |
1291 } // namespace extensions | 1291 } // namespace extensions |
OLD | NEW |