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

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

Issue 9150008: Introduce background.scripts feature for extension manifests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready to land Created 8 years, 11 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_file_util_unittest.cc
diff --git a/chrome/common/extensions/extension_file_util_unittest.cc b/chrome/common/extensions/extension_file_util_unittest.cc
index f9c7ef4d5d2b47a16965ce3935e8129995539656..e54a434cd55258fa22cc8b210e50d2ce85c13f1d 100644
--- a/chrome/common/extensions/extension_file_util_unittest.cc
+++ b/chrome/common/extensions/extension_file_util_unittest.cc
@@ -13,7 +13,9 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
namespace keys = extension_manifest_keys;
@@ -260,20 +262,32 @@ TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) {
}
static scoped_refptr<Extension> LoadExtensionManifest(
+ DictionaryValue* manifest,
+ const FilePath& manifest_dir,
+ Extension::Location location,
+ int extra_flags,
+ std::string* error) {
+ scoped_refptr<Extension> extension = Extension::Create(
+ manifest_dir, location, *manifest, extra_flags, error);
+ return extension;
+}
+
+static scoped_refptr<Extension> LoadExtensionManifest(
const std::string& manifest_value,
const FilePath& manifest_dir,
Extension::Location location,
int extra_flags,
std::string* error) {
JSONStringValueSerializer serializer(manifest_value);
- scoped_ptr<Value> result(serializer.Deserialize(NULL, error));
- if (!result.get())
+ Value* result = serializer.Deserialize(NULL, error);
+ if (!result)
return NULL;
-
- scoped_refptr<Extension> extension = Extension::Create(
- manifest_dir, location, *static_cast<DictionaryValue*>(result.get()),
- extra_flags, error);
- return extension;
+ CHECK_EQ(Value::TYPE_DICTIONARY, result->GetType());
+ return LoadExtensionManifest(static_cast<DictionaryValue*>(result),
+ manifest_dir,
+ location,
+ extra_flags,
+ error);
}
#if defined(OS_WIN)
@@ -304,6 +318,43 @@ TEST(ExtensionFileUtil, ValidateThemeUTF8) {
error;
}
+TEST(ExtensionFileUtil, BackgroundScriptsMustExist) {
+ ScopedTempDir temp;
+ ASSERT_TRUE(temp.CreateUniqueTempDir());
+
+ scoped_ptr<DictionaryValue> value(new DictionaryValue());
+ value->SetString("name", "test");
+ value->SetString("version", "1");
+ value->SetInteger("manifest_version", 1);
+
+ ListValue* scripts = new ListValue();
+ scripts->Append(Value::CreateStringValue("foo.js"));
+ value->Set("background.scripts", scripts);
+
+ std::string error;
+ scoped_refptr<Extension> extension = LoadExtensionManifest(
+ value.get(), temp.path(), Extension::LOAD, 0, &error);
+ ASSERT_TRUE(extension.get()) << error;
+
+ EXPECT_FALSE(extension_file_util::ValidateExtension(extension, &error));
+ EXPECT_EQ(l10n_util::GetStringFUTF8(
+ IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")),
+ error);
+
+ scripts->Clear();
+ scripts->Append(Value::CreateStringValue("http://google.com/foo.js"));
+
+ extension = LoadExtensionManifest(value.get(), temp.path(), Extension::LOAD,
+ 0, &error);
+ ASSERT_TRUE(extension.get()) << error;
+
+ EXPECT_FALSE(extension_file_util::ValidateExtension(extension, &error));
+ EXPECT_EQ(l10n_util::GetStringFUTF8(
+ IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED,
+ ASCIIToUTF16("http://google.com/foo.js")),
+ error);
+}
+
// TODO(aa): More tests as motivation allows. Maybe steal some from
// ExtensionService? Many of them could probably be tested here without the
// MessageLoop shenanigans.
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/extensions/extension_manifests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698