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

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

Issue 10536084: Add a warning when developing an extension that uses old manifest version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blonk Created 8 years, 6 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/manifest_tests/extension_manifests_manifest_version_unittest.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/manifest.h" 5 #include "chrome/common/extensions/manifest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 scoped_ptr<DictionaryValue> manifest_value(new DictionaryValue()); 58 scoped_ptr<DictionaryValue> manifest_value(new DictionaryValue());
59 manifest_value->SetString(keys::kName, "extension"); 59 manifest_value->SetString(keys::kName, "extension");
60 manifest_value->SetString(keys::kVersion, "1"); 60 manifest_value->SetString(keys::kVersion, "1");
61 // Only supported in manifest_version=1. 61 // Only supported in manifest_version=1.
62 manifest_value->SetString(keys::kBackgroundPageLegacy, "bg.html"); 62 manifest_value->SetString(keys::kBackgroundPageLegacy, "bg.html");
63 manifest_value->SetString("unknown_key", "foo"); 63 manifest_value->SetString("unknown_key", "foo");
64 64
65 scoped_ptr<Manifest> manifest( 65 scoped_ptr<Manifest> manifest(
66 new Manifest(Extension::INTERNAL, manifest_value.Pass())); 66 new Manifest(Extension::INTERNAL, manifest_value.Pass()));
67 std::string error; 67 std::string error;
68 std::vector<std::string> warnings; 68 Extension::InstallWarningVector warnings;
69 manifest->ValidateManifest(&error, &warnings); 69 manifest->ValidateManifest(&error, &warnings);
70 EXPECT_TRUE(error.empty()); 70 EXPECT_TRUE(error.empty());
71 ASSERT_EQ(1u, warnings.size()); 71 ASSERT_EQ(1u, warnings.size());
72 AssertType(manifest.get(), Extension::TYPE_EXTENSION); 72 AssertType(manifest.get(), Extension::TYPE_EXTENSION);
73 73
74 // The known key 'background_page' should be accessible. 74 // The known key 'background_page' should be accessible.
75 std::string value; 75 std::string value;
76 EXPECT_TRUE(manifest->GetString(keys::kBackgroundPageLegacy, &value)); 76 EXPECT_TRUE(manifest->GetString(keys::kBackgroundPageLegacy, &value));
77 EXPECT_EQ("bg.html", value); 77 EXPECT_EQ("bg.html", value);
78 78
(...skipping 12 matching lines...) Expand all
91 // Validate should also give a warning. 91 // Validate should also give a warning.
92 warnings.clear(); 92 warnings.clear();
93 manifest->ValidateManifest(&error, &warnings); 93 manifest->ValidateManifest(&error, &warnings);
94 EXPECT_TRUE(error.empty()); 94 EXPECT_TRUE(error.empty());
95 ASSERT_EQ(2u, warnings.size()); 95 ASSERT_EQ(2u, warnings.size());
96 { 96 {
97 Feature feature; 97 Feature feature;
98 feature.set_name("background_page"); 98 feature.set_name("background_page");
99 feature.set_max_manifest_version(1); 99 feature.set_max_manifest_version(1);
100 EXPECT_EQ(feature.GetErrorMessage(Feature::INVALID_MAX_MANIFEST_VERSION), 100 EXPECT_EQ(feature.GetErrorMessage(Feature::INVALID_MAX_MANIFEST_VERSION),
101 warnings[0]); 101 warnings[0].message);
102 } 102 }
103 103
104 // Test DeepCopy and Equals. 104 // Test DeepCopy and Equals.
105 scoped_ptr<Manifest> manifest2(manifest->DeepCopy()); 105 scoped_ptr<Manifest> manifest2(manifest->DeepCopy());
106 EXPECT_TRUE(manifest->Equals(manifest2.get())); 106 EXPECT_TRUE(manifest->Equals(manifest2.get()));
107 EXPECT_TRUE(manifest2->Equals(manifest.get())); 107 EXPECT_TRUE(manifest2->Equals(manifest.get()));
108 MutateManifest( 108 MutateManifest(
109 &manifest, "foo", Value::CreateStringValue("blah")); 109 &manifest, "foo", Value::CreateStringValue("blah"));
110 EXPECT_FALSE(manifest->Equals(manifest2.get())); 110 EXPECT_FALSE(manifest->Equals(manifest2.get()));
111 } 111 }
112 112
113 // Verifies that key restriction based on type works. 113 // Verifies that key restriction based on type works.
114 TEST_F(ManifestTest, ExtensionTypes) { 114 TEST_F(ManifestTest, ExtensionTypes) {
115 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 115 scoped_ptr<DictionaryValue> value(new DictionaryValue());
116 value->SetString(keys::kName, "extension"); 116 value->SetString(keys::kName, "extension");
117 value->SetString(keys::kVersion, "1"); 117 value->SetString(keys::kVersion, "1");
118 118
119 scoped_ptr<Manifest> manifest( 119 scoped_ptr<Manifest> manifest(
120 new Manifest(Extension::INTERNAL, value.Pass())); 120 new Manifest(Extension::INTERNAL, value.Pass()));
121 std::string error; 121 std::string error;
122 std::vector<std::string> warnings; 122 Extension::InstallWarningVector warnings;
123 manifest->ValidateManifest(&error, &warnings); 123 manifest->ValidateManifest(&error, &warnings);
124 EXPECT_TRUE(error.empty()); 124 EXPECT_TRUE(error.empty());
125 EXPECT_TRUE(warnings.empty()); 125 EXPECT_TRUE(warnings.empty());
126 126
127 // By default, the type is Extension. 127 // By default, the type is Extension.
128 AssertType(manifest.get(), Extension::TYPE_EXTENSION); 128 AssertType(manifest.get(), Extension::TYPE_EXTENSION);
129 129
130 // Theme. 130 // Theme.
131 MutateManifest( 131 MutateManifest(
132 &manifest, keys::kTheme, new DictionaryValue()); 132 &manifest, keys::kTheme, new DictionaryValue());
(...skipping 28 matching lines...) Expand all
161 161
162 // Verifies that the getters filter restricted keys. 162 // Verifies that the getters filter restricted keys.
163 TEST_F(ManifestTest, RestrictedKeys) { 163 TEST_F(ManifestTest, RestrictedKeys) {
164 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 164 scoped_ptr<DictionaryValue> value(new DictionaryValue());
165 value->SetString(keys::kName, "extension"); 165 value->SetString(keys::kName, "extension");
166 value->SetString(keys::kVersion, "1"); 166 value->SetString(keys::kVersion, "1");
167 167
168 scoped_ptr<Manifest> manifest( 168 scoped_ptr<Manifest> manifest(
169 new Manifest(Extension::INTERNAL, value.Pass())); 169 new Manifest(Extension::INTERNAL, value.Pass()));
170 std::string error; 170 std::string error;
171 std::vector<std::string> warnings; 171 Extension::InstallWarningVector warnings;
172 manifest->ValidateManifest(&error, &warnings); 172 manifest->ValidateManifest(&error, &warnings);
173 EXPECT_TRUE(error.empty()); 173 EXPECT_TRUE(error.empty());
174 EXPECT_TRUE(warnings.empty()); 174 EXPECT_TRUE(warnings.empty());
175 175
176 // Platform apps cannot have a "page_action" key. 176 // Platform apps cannot have a "page_action" key.
177 MutateManifest( 177 MutateManifest(
178 &manifest, keys::kPageAction, new DictionaryValue()); 178 &manifest, keys::kPageAction, new DictionaryValue());
179 AssertType(manifest.get(), Extension::TYPE_EXTENSION); 179 AssertType(manifest.get(), Extension::TYPE_EXTENSION);
180 base::Value* output = NULL; 180 base::Value* output = NULL;
181 EXPECT_TRUE(manifest->HasKey(keys::kPageAction)); 181 EXPECT_TRUE(manifest->HasKey(keys::kPageAction));
(...skipping 13 matching lines...) Expand all
195 EXPECT_FALSE(manifest->HasKey(keys::kCommands)); 195 EXPECT_FALSE(manifest->HasKey(keys::kCommands));
196 EXPECT_FALSE(manifest->Get(keys::kCommands, &output)); 196 EXPECT_FALSE(manifest->Get(keys::kCommands, &output));
197 197
198 MutateManifest( 198 MutateManifest(
199 &manifest, keys::kManifestVersion, Value::CreateIntegerValue(2)); 199 &manifest, keys::kManifestVersion, Value::CreateIntegerValue(2));
200 EXPECT_TRUE(manifest->HasKey(keys::kCommands)); 200 EXPECT_TRUE(manifest->HasKey(keys::kCommands));
201 EXPECT_TRUE(manifest->Get(keys::kCommands, &output)); 201 EXPECT_TRUE(manifest->Get(keys::kCommands, &output));
202 }; 202 };
203 203
204 } // namespace extensions 204 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_tests/extension_manifests_manifest_version_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698