| 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" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/test_extension_prefs.h" | 12 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 13 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 13 #include "chrome/browser/prefs/pref_change_registrar.h" | 14 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
| 17 #include "chrome/common/extensions/extension_permission_set.h" | 18 #include "chrome/common/extensions/extension_permission_set.h" |
| 19 #include "chrome/common/string_ordinal.h" |
| 18 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 20 #include "content/test/notification_observer_mock.h" | 22 #include "content/test/notification_observer_mock.h" |
| 21 #include "content/test/test_browser_thread.h" | 23 #include "content/test/test_browser_thread.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 using base::Time; | 26 using base::Time; |
| 25 using base::TimeDelta; | 27 using base::TimeDelta; |
| 26 using content::BrowserThread; | 28 using content::BrowserThread; |
| 27 | 29 |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 std::string id4_; | 649 std::string id4_; |
| 648 }; | 650 }; |
| 649 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} | 651 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} |
| 650 | 652 |
| 651 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { | 653 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { |
| 652 public: | 654 public: |
| 653 virtual void Initialize() { | 655 virtual void Initialize() { |
| 654 extension_ = prefs_.AddExtension("on_extension_installed"); | 656 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 655 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 657 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 656 prefs()->OnExtensionInstalled( | 658 prefs()->OnExtensionInstalled( |
| 657 extension_.get(), Extension::DISABLED, false, -1); | 659 extension_.get(), Extension::DISABLED, false, |
| 660 StringOrdinal()); |
| 658 } | 661 } |
| 659 | 662 |
| 660 virtual void Verify() { | 663 virtual void Verify() { |
| 661 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); | 664 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); |
| 662 } | 665 } |
| 663 | 666 |
| 664 private: | 667 private: |
| 665 scoped_refptr<Extension> extension_; | 668 scoped_refptr<Extension> extension_; |
| 666 }; | 669 }; |
| 667 TEST_F(ExtensionPrefsOnExtensionInstalled, | 670 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 668 ExtensionPrefsOnExtensionInstalled) {} | 671 ExtensionPrefsOnExtensionInstalled) {} |
| 669 | 672 |
| 670 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { | 673 class ExtensionPrefsAppLaunchOrdinal : public ExtensionPrefsTest { |
| 671 public: | 674 public: |
| 672 virtual void Initialize() { | 675 virtual void Initialize() { |
| 673 // No extensions yet. | 676 // No extensions yet. |
| 674 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex(0)); | 677 StringOrdinal page = StringOrdinal::CreateInitialOrdinal(); |
| 678 EXPECT_TRUE(StringOrdinal::CreateInitialOrdinal().Equal( |
| 679 prefs()->CreateNextAppLaunchOrdinal(page))); |
| 675 | 680 |
| 676 extension_ = prefs_.AddApp("on_extension_installed"); | 681 extension_ = prefs_.AddApp("on_extension_installed"); |
| 677 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 682 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 678 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 683 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 679 false, -1); | 684 false, StringOrdinal()); |
| 680 } | 685 } |
| 681 | 686 |
| 682 virtual void Verify() { | 687 virtual void Verify() { |
| 683 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 688 StringOrdinal launch_ordinal = |
| 684 // Extension should have been assigned a launch index > 0. | 689 prefs()->GetAppLaunchOrdinal(extension_->id()); |
| 685 EXPECT_GT(launch_index, 0); | 690 StringOrdinal page_ordinal = StringOrdinal::CreateInitialOrdinal(); |
| 686 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex(0)); | |
| 687 // Set a new launch index of one higher and verify. | |
| 688 prefs()->SetAppLaunchIndex(extension_->id(), | |
| 689 prefs()->GetNextAppLaunchIndex(0)); | |
| 690 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | |
| 691 EXPECT_EQ(launch_index + 1, new_launch_index); | |
| 692 | 691 |
| 693 // This extension doesn't exist, so it should return -1. | 692 // Extension should have been assigned a valid StringOrdinal. |
| 694 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); | 693 EXPECT_TRUE(launch_ordinal.IsValid()); |
| 694 EXPECT_TRUE(launch_ordinal.LessThan( |
| 695 prefs()->CreateNextAppLaunchOrdinal(page_ordinal))); |
| 696 // Set a new launch ordinal of and verify it comes after. |
| 697 prefs()->SetAppLaunchOrdinal( |
| 698 extension_->id(), |
| 699 prefs()->CreateNextAppLaunchOrdinal(page_ordinal)); |
| 700 StringOrdinal new_launch_ordinal = |
| 701 prefs()->GetAppLaunchOrdinal(extension_->id()); |
| 702 EXPECT_TRUE(launch_ordinal.LessThan(new_launch_ordinal)); |
| 695 | 703 |
| 696 // The second page doesn't have any apps so its next launch index should | 704 // This extension doesn't exist, so it should return an invalid |
| 697 // still be 0. | 705 // StringOrdinal. |
| 698 EXPECT_EQ(prefs()->GetNextAppLaunchIndex(1), 0); | 706 StringOrdinal invalid_app_launch_ordinal = |
| 707 prefs()->GetAppLaunchOrdinal("foo"); |
| 708 EXPECT_FALSE(invalid_app_launch_ordinal.IsValid()); |
| 709 EXPECT_EQ(-1, prefs()->PageStringOrdinalAsInteger( |
| 710 invalid_app_launch_ordinal)); |
| 711 |
| 712 // The second page doesn't have any apps so its next launch ordinal should |
| 713 // be the first launch ordinal. |
| 714 StringOrdinal next_page = page_ordinal.CreateAfter(); |
| 715 StringOrdinal next_page_app_launch_ordinal = |
| 716 prefs()->CreateNextAppLaunchOrdinal(next_page); |
| 717 EXPECT_TRUE(next_page_app_launch_ordinal.Equal( |
| 718 prefs()->CreateFirstAppLaunchOrdinal(next_page))); |
| 699 } | 719 } |
| 700 | 720 |
| 701 private: | 721 private: |
| 702 scoped_refptr<Extension> extension_; | 722 scoped_refptr<Extension> extension_; |
| 703 }; | 723 }; |
| 704 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} | 724 TEST_F(ExtensionPrefsAppLaunchOrdinal, ExtensionPrefsAppLaunchOrdinal) {} |
| 705 | 725 |
| 706 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { | 726 class ExtensionPrefsPageOrdinal : public ExtensionPrefsTest { |
| 707 public: | 727 public: |
| 708 virtual void Initialize() { | 728 virtual void Initialize() { |
| 709 extension_ = prefs_.AddApp("page_index"); | 729 extension_ = prefs_.AddApp("page_ordinal"); |
| 710 // Install to page 3 (index 2). | 730 // Install with a page preference. |
| 731 StringOrdinal page = StringOrdinal::CreateInitialOrdinal(); |
| 711 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 732 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 712 false, 2); | 733 false, page); |
| 713 EXPECT_EQ(2, prefs()->GetPageIndex(extension_->id())); | 734 EXPECT_TRUE(page.Equal(prefs()->GetPageOrdinal(extension_->id()))); |
| 735 EXPECT_EQ(0, prefs()->PageStringOrdinalAsInteger(page)); |
| 714 | 736 |
| 715 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_index_2"); | 737 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_ordinal_2"); |
| 716 // Install without any page preference. | 738 // Install without any page preference. |
| 717 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 739 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 718 false, -1); | 740 false, StringOrdinal()); |
| 719 EXPECT_EQ(0, prefs()->GetPageIndex(extension_->id())); | 741 EXPECT_TRUE(prefs()->GetPageOrdinal(extension_->id()).IsValid()); |
| 720 } | 742 } |
| 721 | 743 |
| 722 virtual void Verify() { | 744 virtual void Verify() { |
| 723 // Set the page index. | 745 StringOrdinal old_page = prefs()->GetPageOrdinal(extension_->id()); |
| 724 prefs()->SetPageIndex(extension_->id(), 1); | 746 StringOrdinal new_page = old_page.CreateAfter(); |
| 725 // Verify the page index. | |
| 726 EXPECT_EQ(1, prefs()->GetPageIndex(extension_->id())); | |
| 727 | 747 |
| 728 // This extension doesn't exist, so it should return -1. | 748 // Set the page ordinal. |
| 729 EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); | 749 prefs()->SetPageOrdinal(extension_->id(), new_page); |
| 750 // Verify the page ordinal. |
| 751 EXPECT_TRUE(new_page.Equal(prefs()->GetPageOrdinal(extension_->id()))); |
| 752 EXPECT_EQ(1, prefs()->PageStringOrdinalAsInteger(new_page)); |
| 753 |
| 754 // This extension doesn't exist, so it should return an invalid |
| 755 // StringOrdinal. |
| 756 EXPECT_FALSE(prefs()->GetPageOrdinal("foo").IsValid()); |
| 730 } | 757 } |
| 731 | 758 |
| 732 private: | 759 private: |
| 733 scoped_refptr<Extension> extension_; | 760 scoped_refptr<Extension> extension_; |
| 734 }; | 761 }; |
| 735 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} | 762 TEST_F(ExtensionPrefsPageOrdinal, ExtensionPrefsPageOrdinal) {} |
| 736 | 763 |
| 737 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { | 764 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { |
| 738 public: | 765 public: |
| 739 virtual void Initialize() { | 766 virtual void Initialize() { |
| 740 extension_ = prefs_.AddExtension("not_an_app"); | 767 extension_ = prefs_.AddExtension("not_an_app"); |
| 741 // Non-apps should not have any app launch index or page index. | 768 // Non-apps should not have any app launch ordinal or page ordinal. |
| 742 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 769 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 743 false, 0); | 770 false, StringOrdinal()); |
| 744 } | 771 } |
| 745 | 772 |
| 746 virtual void Verify() { | 773 virtual void Verify() { |
| 747 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex(extension_->id())); | 774 EXPECT_FALSE(prefs()->GetAppLaunchOrdinal(extension_->id()).IsValid()); |
| 748 EXPECT_EQ(-1, prefs()->GetPageIndex(extension_->id())); | 775 EXPECT_FALSE(prefs()->GetPageOrdinal(extension_->id()).IsValid()); |
| 749 } | 776 } |
| 750 | 777 |
| 751 private: | 778 private: |
| 752 scoped_refptr<Extension> extension_; | 779 scoped_refptr<Extension> extension_; |
| 753 }; | 780 }; |
| 754 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} | 781 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} |
| 755 | 782 |
| 756 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { | 783 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { |
| 757 public: | 784 public: |
| 758 virtual void Initialize() { | 785 virtual void Initialize() { |
| 759 extension_ = prefs_.AddExtension("on_extension_installed"); | 786 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 760 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); | 787 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 761 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 788 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 762 false, -1); | 789 false, StringOrdinal()); |
| 763 } | 790 } |
| 764 | 791 |
| 765 virtual void Verify() { | 792 virtual void Verify() { |
| 766 // Set the flag and see if it persisted. | 793 // Set the flag and see if it persisted. |
| 767 prefs()->SetAppDraggedByUser(extension_->id()); | 794 prefs()->SetAppDraggedByUser(extension_->id()); |
| 768 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 795 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 769 | 796 |
| 770 // Make sure it doesn't change on consecutive calls. | 797 // Make sure it doesn't change on consecutive calls. |
| 771 prefs()->SetAppDraggedByUser(extension_->id()); | 798 prefs()->SetAppDraggedByUser(extension_->id()); |
| 772 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 799 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 929 |
| 903 // Flags indicating whether each of the extensions has been installed, yet. | 930 // Flags indicating whether each of the extensions has been installed, yet. |
| 904 bool installed[3]; | 931 bool installed[3]; |
| 905 | 932 |
| 906 private: | 933 private: |
| 907 void EnsureExtensionInstalled(Extension *ext) { | 934 void EnsureExtensionInstalled(Extension *ext) { |
| 908 // Install extension the first time a preference is set for it. | 935 // Install extension the first time a preference is set for it. |
| 909 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 936 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
| 910 for (int i = 0; i < 3; ++i) { | 937 for (int i = 0; i < 3; ++i) { |
| 911 if (ext == extensions[i] && !installed[i]) { | 938 if (ext == extensions[i] && !installed[i]) { |
| 912 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false, -1); | 939 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, |
| 940 false, StringOrdinal()); |
| 913 installed[i] = true; | 941 installed[i] = true; |
| 914 break; | 942 break; |
| 915 } | 943 } |
| 916 } | 944 } |
| 917 } | 945 } |
| 918 | 946 |
| 919 void EnsureExtensionUninstalled(const std::string& extension_id) { | 947 void EnsureExtensionUninstalled(const std::string& extension_id) { |
| 920 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 948 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
| 921 for (int i = 0; i < 3; ++i) { | 949 for (int i = 0; i < 3; ++i) { |
| 922 if (extensions[i]->id() == extension_id) { | 950 if (extensions[i]->id() == extension_id) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 ++iteration_; | 1237 ++iteration_; |
| 1210 } else { | 1238 } else { |
| 1211 EXPECT_EQ(kDefaultPref1, actual); | 1239 EXPECT_EQ(kDefaultPref1, actual); |
| 1212 } | 1240 } |
| 1213 } | 1241 } |
| 1214 | 1242 |
| 1215 private: | 1243 private: |
| 1216 int iteration_; | 1244 int iteration_; |
| 1217 }; | 1245 }; |
| 1218 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} | 1246 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} |
| 1247 |
| 1248 // Tests the application index to ordinal migration code. This should be removed |
| 1249 // when the migrate code is taken out. |
| 1250 class ExtensionPrefsMigrateAppIndex : public ExtensionPrefsPreferencesBase { |
| 1251 public: |
| 1252 ExtensionPrefsMigrateAppIndex() {} |
| 1253 virtual ~ExtensionPrefsMigrateAppIndex() {} |
| 1254 virtual void Initialize() { |
| 1255 // A preference determining the order of which the apps appear on the NTP. |
| 1256 const char kPrefAppLaunchIndexDeprecated[] = "app_launcher_index"; |
| 1257 // A preference determining the page on which an app appears in the NTP. |
| 1258 const char kPrefPageIndexDeprecated[] = "page_index"; |
| 1259 |
| 1260 // Setup the deprecated preferences. |
| 1261 prefs()->UpdateExtensionPref(ext1_->id(), |
| 1262 kPrefAppLaunchIndexDeprecated, |
| 1263 Value::CreateIntegerValue(0)); |
| 1264 prefs()->UpdateExtensionPref(ext1_->id(), |
| 1265 kPrefPageIndexDeprecated, |
| 1266 Value::CreateIntegerValue(0)); |
| 1267 |
| 1268 prefs()->UpdateExtensionPref(ext2_->id(), |
| 1269 kPrefAppLaunchIndexDeprecated, |
| 1270 Value::CreateIntegerValue(1)); |
| 1271 prefs()->UpdateExtensionPref(ext2_->id(), |
| 1272 kPrefPageIndexDeprecated, |
| 1273 Value::CreateIntegerValue(0)); |
| 1274 |
| 1275 prefs()->UpdateExtensionPref(ext3_->id(), |
| 1276 kPrefAppLaunchIndexDeprecated, |
| 1277 Value::CreateIntegerValue(0)); |
| 1278 prefs()->UpdateExtensionPref(ext3_->id(), |
| 1279 kPrefPageIndexDeprecated, |
| 1280 Value::CreateIntegerValue(1)); |
| 1281 |
| 1282 // We insert the ids in reserve order so that we have to deal with the |
| 1283 // element on the 2nd page before the 1st page is seen. |
| 1284 ExtensionPrefs::ExtensionIdSet ids; |
| 1285 ids.push_back(ext3_->id()); |
| 1286 ids.push_back(ext2_->id()); |
| 1287 ids.push_back(ext1_->id()); |
| 1288 |
| 1289 prefs_.prefs()->MigrateAppIndex(ids); |
| 1290 } |
| 1291 virtual void Verify() { |
| 1292 StringOrdinal first_ordinal = StringOrdinal::CreateInitialOrdinal(); |
| 1293 |
| 1294 EXPECT_TRUE(first_ordinal.Equal(prefs()->GetAppLaunchOrdinal(ext1_->id()))); |
| 1295 EXPECT_TRUE(first_ordinal.LessThan( |
| 1296 prefs()->GetAppLaunchOrdinal(ext2_->id()))); |
| 1297 EXPECT_TRUE(first_ordinal.Equal(prefs()->GetAppLaunchOrdinal(ext3_->id()))); |
| 1298 |
| 1299 EXPECT_TRUE(first_ordinal.Equal(prefs()->GetPageOrdinal(ext1_->id()))); |
| 1300 EXPECT_TRUE(first_ordinal.Equal(prefs()->GetPageOrdinal(ext2_->id()))); |
| 1301 EXPECT_TRUE(first_ordinal.LessThan(prefs()->GetPageOrdinal(ext3_->id()))); |
| 1302 } |
| 1303 }; |
| 1304 TEST_F(ExtensionPrefsMigrateAppIndex, ExtensionPrefsMigrateAppIndex) {} |
| 1305 |
| 1306 class ExtensionPrefsGetMinOrMaxAppLaunchOrdinalsOnPage : |
| 1307 public ExtensionPrefsPreferencesBase { |
| 1308 public: |
| 1309 ExtensionPrefsGetMinOrMaxAppLaunchOrdinalsOnPage() {} |
| 1310 virtual ~ExtensionPrefsGetMinOrMaxAppLaunchOrdinalsOnPage() {} |
| 1311 virtual void Initialize() { |
| 1312 DictionaryValue simple_dict; |
| 1313 simple_dict.SetString(keys::kVersion, "1.0.0.0"); |
| 1314 simple_dict.SetString(keys::kName, "unused"); |
| 1315 simple_dict.SetString(keys::kApp, "true"); |
| 1316 simple_dict.SetString(keys::kLaunchLocalPath, "fake.html"); |
| 1317 |
| 1318 std::string error; |
| 1319 app1_scoped_ = Extension::Create( |
| 1320 prefs_.temp_dir().AppendASCII("app1_"), Extension::EXTERNAL_PREF, |
| 1321 simple_dict, Extension::STRICT_ERROR_CHECKS, &error); |
| 1322 prefs()->OnExtensionInstalled(app1_scoped_.get(), |
| 1323 Extension::ENABLED, |
| 1324 false, |
| 1325 StringOrdinal()); |
| 1326 |
| 1327 app2_scoped_ = Extension::Create( |
| 1328 prefs_.temp_dir().AppendASCII("app2_"), Extension::EXTERNAL_PREF, |
| 1329 simple_dict, Extension::STRICT_ERROR_CHECKS, &error); |
| 1330 prefs()->OnExtensionInstalled(app2_scoped_.get(), |
| 1331 Extension::ENABLED, |
| 1332 false, |
| 1333 StringOrdinal()); |
| 1334 } |
| 1335 virtual void Verify() { |
| 1336 StringOrdinal page = StringOrdinal::CreateInitialOrdinal(); |
| 1337 |
| 1338 StringOrdinal min = prefs()->GetMinOrMaxAppLaunchOrdinalsOnPage( |
| 1339 page, |
| 1340 ExtensionPrefs::MIN_ORDINAL); |
| 1341 StringOrdinal max = prefs()->GetMinOrMaxAppLaunchOrdinalsOnPage( |
| 1342 page, |
| 1343 ExtensionPrefs::MAX_ORDINAL); |
| 1344 EXPECT_TRUE(min.IsValid()); |
| 1345 EXPECT_TRUE(max.IsValid()); |
| 1346 EXPECT_TRUE(min.LessThan(max)); |
| 1347 |
| 1348 // Ensure that the min and max values aren't set for empty pages. |
| 1349 min = StringOrdinal(); |
| 1350 max = StringOrdinal(); |
| 1351 StringOrdinal empty_page = page.CreateAfter(); |
| 1352 EXPECT_FALSE(min.IsValid()); |
| 1353 EXPECT_FALSE(max.IsValid()); |
| 1354 min = prefs()->GetMinOrMaxAppLaunchOrdinalsOnPage( |
| 1355 empty_page, |
| 1356 ExtensionPrefs::MIN_ORDINAL); |
| 1357 max = prefs()->GetMinOrMaxAppLaunchOrdinalsOnPage( |
| 1358 empty_page, |
| 1359 ExtensionPrefs::MAX_ORDINAL); |
| 1360 EXPECT_FALSE(min.IsValid()); |
| 1361 EXPECT_FALSE(max.IsValid()); |
| 1362 } |
| 1363 |
| 1364 private: |
| 1365 scoped_refptr<Extension> app1_scoped_; |
| 1366 scoped_refptr<Extension> app2_scoped_; |
| 1367 }; |
| 1368 TEST_F(ExtensionPrefsGetMinOrMaxAppLaunchOrdinalsOnPage, |
| 1369 ExtensionPrefsGetMinOrMaxAppLaunchOrdinalsOnPage) {} |
| OLD | NEW |