OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 std::string id4_; | 571 std::string id4_; |
572 }; | 572 }; |
573 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} | 573 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} |
574 | 574 |
575 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { | 575 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { |
576 public: | 576 public: |
577 virtual void Initialize() { | 577 virtual void Initialize() { |
578 extension_ = prefs_.AddExtension("on_extension_installed"); | 578 extension_ = prefs_.AddExtension("on_extension_installed"); |
579 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 579 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
580 prefs()->OnExtensionInstalled( | 580 prefs()->OnExtensionInstalled( |
581 extension_.get(), Extension::DISABLED, false, 0); | 581 extension_.get(), Extension::DISABLED, false, -1); |
582 } | 582 } |
583 | 583 |
584 virtual void Verify() { | 584 virtual void Verify() { |
585 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); | 585 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); |
586 } | 586 } |
587 | 587 |
588 private: | 588 private: |
589 scoped_refptr<Extension> extension_; | 589 scoped_refptr<Extension> extension_; |
590 }; | 590 }; |
591 TEST_F(ExtensionPrefsOnExtensionInstalled, | 591 TEST_F(ExtensionPrefsOnExtensionInstalled, |
592 ExtensionPrefsOnExtensionInstalled) {} | 592 ExtensionPrefsOnExtensionInstalled) {} |
593 | 593 |
594 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { | 594 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { |
595 public: | 595 public: |
596 virtual void Initialize() { | 596 virtual void Initialize() { |
597 // No extensions yet. | 597 // No extensions yet. |
598 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex(0)); | 598 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex(0)); |
599 | 599 |
600 extension_ = prefs_.AddExtension("on_extension_installed"); | 600 extension_ = prefs_.AddApp("on_extension_installed"); |
601 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 601 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
602 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 602 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
603 false, 0); | 603 false, -1); |
604 } | 604 } |
605 | 605 |
606 virtual void Verify() { | 606 virtual void Verify() { |
607 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 607 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
608 // Extension should have been assigned a launch index > 0. | 608 // Extension should have been assigned a launch index > 0. |
609 EXPECT_GT(launch_index, 0); | 609 EXPECT_GT(launch_index, 0); |
610 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex(0)); | 610 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex(0)); |
611 // Set a new launch index of one higher and verify. | 611 // Set a new launch index of one higher and verify. |
612 prefs()->SetAppLaunchIndex(extension_->id(), | 612 prefs()->SetAppLaunchIndex(extension_->id(), |
613 prefs()->GetNextAppLaunchIndex(0)); | 613 prefs()->GetNextAppLaunchIndex(0)); |
614 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 614 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
615 EXPECT_EQ(launch_index + 1, new_launch_index); | 615 EXPECT_EQ(launch_index + 1, new_launch_index); |
616 | 616 |
617 // This extension doesn't exist, so it should return -1. | 617 // This extension doesn't exist, so it should return -1. |
618 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); | 618 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); |
619 | 619 |
620 // The second page doesn't have any apps so its next launch index should | 620 // The second page doesn't have any apps so its next launch index should |
621 // still be 0. | 621 // still be 0. |
622 EXPECT_EQ(prefs()->GetNextAppLaunchIndex(1), 0); | 622 EXPECT_EQ(prefs()->GetNextAppLaunchIndex(1), 0); |
623 } | 623 } |
624 | 624 |
625 private: | 625 private: |
626 scoped_refptr<Extension> extension_; | 626 scoped_refptr<Extension> extension_; |
627 }; | 627 }; |
628 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} | 628 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} |
629 | 629 |
630 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { | 630 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { |
631 public: | 631 public: |
632 virtual void Initialize() { | 632 virtual void Initialize() { |
633 extension_ = prefs_.AddExtension("page_index"); | 633 extension_ = prefs_.AddApp("page_index"); |
634 // Install to page 3 (index 2). | 634 // Install to page 3 (index 2). |
635 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 635 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
636 false, 2); | 636 false, 2); |
637 EXPECT_EQ(2, prefs()->GetPageIndex(extension_->id())); | 637 EXPECT_EQ(2, prefs()->GetPageIndex(extension_->id())); |
| 638 |
| 639 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_index_2"); |
| 640 // Install without any page preference. |
| 641 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 642 false, -1); |
| 643 EXPECT_EQ(0, prefs()->GetPageIndex(extension_->id())); |
638 } | 644 } |
639 | 645 |
640 virtual void Verify() { | 646 virtual void Verify() { |
641 // Set the page index. | 647 // Set the page index. |
642 prefs()->SetPageIndex(extension_->id(), 1); | 648 prefs()->SetPageIndex(extension_->id(), 1); |
643 // Verify the page index. | 649 // Verify the page index. |
644 EXPECT_EQ(1, prefs()->GetPageIndex(extension_->id())); | 650 EXPECT_EQ(1, prefs()->GetPageIndex(extension_->id())); |
645 | 651 |
646 // This extension doesn't exist, so it should return -1. | 652 // This extension doesn't exist, so it should return -1. |
647 EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); | 653 EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); |
648 } | 654 } |
649 | 655 |
650 private: | 656 private: |
651 scoped_refptr<Extension> extension_; | 657 scoped_refptr<Extension> extension_; |
652 }; | 658 }; |
653 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} | 659 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} |
654 | 660 |
| 661 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { |
| 662 public: |
| 663 virtual void Initialize() { |
| 664 extension_ = prefs_.AddExtension("not_an_app"); |
| 665 // Non-apps should not have any app launch index or page index. |
| 666 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 667 false, 0); |
| 668 } |
| 669 |
| 670 virtual void Verify() { |
| 671 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex(extension_->id())); |
| 672 EXPECT_EQ(-1, prefs()->GetPageIndex(extension_->id())); |
| 673 } |
| 674 |
| 675 private: |
| 676 scoped_refptr<Extension> extension_; |
| 677 }; |
| 678 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} |
| 679 |
655 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { | 680 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { |
656 public: | 681 public: |
657 virtual void Initialize() { | 682 virtual void Initialize() { |
658 extension_ = prefs_.AddExtension("on_extension_installed"); | 683 extension_ = prefs_.AddExtension("on_extension_installed"); |
659 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); | 684 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); |
660 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 685 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
661 false, 0); | 686 false, -1); |
662 } | 687 } |
663 | 688 |
664 virtual void Verify() { | 689 virtual void Verify() { |
665 // Set the flag and see if it persisted. | 690 // Set the flag and see if it persisted. |
666 prefs()->SetAppDraggedByUser(extension_->id()); | 691 prefs()->SetAppDraggedByUser(extension_->id()); |
667 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 692 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
668 | 693 |
669 // Make sure it doesn't change on consecutive calls. | 694 // Make sure it doesn't change on consecutive calls. |
670 prefs()->SetAppDraggedByUser(extension_->id()); | 695 prefs()->SetAppDraggedByUser(extension_->id()); |
671 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 696 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 | 826 |
802 // Flags indicating whether each of the extensions has been installed, yet. | 827 // Flags indicating whether each of the extensions has been installed, yet. |
803 bool installed[3]; | 828 bool installed[3]; |
804 | 829 |
805 private: | 830 private: |
806 void EnsureExtensionInstalled(Extension *ext) { | 831 void EnsureExtensionInstalled(Extension *ext) { |
807 // Install extension the first time a preference is set for it. | 832 // Install extension the first time a preference is set for it. |
808 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 833 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
809 for (int i = 0; i < 3; ++i) { | 834 for (int i = 0; i < 3; ++i) { |
810 if (ext == extensions[i] && !installed[i]) { | 835 if (ext == extensions[i] && !installed[i]) { |
811 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false, 0); | 836 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false, -1); |
812 installed[i] = true; | 837 installed[i] = true; |
813 break; | 838 break; |
814 } | 839 } |
815 } | 840 } |
816 } | 841 } |
817 | 842 |
818 void EnsureExtensionUninstalled(const std::string& extension_id) { | 843 void EnsureExtensionUninstalled(const std::string& extension_id) { |
819 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 844 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
820 for (int i = 0; i < 3; ++i) { | 845 for (int i = 0; i < 3; ++i) { |
821 if (extensions[i]->id() == extension_id) { | 846 if (extensions[i]->id() == extension_id) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 testing::Mock::VerifyAndClearExpectations(v1i); | 1094 testing::Mock::VerifyAndClearExpectations(v1i); |
1070 testing::Mock::VerifyAndClearExpectations(v2); | 1095 testing::Mock::VerifyAndClearExpectations(v2); |
1071 testing::Mock::VerifyAndClearExpectations(v2i); | 1096 testing::Mock::VerifyAndClearExpectations(v2i); |
1072 } | 1097 } |
1073 | 1098 |
1074 virtual void Verify() { | 1099 virtual void Verify() { |
1075 } | 1100 } |
1076 }; | 1101 }; |
1077 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 1102 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
1078 ExtensionPrefsSetExtensionControlledPref) {} | 1103 ExtensionPrefsSetExtensionControlledPref) {} |
OLD | NEW |