| 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" | |
| 14 #include "chrome/browser/prefs/pref_change_registrar.h" | 13 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/common/extensions/extension_permission_set.h" | 17 #include "chrome/common/extensions/extension_permission_set.h" |
| 19 #include "chrome/common/string_ordinal.h" | |
| 20 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 22 #include "content/test/notification_observer_mock.h" | 20 #include "content/test/notification_observer_mock.h" |
| 23 #include "content/test/test_browser_thread.h" | 21 #include "content/test/test_browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 23 |
| 26 using base::Time; | 24 using base::Time; |
| 27 using base::TimeDelta; | 25 using base::TimeDelta; |
| 28 using content::BrowserThread; | 26 using content::BrowserThread; |
| 29 | 27 |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 std::string id4_; | 647 std::string id4_; |
| 650 }; | 648 }; |
| 651 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} | 649 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} |
| 652 | 650 |
| 653 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { | 651 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { |
| 654 public: | 652 public: |
| 655 virtual void Initialize() { | 653 virtual void Initialize() { |
| 656 extension_ = prefs_.AddExtension("on_extension_installed"); | 654 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 657 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 655 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 658 prefs()->OnExtensionInstalled( | 656 prefs()->OnExtensionInstalled( |
| 659 extension_.get(), Extension::DISABLED, false, | 657 extension_.get(), Extension::DISABLED, false, -1); |
| 660 StringOrdinal()); | |
| 661 } | 658 } |
| 662 | 659 |
| 663 virtual void Verify() { | 660 virtual void Verify() { |
| 664 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); | 661 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); |
| 665 } | 662 } |
| 666 | 663 |
| 667 private: | 664 private: |
| 668 scoped_refptr<Extension> extension_; | 665 scoped_refptr<Extension> extension_; |
| 669 }; | 666 }; |
| 670 TEST_F(ExtensionPrefsOnExtensionInstalled, | 667 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 671 ExtensionPrefsOnExtensionInstalled) {} | 668 ExtensionPrefsOnExtensionInstalled) {} |
| 672 | 669 |
| 673 class ExtensionPrefsAppLaunchOrdinal : public ExtensionPrefsTest { | 670 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { |
| 674 public: | 671 public: |
| 675 virtual void Initialize() { | 672 virtual void Initialize() { |
| 676 // No extensions yet. | 673 // No extensions yet. |
| 677 StringOrdinal page = StringOrdinal::CreateInitialOrdinal(); | 674 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex(0)); |
| 678 EXPECT_TRUE(StringOrdinal::CreateInitialOrdinal().Equal( | |
| 679 prefs()->CreateNextAppLaunchOrdinal(page))); | |
| 680 | 675 |
| 681 extension_ = prefs_.AddApp("on_extension_installed"); | 676 extension_ = prefs_.AddApp("on_extension_installed"); |
| 682 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 677 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 683 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 678 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 684 false, StringOrdinal()); | 679 false, -1); |
| 685 } | 680 } |
| 686 | 681 |
| 687 virtual void Verify() { | 682 virtual void Verify() { |
| 688 StringOrdinal launch_ordinal = | 683 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
| 689 prefs()->GetAppLaunchOrdinal(extension_->id()); | 684 // Extension should have been assigned a launch index > 0. |
| 690 StringOrdinal page_ordinal = StringOrdinal::CreateInitialOrdinal(); | 685 EXPECT_GT(launch_index, 0); |
| 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); |
| 691 | 692 |
| 692 // Extension should have been assigned a valid StringOrdinal. | 693 // This extension doesn't exist, so it should return -1. |
| 693 EXPECT_TRUE(launch_ordinal.IsValid()); | 694 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); |
| 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)); | |
| 703 | 695 |
| 704 // This extension doesn't exist, so it should return an invalid | 696 // The second page doesn't have any apps so its next launch index should |
| 705 // StringOrdinal. | 697 // still be 0. |
| 706 StringOrdinal invalid_app_launch_ordinal = | 698 EXPECT_EQ(prefs()->GetNextAppLaunchIndex(1), 0); |
| 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))); | |
| 719 } | 699 } |
| 720 | 700 |
| 721 private: | 701 private: |
| 722 scoped_refptr<Extension> extension_; | 702 scoped_refptr<Extension> extension_; |
| 723 }; | 703 }; |
| 724 TEST_F(ExtensionPrefsAppLaunchOrdinal, ExtensionPrefsAppLaunchOrdinal) {} | 704 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} |
| 725 | 705 |
| 726 class ExtensionPrefsPageOrdinal : public ExtensionPrefsTest { | 706 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { |
| 727 public: | 707 public: |
| 728 virtual void Initialize() { | 708 virtual void Initialize() { |
| 729 extension_ = prefs_.AddApp("page_ordinal"); | 709 extension_ = prefs_.AddApp("page_index"); |
| 730 // Install with a page preference. | 710 // Install to page 3 (index 2). |
| 731 StringOrdinal page = StringOrdinal::CreateInitialOrdinal(); | |
| 732 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 711 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 733 false, page); | 712 false, 2); |
| 734 EXPECT_TRUE(page.Equal(prefs()->GetPageOrdinal(extension_->id()))); | 713 EXPECT_EQ(2, prefs()->GetPageIndex(extension_->id())); |
| 735 EXPECT_EQ(0, prefs()->PageStringOrdinalAsInteger(page)); | |
| 736 | 714 |
| 737 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_ordinal_2"); | 715 scoped_refptr<Extension> extension2 = prefs_.AddApp("page_index_2"); |
| 738 // Install without any page preference. | 716 // Install without any page preference. |
| 739 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 717 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 740 false, StringOrdinal()); | 718 false, -1); |
| 741 EXPECT_TRUE(prefs()->GetPageOrdinal(extension_->id()).IsValid()); | 719 EXPECT_EQ(0, prefs()->GetPageIndex(extension_->id())); |
| 742 } | 720 } |
| 743 | 721 |
| 744 virtual void Verify() { | 722 virtual void Verify() { |
| 745 StringOrdinal old_page = prefs()->GetPageOrdinal(extension_->id()); | 723 // Set the page index. |
| 746 StringOrdinal new_page = old_page.CreateAfter(); | 724 prefs()->SetPageIndex(extension_->id(), 1); |
| 725 // Verify the page index. |
| 726 EXPECT_EQ(1, prefs()->GetPageIndex(extension_->id())); |
| 747 | 727 |
| 748 // Set the page ordinal. | 728 // This extension doesn't exist, so it should return -1. |
| 749 prefs()->SetPageOrdinal(extension_->id(), new_page); | 729 EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); |
| 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()); | |
| 757 } | 730 } |
| 758 | 731 |
| 759 private: | 732 private: |
| 760 scoped_refptr<Extension> extension_; | 733 scoped_refptr<Extension> extension_; |
| 761 }; | 734 }; |
| 762 TEST_F(ExtensionPrefsPageOrdinal, ExtensionPrefsPageOrdinal) {} | 735 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} |
| 763 | 736 |
| 764 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { | 737 class ExtensionPrefsAppLocation : public ExtensionPrefsTest { |
| 765 public: | 738 public: |
| 766 virtual void Initialize() { | 739 virtual void Initialize() { |
| 767 extension_ = prefs_.AddExtension("not_an_app"); | 740 extension_ = prefs_.AddExtension("not_an_app"); |
| 768 // Non-apps should not have any app launch ordinal or page ordinal. | 741 // Non-apps should not have any app launch index or page index. |
| 769 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 742 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 770 false, StringOrdinal()); | 743 false, 0); |
| 771 } | 744 } |
| 772 | 745 |
| 773 virtual void Verify() { | 746 virtual void Verify() { |
| 774 EXPECT_FALSE(prefs()->GetAppLaunchOrdinal(extension_->id()).IsValid()); | 747 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex(extension_->id())); |
| 775 EXPECT_FALSE(prefs()->GetPageOrdinal(extension_->id()).IsValid()); | 748 EXPECT_EQ(-1, prefs()->GetPageIndex(extension_->id())); |
| 776 } | 749 } |
| 777 | 750 |
| 778 private: | 751 private: |
| 779 scoped_refptr<Extension> extension_; | 752 scoped_refptr<Extension> extension_; |
| 780 }; | 753 }; |
| 781 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} | 754 TEST_F(ExtensionPrefsAppLocation, ExtensionPrefsAppLocation) {} |
| 782 | 755 |
| 783 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { | 756 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { |
| 784 public: | 757 public: |
| 785 virtual void Initialize() { | 758 virtual void Initialize() { |
| 786 extension_ = prefs_.AddExtension("on_extension_installed"); | 759 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 787 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); | 760 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 788 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 761 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 789 false, StringOrdinal()); | 762 false, -1); |
| 790 } | 763 } |
| 791 | 764 |
| 792 virtual void Verify() { | 765 virtual void Verify() { |
| 793 // Set the flag and see if it persisted. | 766 // Set the flag and see if it persisted. |
| 794 prefs()->SetAppDraggedByUser(extension_->id()); | 767 prefs()->SetAppDraggedByUser(extension_->id()); |
| 795 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 768 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 796 | 769 |
| 797 // Make sure it doesn't change on consecutive calls. | 770 // Make sure it doesn't change on consecutive calls. |
| 798 prefs()->SetAppDraggedByUser(extension_->id()); | 771 prefs()->SetAppDraggedByUser(extension_->id()); |
| 799 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 772 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 | 902 |
| 930 // Flags indicating whether each of the extensions has been installed, yet. | 903 // Flags indicating whether each of the extensions has been installed, yet. |
| 931 bool installed[3]; | 904 bool installed[3]; |
| 932 | 905 |
| 933 private: | 906 private: |
| 934 void EnsureExtensionInstalled(Extension *ext) { | 907 void EnsureExtensionInstalled(Extension *ext) { |
| 935 // Install extension the first time a preference is set for it. | 908 // Install extension the first time a preference is set for it. |
| 936 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 909 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
| 937 for (int i = 0; i < 3; ++i) { | 910 for (int i = 0; i < 3; ++i) { |
| 938 if (ext == extensions[i] && !installed[i]) { | 911 if (ext == extensions[i] && !installed[i]) { |
| 939 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, | 912 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false, -1); |
| 940 false, StringOrdinal()); | |
| 941 installed[i] = true; | 913 installed[i] = true; |
| 942 break; | 914 break; |
| 943 } | 915 } |
| 944 } | 916 } |
| 945 } | 917 } |
| 946 | 918 |
| 947 void EnsureExtensionUninstalled(const std::string& extension_id) { | 919 void EnsureExtensionUninstalled(const std::string& extension_id) { |
| 948 Extension* extensions[] = {ext1_, ext2_, ext3_}; | 920 Extension* extensions[] = {ext1_, ext2_, ext3_}; |
| 949 for (int i = 0; i < 3; ++i) { | 921 for (int i = 0; i < 3; ++i) { |
| 950 if (extensions[i]->id() == extension_id) { | 922 if (extensions[i]->id() == extension_id) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 ++iteration_; | 1209 ++iteration_; |
| 1238 } else { | 1210 } else { |
| 1239 EXPECT_EQ(kDefaultPref1, actual); | 1211 EXPECT_EQ(kDefaultPref1, actual); |
| 1240 } | 1212 } |
| 1241 } | 1213 } |
| 1242 | 1214 |
| 1243 private: | 1215 private: |
| 1244 int iteration_; | 1216 int iteration_; |
| 1245 }; | 1217 }; |
| 1246 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} | 1218 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 |