Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 10855190: Disable sync for default apps (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 USER_SCRIPT, 1048 USER_SCRIPT,
1049 THEME 1049 THEME
1050 }; 1050 };
1051 1051
1052 static scoped_refptr<Extension> MakeSyncTestExtension( 1052 static scoped_refptr<Extension> MakeSyncTestExtension(
1053 SyncTestExtensionType type, 1053 SyncTestExtensionType type,
1054 const GURL& update_url, 1054 const GURL& update_url,
1055 const GURL& launch_url, 1055 const GURL& launch_url,
1056 Extension::Location location, 1056 Extension::Location location,
1057 int num_plugins, 1057 int num_plugins,
1058 const FilePath& extension_path) { 1058 const FilePath& extension_path,
1059 int creation_flags) {
1059 DictionaryValue source; 1060 DictionaryValue source;
1060 source.SetString(extension_manifest_keys::kName, 1061 source.SetString(extension_manifest_keys::kName,
1061 "PossiblySyncableExtension"); 1062 "PossiblySyncableExtension");
1062 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); 1063 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
1063 if (type == APP) 1064 if (type == APP)
1064 source.SetString(extension_manifest_keys::kApp, "true"); 1065 source.SetString(extension_manifest_keys::kApp, "true");
1065 if (type == THEME) 1066 if (type == THEME)
1066 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); 1067 source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
1067 if (!update_url.is_empty()) { 1068 if (!update_url.is_empty()) {
1068 source.SetString(extension_manifest_keys::kUpdateURL, 1069 source.SetString(extension_manifest_keys::kUpdateURL,
(...skipping 10 matching lines...) Expand all
1079 for (int i = 0; i < num_plugins; ++i) { 1080 for (int i = 0; i < num_plugins; ++i) {
1080 DictionaryValue* plugin = new DictionaryValue(); 1081 DictionaryValue* plugin = new DictionaryValue();
1081 plugin->SetString(extension_manifest_keys::kPluginsPath, ""); 1082 plugin->SetString(extension_manifest_keys::kPluginsPath, "");
1082 plugins->Set(i, plugin); 1083 plugins->Set(i, plugin);
1083 } 1084 }
1084 source.Set(extension_manifest_keys::kPlugins, plugins); 1085 source.Set(extension_manifest_keys::kPlugins, plugins);
1085 } 1086 }
1086 1087
1087 std::string error; 1088 std::string error;
1088 scoped_refptr<Extension> extension = Extension::Create( 1089 scoped_refptr<Extension> extension = Extension::Create(
1089 extension_path, location, source, Extension::NO_FLAGS, &error); 1090 extension_path, location, source, creation_flags, &error);
1090 EXPECT_TRUE(extension); 1091 EXPECT_TRUE(extension);
1091 EXPECT_EQ("", error); 1092 EXPECT_EQ("", error);
1092 return extension; 1093 return extension;
1093 } 1094 }
1094 1095
1095 static const char kValidUpdateUrl1[] = 1096 static const char kValidUpdateUrl1[] =
1096 "http://clients2.google.com/service/update2/crx"; 1097 "http://clients2.google.com/service/update2/crx";
1097 static const char kValidUpdateUrl2[] = 1098 static const char kValidUpdateUrl2[] =
1098 "https://clients2.google.com/service/update2/crx"; 1099 "https://clients2.google.com/service/update2/crx";
1099 } 1100 }
1100 1101
1101 TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { 1102 TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) {
1102 scoped_refptr<Extension> extension( 1103 scoped_refptr<Extension> extension(
1103 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1104 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1104 Extension::INTERNAL, 0, FilePath())); 1105 Extension::INTERNAL, 0, FilePath(),
1106 Extension::NO_FLAGS));
1105 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1107 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1106 } 1108 }
1107 1109
1108 TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { 1110 TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) {
1109 scoped_refptr<Extension> extension( 1111 scoped_refptr<Extension> extension(
1110 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), 1112 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(),
1111 Extension::INTERNAL, 0, FilePath())); 1113 Extension::INTERNAL, 0, FilePath(),
1114 Extension::NO_FLAGS));
1112 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1115 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1113 } 1116 }
1114 1117
1115 TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { 1118 TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) {
1116 scoped_refptr<Extension> extension( 1119 scoped_refptr<Extension> extension(
1117 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), 1120 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(),
1118 Extension::INTERNAL, 0, FilePath())); 1121 Extension::INTERNAL, 0, FilePath(),
1122 Extension::NO_FLAGS));
1119 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1123 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1120 } 1124 }
1121 1125
1122 TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { 1126 TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) {
1123 scoped_refptr<Extension> extension( 1127 scoped_refptr<Extension> extension(
1124 MakeSyncTestExtension(THEME, GURL(), GURL(), 1128 MakeSyncTestExtension(THEME, GURL(), GURL(),
1125 Extension::INTERNAL, 0, FilePath())); 1129 Extension::INTERNAL, 0, FilePath(),
1130 Extension::NO_FLAGS));
1126 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1131 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1127 } 1132 }
1128 1133
1129 TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { 1134 TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) {
1130 scoped_refptr<Extension> extension( 1135 scoped_refptr<Extension> extension(
1131 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), 1136 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"),
1132 Extension::INTERNAL, 0, FilePath())); 1137 Extension::INTERNAL, 0, FilePath(),
1138 Extension::NO_FLAGS));
1133 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1139 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1134 } 1140 }
1135 1141
1136 TEST(ExtensionTest, GetSyncTypeExtensionExternal) { 1142 TEST(ExtensionTest, GetSyncTypeExtensionExternal) {
1137 scoped_refptr<Extension> extension( 1143 scoped_refptr<Extension> extension(
1138 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1144 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1139 Extension::EXTERNAL_PREF, 0, FilePath())); 1145 Extension::EXTERNAL_PREF, 0, FilePath(),
1146 Extension::NO_FLAGS));
1147
1140 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1148 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1141 } 1149 }
1142 1150
1143 TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { 1151 TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) {
1144 scoped_refptr<Extension> extension( 1152 scoped_refptr<Extension> extension(
1145 MakeSyncTestExtension( 1153 MakeSyncTestExtension(
1146 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), 1154 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(),
1147 Extension::INTERNAL, 0, FilePath())); 1155 Extension::INTERNAL, 0, FilePath(), Extension::NO_FLAGS));
1148 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1156 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1149 } 1157 }
1150 1158
1151 TEST(ExtensionTest, OnlyDisplayAppsInLauncher) { 1159 TEST(ExtensionTest, OnlyDisplayAppsInLauncher) {
1152 scoped_refptr<Extension> extension( 1160 scoped_refptr<Extension> extension(
1153 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1161 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1154 Extension::INTERNAL, 0, FilePath())); 1162 Extension::INTERNAL, 0, FilePath(),
1163 Extension::NO_FLAGS));
1164
1155 EXPECT_FALSE(extension->ShouldDisplayInLauncher()); 1165 EXPECT_FALSE(extension->ShouldDisplayInLauncher());
1156 1166
1157 scoped_refptr<Extension> app( 1167 scoped_refptr<Extension> app(
1158 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), 1168 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"),
1159 Extension::INTERNAL, 0, FilePath())); 1169 Extension::INTERNAL, 0, FilePath(),
1170 Extension::NO_FLAGS));
1160 EXPECT_TRUE(app->ShouldDisplayInLauncher()); 1171 EXPECT_TRUE(app->ShouldDisplayInLauncher());
1161 } 1172 }
1162 1173
1163 TEST(ExtensionTest, OnlySyncInternal) { 1174 TEST(ExtensionTest, OnlySyncInternal) {
1164 scoped_refptr<Extension> extension_internal( 1175 scoped_refptr<Extension> extension_internal(
1165 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1176 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1166 Extension::INTERNAL, 0, FilePath())); 1177 Extension::INTERNAL, 0, FilePath(),
1178 Extension::NO_FLAGS));
1167 EXPECT_TRUE(extension_internal->IsSyncable()); 1179 EXPECT_TRUE(extension_internal->IsSyncable());
1168 1180
1169 scoped_refptr<Extension> extension_noninternal( 1181 scoped_refptr<Extension> extension_noninternal(
1170 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1182 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1171 Extension::COMPONENT, 0, FilePath())); 1183 Extension::COMPONENT, 0, FilePath(),
1184 Extension::NO_FLAGS));
1172 EXPECT_FALSE(extension_noninternal->IsSyncable()); 1185 EXPECT_FALSE(extension_noninternal->IsSyncable());
1173 } 1186 }
1174 1187
1188 TEST(ExtensionTest, DontSyncDefault) {
1189 scoped_refptr<Extension> extension_default(
1190 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1191 Extension::INTERNAL, 0, FilePath(),
1192 Extension::WAS_INSTALLED_BY_DEFAULT));
1193 EXPECT_FALSE(extension_default->IsSyncable());
1194 }
1195
1175 // These last 2 tests don't make sense on Chrome OS, where extension plugins 1196 // These last 2 tests don't make sense on Chrome OS, where extension plugins
1176 // are not allowed. 1197 // are not allowed.
1177 #if !defined(OS_CHROMEOS) 1198 #if !defined(OS_CHROMEOS)
1178 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { 1199 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) {
1179 scoped_refptr<Extension> extension( 1200 scoped_refptr<Extension> extension(
1180 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1201 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1181 Extension::INTERNAL, 1, FilePath())); 1202 Extension::INTERNAL, 1, FilePath(),
1203 Extension::NO_FLAGS));
1182 if (extension) 1204 if (extension)
1183 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1205 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1184 } 1206 }
1185 1207
1186 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { 1208 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) {
1187 scoped_refptr<Extension> extension( 1209 scoped_refptr<Extension> extension(
1188 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1210 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1189 Extension::INTERNAL, 2, FilePath())); 1211 Extension::INTERNAL, 2, FilePath(),
1212 Extension::NO_FLAGS));
1190 if (extension) 1213 if (extension)
1191 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1214 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1192 } 1215 }
1193 #endif // !defined(OS_CHROMEOS) 1216 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698