Chromium Code Reviews| 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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 EXPECT_TRUE(Extension::GenerateId("test", &result)); | 795 EXPECT_TRUE(Extension::GenerateId("test", &result)); |
| 796 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); | 796 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); |
| 797 | 797 |
| 798 EXPECT_TRUE(Extension::GenerateId("_", &result)); | 798 EXPECT_TRUE(Extension::GenerateId("_", &result)); |
| 799 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); | 799 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); |
| 800 | 800 |
| 801 EXPECT_TRUE(Extension::GenerateId( | 801 EXPECT_TRUE(Extension::GenerateId( |
| 802 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); | 802 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); |
| 803 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); | 803 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); |
| 804 } | 804 } |
| 805 | |
| 806 namespace { | |
| 807 enum SyncTestExtensionType { | |
| 808 EXTENSION, | |
| 809 USER_SCRIPT, | |
| 810 THEME | |
| 811 }; | |
| 812 | |
| 813 static scoped_refptr<Extension> MakeSyncTestExtension( | |
| 814 SyncTestExtensionType type, | |
| 815 const GURL& update_url, | |
| 816 const GURL& launch_url, | |
| 817 Extension::Location location, | |
| 818 int num_plugins, | |
| 819 const FilePath& extension_path) { | |
| 820 DictionaryValue source; | |
| 821 source.SetString(extension_manifest_keys::kName, | |
| 822 "PossiblySyncableExtension"); | |
| 823 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | |
| 824 if (type == THEME) { | |
| 825 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | |
| 826 } | |
| 827 if (!update_url.is_empty()) { | |
| 828 source.SetString(extension_manifest_keys::kUpdateURL, | |
| 829 update_url.spec()); | |
| 830 } | |
| 831 if (!launch_url.is_empty()) { | |
| 832 source.SetString(extension_manifest_keys::kLaunchWebURL, | |
| 833 launch_url.spec()); | |
| 834 } | |
| 835 if (type != THEME) { | |
| 836 source.SetBoolean(extension_manifest_keys::kConvertedFromUserScript, | |
| 837 type == USER_SCRIPT); | |
| 838 ListValue* plugins = new ListValue(); | |
| 839 for (int i = 0; i < num_plugins; ++i) { | |
| 840 DictionaryValue* plugin = new DictionaryValue(); | |
| 841 plugin->SetString(extension_manifest_keys::kPluginsPath, ""); | |
| 842 plugins->Set(i, plugin); | |
| 843 } | |
| 844 source.Set(extension_manifest_keys::kPlugins, plugins); | |
| 845 } | |
| 846 | |
| 847 std::string error; | |
| 848 scoped_refptr<Extension> extension = Extension::Create( | |
| 849 extension_path, location, source, Extension::STRICT_ERROR_CHECKS, &error); | |
| 850 EXPECT_TRUE(extension); | |
| 851 EXPECT_EQ("", error); | |
| 852 return extension; | |
| 853 } | |
| 854 | |
| 855 #if defined(OS_WIN) | |
| 856 static const FilePath::CharType kExtensionFilePath[] = | |
| 857 FILE_PATH_LITERAL("c:\\foo"); | |
| 858 #elif defined(OS_POSIX) | |
| 859 static const FilePath::CharType kExtensionFilePath[] = | |
| 860 FILE_PATH_LITERAL("/foo"); | |
| 861 #endif | |
|
asargent_no_longer_on_chrome
2011/08/12 20:50:39
I think a while back I made it so that you can pas
| |
| 862 | |
| 863 static const char kValidUpdateUrl1[] = | |
| 864 "http://clients2.google.com/service/update2/crx"; | |
| 865 static const char kValidUpdateUrl2[] = | |
| 866 "https://clients2.google.com/service/update2/crx"; | |
| 867 } | |
| 868 | |
| 869 TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { | |
| 870 FilePath file_path(kExtensionFilePath); | |
| 871 scoped_refptr<Extension> extension( | |
| 872 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
| 873 Extension::INTERNAL, 0, file_path)); | |
| 874 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 875 } | |
| 876 | |
| 877 TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { | |
| 878 FilePath file_path(kExtensionFilePath); | |
| 879 scoped_refptr<Extension> extension( | |
| 880 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), | |
| 881 Extension::INTERNAL, 0, file_path)); | |
| 882 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 883 } | |
| 884 | |
| 885 TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { | |
| 886 FilePath file_path(kExtensionFilePath); | |
| 887 scoped_refptr<Extension> extension( | |
| 888 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), | |
| 889 Extension::INTERNAL, 0, file_path)); | |
| 890 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 891 } | |
| 892 | |
| 893 TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { | |
| 894 FilePath file_path(kExtensionFilePath); | |
| 895 scoped_refptr<Extension> extension( | |
| 896 MakeSyncTestExtension(THEME, GURL(), GURL(), | |
| 897 Extension::INTERNAL, 0, file_path)); | |
| 898 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 899 } | |
| 900 | |
| 901 TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { | |
| 902 FilePath file_path(kExtensionFilePath); | |
| 903 scoped_refptr<Extension> extension( | |
| 904 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), | |
| 905 Extension::INTERNAL, 0, file_path)); | |
| 906 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 907 } | |
| 908 | |
| 909 TEST(ExtensionTest, GetSyncTypeExtensionExternal) { | |
| 910 FilePath file_path(kExtensionFilePath); | |
| 911 scoped_refptr<Extension> extension( | |
| 912 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
| 913 Extension::EXTERNAL_PREF, 0, file_path)); | |
| 914 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 915 } | |
| 916 | |
| 917 TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { | |
| 918 FilePath file_path(kExtensionFilePath); | |
| 919 scoped_refptr<Extension> extension( | |
| 920 MakeSyncTestExtension( | |
| 921 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), | |
| 922 Extension::INTERNAL, 0, file_path)); | |
| 923 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 924 } | |
| 925 | |
| 926 // These last 2 tests don't make sense on Chrome OS, where extension plugins | |
| 927 // are not allowed. | |
| 928 #if !defined(OS_CHROMEOS) | |
| 929 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { | |
| 930 FilePath file_path(kExtensionFilePath); | |
| 931 scoped_refptr<Extension> extension( | |
| 932 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
| 933 Extension::INTERNAL, 1, file_path)); | |
| 934 if (extension) | |
| 935 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 936 } | |
| 937 | |
| 938 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | |
| 939 FilePath file_path(kExtensionFilePath); | |
| 940 scoped_refptr<Extension> extension( | |
| 941 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
| 942 Extension::INTERNAL, 2, file_path)); | |
| 943 if (extension) | |
| 944 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
| 945 } | |
| 946 #endif | |
|
asargent_no_longer_on_chrome
2011/08/12 20:50:39
nit: add comment here-
#endif // !defined(CHROME
| |
| OLD | NEW |