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

Unified Diff: chrome/common/extensions/extension_unittest.cc

Issue 7564037: Apps/Extensions Sync refactoring -- delete most of the old glue, implement new sync API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension_unittest.cc
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index f260141834c7e85c63e92993e683d919d9b218bc..5a6c35d869491f45234fe87cf98dd275e4cae678 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -802,3 +802,145 @@ TEST(ExtensionTest, GenerateId) {
"this_string_is_longer_than_a_single_sha256_hash_digest", &result));
EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi");
}
+
+namespace {
+enum SyncTestExtensionType {
+ EXTENSION,
+ USER_SCRIPT,
+ THEME
+};
+
+static scoped_refptr<Extension> MakeSyncTestExtension(
+ SyncTestExtensionType type,
+ const GURL& update_url,
+ const GURL& launch_url,
+ Extension::Location location,
+ int num_plugins,
+ const FilePath& extension_path) {
+ DictionaryValue source;
+ source.SetString(extension_manifest_keys::kName,
+ "PossiblySyncableExtension");
+ source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
+ if (type == THEME) {
+ source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
+ }
+ if (!update_url.is_empty()) {
+ source.SetString(extension_manifest_keys::kUpdateURL,
+ update_url.spec());
+ }
+ if (!launch_url.is_empty()) {
+ source.SetString(extension_manifest_keys::kLaunchWebURL,
+ launch_url.spec());
+ }
+ if (type != THEME) {
+ source.SetBoolean(extension_manifest_keys::kConvertedFromUserScript,
+ type == USER_SCRIPT);
+ ListValue* plugins = new ListValue();
+ for (int i = 0; i < num_plugins; ++i) {
+ DictionaryValue* plugin = new DictionaryValue();
+ plugin->SetString(extension_manifest_keys::kPluginsPath, "");
+ plugins->Set(i, plugin);
+ }
+ source.Set(extension_manifest_keys::kPlugins, plugins);
+ }
+
+ std::string error;
+ scoped_refptr<Extension> extension = Extension::Create(
+ extension_path, location, source, Extension::STRICT_ERROR_CHECKS, &error);
+ EXPECT_TRUE(extension);
+ EXPECT_EQ("", error);
+ return extension;
+}
+
+#if defined(OS_WIN)
+static const FilePath::CharType kExtensionFilePath[] =
+ FILE_PATH_LITERAL("c:\\foo");
+#elif defined(OS_POSIX)
+static const FilePath::CharType kExtensionFilePath[] =
+ FILE_PATH_LITERAL("/foo");
+#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
+
+static const char kValidUpdateUrl1[] =
+ "http://clients2.google.com/service/update2/crx";
+static const char kValidUpdateUrl2[] =
+ "https://clients2.google.com/service/update2/crx";
+}
+
+TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
+ Extension::INTERNAL, 0, file_path));
+ EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(),
+ Extension::INTERNAL, 0, file_path));
+ EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(),
+ Extension::INTERNAL, 0, file_path));
+ EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(THEME, GURL(), GURL(),
+ Extension::INTERNAL, 0, file_path));
+ EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"),
+ Extension::INTERNAL, 0, file_path));
+ EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeExtensionExternal) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
+ Extension::EXTERNAL_PREF, 0, file_path));
+ EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(
+ USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(),
+ Extension::INTERNAL, 0, file_path));
+ EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+// These last 2 tests don't make sense on Chrome OS, where extension plugins
+// are not allowed.
+#if !defined(OS_CHROMEOS)
+TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
+ Extension::INTERNAL, 1, file_path));
+ if (extension)
+ EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+
+TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) {
+ FilePath file_path(kExtensionFilePath);
+ scoped_refptr<Extension> extension(
+ MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
+ Extension::INTERNAL, 2, file_path));
+ if (extension)
+ EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
+}
+#endif
asargent_no_longer_on_chrome 2011/08/12 20:50:39 nit: add comment here- #endif // !defined(CHROME
« chrome/common/extensions/extension.cc ('K') | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698