diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-12 19:36:42 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-12 19:36:42 +0000 |
commit | 64a02b8056c86576428022859baadbb9a7b929f1 (patch) | |
tree | fba294d94f03345806aeb15f6a2fbb2d8fd652f6 | |
parent | af05c6aa88661f7595b6a883667c352d51e66eb7 (diff) | |
download | chromium_src-64a02b8056c86576428022859baadbb9a7b929f1.zip chromium_src-64a02b8056c86576428022859baadbb9a7b929f1.tar.gz chromium_src-64a02b8056c86576428022859baadbb9a7b929f1.tar.bz2 |
Add version to list of required fields. This is required prep work for extension installation.
Review URL: http://codereview.chromium.org/17320
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7887 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension.cc | 14 | ||||
-rw-r--r-- | chrome/browser/extensions/extension.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_unittest.cc | 9 | ||||
-rwxr-xr-x | chrome/test/data/extensions/extension1/manifest | 1 | ||||
-rwxr-xr-x | chrome/test/data/extensions/extension2/manifest | 1 |
5 files changed, 32 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index 3c5dff0..d93cacd 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -15,11 +15,12 @@ const wchar_t* Extension::kIdKey = L"id"; const wchar_t* Extension::kNameKey = L"name"; const wchar_t* Extension::kDescriptionKey = L"description"; const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; +const wchar_t* Extension::kVersionKey = L"version"; const char* Extension::kInvalidManifestError = "Manifest is missing or invalid."; const char* Extension::kInvalidFormatVersionError = - "Required key 'format_version' is missing or invalid"; + "Required key 'format_version' is missing or invalid."; const char* Extension::kInvalidIdError = "Required key 'id' is missing or invalid."; const char* Extension::kInvalidNameError = @@ -30,6 +31,8 @@ const char* Extension::kInvalidContentScriptsListError = "Invalid type for 'content_scripts' key."; const char* Extension::kInvalidContentScriptError = "Invalid type for content_scripts at index "; +const char* Extension::kInvalidVersionError = + "Required key 'version' is missing or invalid."; bool Extension::InitFromValue(const DictionaryValue& source, std::string* error) { @@ -47,6 +50,12 @@ bool Extension::InitFromValue(const DictionaryValue& source, return false; } + // Initialize version. + if (!source.GetString(kVersionKey, &version_)) { + *error = kInvalidVersionError; + return false; + } + // Initialize name. if (!source.GetString(kNameKey, &name_)) { *error = kInvalidNameError; @@ -95,6 +104,9 @@ void Extension::CopyToValue(DictionaryValue* destination) { // Copy id. destination->SetString(kIdKey, id_); + // Copy version. + destination->SetString(kVersionKey, version_); + // Copy name. destination->SetString(kNameKey, name_); diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h index ac6c671..2b2f775 100644 --- a/chrome/browser/extensions/extension.h +++ b/chrome/browser/extensions/extension.h @@ -30,6 +30,7 @@ class Extension { static const wchar_t* kNameKey; static const wchar_t* kDescriptionKey; static const wchar_t* kContentScriptsKey; + static const wchar_t* kVersionKey; // Error messages returned from InitFromValue(). static const char* kInvalidFormatVersionError; @@ -39,6 +40,7 @@ class Extension { static const char* kInvalidDescriptionError; static const char* kInvalidContentScriptsListError; static const char* kInvalidContentScriptError; + static const char* kInvalidVersionError; // The path to the folder the extension is stored in. const FilePath& path() const { return path_; } @@ -51,6 +53,9 @@ class Extension { // previous version's update key. const std::string& id() const { return id_; } + // The version number for the extension. + const std::string& version() const { return version_; } + // A human-readable name of the extension. const std::string& name() const { return name_; } @@ -75,6 +80,9 @@ class Extension { // The extension's ID. std::string id_; + // The extension's version. + std::string version_; + // The extension's human-readable name. std::string name_; diff --git a/chrome/browser/extensions/extension_unittest.cc b/chrome/browser/extensions/extension_unittest.cc index 7aa51a0..71812b9 100644 --- a/chrome/browser/extensions/extension_unittest.cc +++ b/chrome/browser/extensions/extension_unittest.cc @@ -28,6 +28,14 @@ TEST(ExtensionTest, InitFromValueInvalid) { EXPECT_EQ(Extension::kInvalidIdError, error); input_value.SetString(Extension::kIdKey, L"com.google.myextension"); + // Test missing and invalid versions + EXPECT_FALSE(extension.InitFromValue(input_value, &error)); + EXPECT_EQ(Extension::kInvalidVersionError, error); + input_value.SetInteger(Extension::kVersionKey, 42); + EXPECT_FALSE(extension.InitFromValue(input_value, &error)); + EXPECT_EQ(Extension::kInvalidVersionError, error); + input_value.SetString(Extension::kVersionKey, L"1.0"); + // Test missing and invalid names EXPECT_FALSE(extension.InitFromValue(input_value, &error)); EXPECT_EQ(Extension::kInvalidNameError, error); @@ -64,6 +72,7 @@ TEST(ExtensionTest, InitFromValueValid) { // Test minimal extension input_value.SetInteger(Extension::kFormatVersionKey, 1); input_value.SetString(Extension::kIdKey, L"com.google.myextension"); + input_value.SetString(Extension::kVersionKey, L"1.0"); input_value.SetString(Extension::kNameKey, L"my extension"); EXPECT_TRUE(extension.InitFromValue(input_value, &error)); diff --git a/chrome/test/data/extensions/extension1/manifest b/chrome/test/data/extensions/extension1/manifest index b475913..bfde176 100755 --- a/chrome/test/data/extensions/extension1/manifest +++ b/chrome/test/data/extensions/extension1/manifest @@ -1,6 +1,7 @@ {
"format_version": 1,
"id": "com.google.myextension1",
+ "version": "1.0",
"name": "My extension 1",
"description": "The first extension that I made.",
"content_scripts": [
diff --git a/chrome/test/data/extensions/extension2/manifest b/chrome/test/data/extensions/extension2/manifest index 82b25d8d..0f58ffd 100755 --- a/chrome/test/data/extensions/extension2/manifest +++ b/chrome/test/data/extensions/extension2/manifest @@ -1,5 +1,6 @@ {
"format_version": 1,
"id": "com.google.myextension2",
+ "version": "1.0",
"name": "My extension 2"
}
|