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 static const char kValidUpdateUrl1[] = | |
856 "http://clients2.google.com/service/update2/crx"; | |
857 static const char kValidUpdateUrl2[] = | |
858 "https://clients2.google.com/service/update2/crx"; | |
859 } | |
860 | |
861 TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { | |
862 scoped_refptr<Extension> extension( | |
863 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
864 Extension::INTERNAL, 0, FilePath())); | |
865 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
866 } | |
867 | |
868 TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { | |
869 scoped_refptr<Extension> extension( | |
870 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), | |
871 Extension::INTERNAL, 0, FilePath())); | |
872 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
873 } | |
874 | |
875 TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { | |
876 scoped_refptr<Extension> extension( | |
877 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), | |
878 Extension::INTERNAL, 0, FilePath())); | |
879 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
880 } | |
881 | |
882 TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { | |
883 scoped_refptr<Extension> extension( | |
884 MakeSyncTestExtension(THEME, GURL(), GURL(), | |
885 Extension::INTERNAL, 0, FilePath())); | |
886 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
887 } | |
888 | |
889 TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { | |
890 scoped_refptr<Extension> extension( | |
891 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), | |
892 Extension::INTERNAL, 0, FilePath())); | |
893 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
894 } | |
895 | |
896 TEST(ExtensionTest, GetSyncTypeExtensionExternal) { | |
897 scoped_refptr<Extension> extension( | |
898 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
899 Extension::EXTERNAL_PREF, 0, FilePath())); | |
900 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
901 } | |
902 | |
903 TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { | |
904 scoped_refptr<Extension> extension( | |
905 MakeSyncTestExtension( | |
906 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), | |
907 Extension::INTERNAL, 0, FilePath())); | |
908 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
909 } | |
910 | |
911 // These last 2 tests don't make sense on Chrome OS, where extension plugins | |
912 // are not allowed. | |
913 #if !defined(OS_CHROMEOS) | |
914 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { | |
915 scoped_refptr<Extension> extension( | |
916 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
917 Extension::INTERNAL, 1, FilePath())); | |
918 if (extension) | |
919 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
920 } | |
921 | |
922 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | |
923 scoped_refptr<Extension> extension( | |
924 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | |
925 Extension::INTERNAL, 2, FilePath())); | |
926 if (extension) | |
927 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | |
928 } | |
929 #endif // !defined(OS_CHROMEOS) | |
OLD | NEW |