| 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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 std::string id4_; | 570 std::string id4_; |
| 571 }; | 571 }; |
| 572 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} | 572 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} |
| 573 | 573 |
| 574 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { | 574 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { |
| 575 public: | 575 public: |
| 576 virtual void Initialize() { | 576 virtual void Initialize() { |
| 577 extension_ = prefs_.AddExtension("on_extension_installed"); | 577 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 578 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 578 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 579 prefs()->OnExtensionInstalled( | 579 prefs()->OnExtensionInstalled( |
| 580 extension_.get(), Extension::DISABLED, false, -1); | 580 extension_.get(), Extension::DISABLED, false, |
| 581 extension_misc::kUnsetIndex); |
| 581 } | 582 } |
| 582 | 583 |
| 583 virtual void Verify() { | 584 virtual void Verify() { |
| 584 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); | 585 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); |
| 585 } | 586 } |
| 586 | 587 |
| 587 private: | 588 private: |
| 588 scoped_refptr<Extension> extension_; | 589 scoped_refptr<Extension> extension_; |
| 589 }; | 590 }; |
| 590 TEST_F(ExtensionPrefsOnExtensionInstalled, | 591 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 591 ExtensionPrefsOnExtensionInstalled) {} | 592 ExtensionPrefsOnExtensionInstalled) {} |
| 592 | 593 |
| 593 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { | 594 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { |
| 594 public: | 595 public: |
| 595 virtual void Initialize() { | 596 virtual void Initialize() { |
| 596 // No extensions yet. | 597 // No extensions yet. |
| 597 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex(0)); | 598 EXPECT_EQ("0", prefs()->GetNextAppLaunchIndex("0")); |
| 598 | 599 |
| 599 extension_ = prefs_.AddApp("on_extension_installed"); | 600 extension_ = prefs_.AddApp("on_extension_installed"); |
| 600 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 601 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 601 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 602 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 602 false, -1); | 603 false, extension_misc::kUnsetIndex); |
| 603 } | 604 } |
| 604 | 605 |
| 605 virtual void Verify() { | 606 virtual void Verify() { |
| 606 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 607 std::string launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
| 608 int launch_index_int; |
| 609 base::StringToInt(launch_index, &launch_index_int); |
| 610 |
| 607 // Extension should have been assigned a launch index > 0. | 611 // Extension should have been assigned a launch index > 0. |
| 608 EXPECT_GT(launch_index, 0); | 612 EXPECT_GT(launch_index, "0"); |
| 609 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex(0)); | 613 EXPECT_EQ(base::IntToString(launch_index_int + 1), |
| 614 prefs()->GetNextAppLaunchIndex("0")); |
| 610 // Set a new launch index of one higher and verify. | 615 // Set a new launch index of one higher and verify. |
| 611 prefs()->SetAppLaunchIndex(extension_->id(), | 616 prefs()->SetAppLaunchIndex(extension_->id(), |
| 612 prefs()->GetNextAppLaunchIndex(0)); | 617 prefs()->GetNextAppLaunchIndex("0")); |
| 613 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 618 std::string new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
| 614 EXPECT_EQ(launch_index + 1, new_launch_index); | 619 EXPECT_EQ(base::IntToString(launch_index_int + 1), new_launch_index); |
| 615 | 620 |
| 616 // This extension doesn't exist, so it should return -1. | 621 // This extension doesn't exist, so it should return kUnsetIndex |
| 617 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); | 622 EXPECT_EQ(extension_misc::kUnsetIndex, prefs()->GetAppLaunchIndex("foo")); |
| 618 | 623 |
| 619 // The second page doesn't have any apps so its next launch index should | 624 // The second page doesn't have any apps so its next launch index should |
| 620 // still be 0. | 625 // still be 0. |
| 621 EXPECT_EQ(prefs()->GetNextAppLaunchIndex(1), 0); | 626 EXPECT_EQ(prefs()->GetNextAppLaunchIndex("1"), "0"); |
| 622 } | 627 } |
| 623 | 628 |
| 624 private: | 629 private: |
| 625 scoped_refptr<Extension> extension_; | 630 scoped_refptr<Extension> extension_; |
| 626 }; | 631 }; |
| 627 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} | 632 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} |
| 628 | 633 |
| 629 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { | 634 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { |
| 630 public: | 635 public: |
| 631 virtual void Initialize() { | 636 virtual void Initialize() { |
| 632 extension_ = prefs_.AddApp("page_index"); | 637 extension_ = prefs_.AddApp("page_index"); |
| 633 // Install to page 3 (index 2). | 638 // Install to page 3 (index 2). |
| 634 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 639 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 635 false, 2); | 640 false, "2"); |
| 636 EXPECT_EQ(2, prefs()->GetPageIndex(extension_->id())); | 641 EXPECT_EQ("2", prefs()->GetPageIndex(extension_->id())); |
| 637 | 642 |
| 638 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_index_2"); | 643 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_index_2"); |
| 639 // Install without any page preference. | 644 // Install without any page preference. |
| 640 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 645 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 641 false, -1); | 646 false, extension_misc::kUnsetIndex); |
| 642 EXPECT_EQ(0, prefs()->GetPageIndex(extension_->id())); | 647 EXPECT_EQ("0", prefs()->GetPageIndex(extension_->id())); |
| 643 } | 648 } |
| 644 | 649 |
| 645 virtual void Verify() { | 650 virtual void Verify() { |
| 646 // Set the page index. | 651 // Set the page index. |
| 647 prefs()->SetPageIndex(extension_->id(), 1); | 652 prefs()->SetPageIndex(extension_->id(), "1"); |
| 648 // Verify the page index. | 653 // Verify the page index. |
| 649 EXPECT_EQ(1, prefs()->GetPageIndex(extension_->id())); | 654 EXPECT_EQ("1", prefs()->GetPageIndex(extension_->id())); |
| 650 | 655 |
| 651 // This extension doesn't exist, so it should return -1. | 656 // This extension doesn't exist, so it should return kUnsetIndex. |
| 652 EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); | 657 EXPECT_EQ(extension_misc::kUnsetIndex, prefs()->GetPageIndex("foo")); |
| 653 } | 658 } |
| 654 | 659 |
| 655 private: | 660 private: |
| 656 scoped_refptr<Extension> extension_; | 661 scoped_refptr<Extension> extension_; |
| 657 }; | 662 }; |
| 658 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} | 663 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} |
| 659 | 664 |
| 660 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { | 665 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { |
| 661 public: | 666 public: |
| 662 virtual void Initialize() { | 667 virtual void Initialize() { |
| 663 extension_ = prefs_.AddExtension("not_an_app"); | 668 extension_ = prefs_.AddExtension("not_an_app"); |
| 664 // Non-apps should not have any app launch index or page index. | 669 // Non-apps should not have any app launch index or page index. |
| 665 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 670 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 666 false, 0); | 671 false, "0"); |
| 667 } | 672 } |
| 668 | 673 |
| 669 virtual void Verify() { | 674 virtual void Verify() { |
| 670 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex(extension_->id())); | 675 EXPECT_EQ(extension_misc::kUnsetIndex, |
| 671 EXPECT_EQ(-1, prefs()->GetPageIndex(extension_->id())); | 676 prefs()->GetAppLaunchIndex(extension_->id())); |
| 677 EXPECT_EQ(extension_misc::kUnsetIndex, |
| 678 prefs()->GetPageIndex(extension_->id())); |
| 672 } | 679 } |
| 673 | 680 |
| 674 private: | 681 private: |
| 675 scoped_refptr<Extension> extension_; | 682 scoped_refptr<Extension> extension_; |
| 676 }; | 683 }; |
| 677 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} | 684 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} |
| 678 | 685 |
| 679 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { | 686 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { |
| 680 public: | 687 public: |
| 681 virtual void Initialize() { | 688 virtual void Initialize() { |
| 682 extension_ = prefs_.AddExtension("on_extension_installed"); | 689 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 683 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); | 690 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 684 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 691 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 685 false, -1); | 692 false, extension_misc::kUnsetIndex); |
| 686 } | 693 } |
| 687 | 694 |
| 688 virtual void Verify() { | 695 virtual void Verify() { |
| 689 // Set the flag and see if it persisted. | 696 // Set the flag and see if it persisted. |
| 690 prefs()->SetAppDraggedByUser(extension_->id()); | 697 prefs()->SetAppDraggedByUser(extension_->id()); |
| 691 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 698 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 692 | 699 |
| 693 // Make sure it doesn't change on consecutive calls. | 700 // Make sure it doesn't change on consecutive calls. |
| 694 prefs()->SetAppDraggedByUser(extension_->id()); | 701 prefs()->SetAppDraggedByUser(extension_->id()); |
| 695 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 702 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 832 |
| 826 // Flags indicating whether each of the extensions has been installed, yet. | 833 // Flags indicating whether each of the extensions has been installed, yet. |
| 827 bool installed[3]; | 834 bool installed[3]; |
| 828 | 835 |
| 829 private: | 836 private: |
| 830 void EnsureExtensionInstalled(Extension *ext) { | 837 void EnsureExtensionInstalled(Extension *ext) { |
| 831 // Install extension the first time a preference is set for it. | 838 // Install extension the first time a preference is set for it. |
| 832 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 839 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
| 833 for (int i = 0; i < 3; ++i) { | 840 for (int i = 0; i < 3; ++i) { |
| 834 if (ext == extensions[i] && !installed[i]) { | 841 if (ext == extensions[i] && !installed[i]) { |
| 835 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false, -1); | 842 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, |
| 843 false, extension_misc::kUnsetIndex); |
| 836 installed[i] = true; | 844 installed[i] = true; |
| 837 break; | 845 break; |
| 838 } | 846 } |
| 839 } | 847 } |
| 840 } | 848 } |
| 841 | 849 |
| 842 void EnsureExtensionUninstalled(const std::string& extension_id) { | 850 void EnsureExtensionUninstalled(const std::string& extension_id) { |
| 843 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 851 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
| 844 for (int i = 0; i < 3; ++i) { | 852 for (int i = 0; i < 3; ++i) { |
| 845 if (extensions[i]->id() == extension_id) { | 853 if (extensions[i]->id() == extension_id) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 ++iteration_; | 1140 ++iteration_; |
| 1133 } else { | 1141 } else { |
| 1134 EXPECT_EQ(kDefaultPref1, actual); | 1142 EXPECT_EQ(kDefaultPref1, actual); |
| 1135 } | 1143 } |
| 1136 } | 1144 } |
| 1137 | 1145 |
| 1138 private: | 1146 private: |
| 1139 int iteration_; | 1147 int iteration_; |
| 1140 }; | 1148 }; |
| 1141 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} | 1149 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} |
| OLD | NEW |