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

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

Issue 572813002: Refactor ExtensionManifestTest to allow usage in src/extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 "extensions/common/manifest.h" 5 #include "extensions/common/manifest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "extensions/common/error_utils.h" 14 #include "extensions/common/error_utils.h"
15 #include "extensions/common/features/feature.h" 15 #include "extensions/common/features/feature.h"
16 #include "extensions/common/features/simple_feature.h" 16 #include "extensions/common/features/simple_feature.h"
17 #include "extensions/common/install_warning.h" 17 #include "extensions/common/install_warning.h"
18 #include "extensions/common/manifest_constants.h" 18 #include "extensions/common/manifest_constants.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
23 namespace errors = manifest_errors; 23 namespace errors = manifest_errors;
24 namespace keys = manifest_keys; 24 namespace keys = manifest_keys;
25 25
26 class ManifestTest : public testing::Test { 26 // Not named "ManifestTest" because a test utility class has that name.
27 class ManifestUnitTest : public testing::Test {
27 public: 28 public:
28 ManifestTest() : default_value_("test") {} 29 ManifestUnitTest() : default_value_("test") {}
29 30
30 protected: 31 protected:
31 void AssertType(Manifest* manifest, Manifest::Type type) { 32 void AssertType(Manifest* manifest, Manifest::Type type) {
32 EXPECT_EQ(type, manifest->type()); 33 EXPECT_EQ(type, manifest->type());
33 EXPECT_EQ(type == Manifest::TYPE_THEME, manifest->is_theme()); 34 EXPECT_EQ(type == Manifest::TYPE_THEME, manifest->is_theme());
34 EXPECT_EQ(type == Manifest::TYPE_PLATFORM_APP, 35 EXPECT_EQ(type == Manifest::TYPE_PLATFORM_APP,
35 manifest->is_platform_app()); 36 manifest->is_platform_app());
36 EXPECT_EQ(type == Manifest::TYPE_LEGACY_PACKAGED_APP, 37 EXPECT_EQ(type == Manifest::TYPE_LEGACY_PACKAGED_APP,
37 manifest->is_legacy_packaged_app()); 38 manifest->is_legacy_packaged_app());
38 EXPECT_EQ(type == Manifest::TYPE_HOSTED_APP, manifest->is_hosted_app()); 39 EXPECT_EQ(type == Manifest::TYPE_HOSTED_APP, manifest->is_hosted_app());
(...skipping 13 matching lines...) Expand all
52 manifest_value->Set(key, value); 53 manifest_value->Set(key, value);
53 else 54 else
54 manifest_value->Remove(key, NULL); 55 manifest_value->Remove(key, NULL);
55 manifest->reset(new Manifest(Manifest::INTERNAL, manifest_value.Pass())); 56 manifest->reset(new Manifest(Manifest::INTERNAL, manifest_value.Pass()));
56 } 57 }
57 58
58 std::string default_value_; 59 std::string default_value_;
59 }; 60 };
60 61
61 // Verifies that extensions can access the correct keys. 62 // Verifies that extensions can access the correct keys.
62 TEST_F(ManifestTest, Extension) { 63 TEST_F(ManifestUnitTest, Extension) {
63 scoped_ptr<base::DictionaryValue> manifest_value(new base::DictionaryValue()); 64 scoped_ptr<base::DictionaryValue> manifest_value(new base::DictionaryValue());
64 manifest_value->SetString(keys::kName, "extension"); 65 manifest_value->SetString(keys::kName, "extension");
65 manifest_value->SetString(keys::kVersion, "1"); 66 manifest_value->SetString(keys::kVersion, "1");
66 // Only supported in manifest_version=1. 67 // Only supported in manifest_version=1.
67 manifest_value->SetString(keys::kBackgroundPageLegacy, "bg.html"); 68 manifest_value->SetString(keys::kBackgroundPageLegacy, "bg.html");
68 manifest_value->SetString("unknown_key", "foo"); 69 manifest_value->SetString("unknown_key", "foo");
69 70
70 scoped_ptr<Manifest> manifest( 71 scoped_ptr<Manifest> manifest(
71 new Manifest(Manifest::INTERNAL, manifest_value.Pass())); 72 new Manifest(Manifest::INTERNAL, manifest_value.Pass()));
72 std::string error; 73 std::string error;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Test DeepCopy and Equals. 111 // Test DeepCopy and Equals.
111 scoped_ptr<Manifest> manifest2(manifest->DeepCopy()); 112 scoped_ptr<Manifest> manifest2(manifest->DeepCopy());
112 EXPECT_TRUE(manifest->Equals(manifest2.get())); 113 EXPECT_TRUE(manifest->Equals(manifest2.get()));
113 EXPECT_TRUE(manifest2->Equals(manifest.get())); 114 EXPECT_TRUE(manifest2->Equals(manifest.get()));
114 MutateManifest( 115 MutateManifest(
115 &manifest, "foo", new base::StringValue("blah")); 116 &manifest, "foo", new base::StringValue("blah"));
116 EXPECT_FALSE(manifest->Equals(manifest2.get())); 117 EXPECT_FALSE(manifest->Equals(manifest2.get()));
117 } 118 }
118 119
119 // Verifies that key restriction based on type works. 120 // Verifies that key restriction based on type works.
120 TEST_F(ManifestTest, ExtensionTypes) { 121 TEST_F(ManifestUnitTest, ExtensionTypes) {
121 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 122 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
122 value->SetString(keys::kName, "extension"); 123 value->SetString(keys::kName, "extension");
123 value->SetString(keys::kVersion, "1"); 124 value->SetString(keys::kVersion, "1");
124 125
125 scoped_ptr<Manifest> manifest( 126 scoped_ptr<Manifest> manifest(
126 new Manifest(Manifest::INTERNAL, value.Pass())); 127 new Manifest(Manifest::INTERNAL, value.Pass()));
127 std::string error; 128 std::string error;
128 std::vector<InstallWarning> warnings; 129 std::vector<InstallWarning> warnings;
129 EXPECT_TRUE(manifest->ValidateManifest(&error, &warnings)); 130 EXPECT_TRUE(manifest->ValidateManifest(&error, &warnings));
130 EXPECT_TRUE(error.empty()); 131 EXPECT_TRUE(error.empty());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 MutateManifest( 167 MutateManifest(
167 &manifest, keys::kWebURLs, NULL); 168 &manifest, keys::kWebURLs, NULL);
168 MutateManifest( 169 MutateManifest(
169 &manifest, keys::kLaunchWebURL, new base::StringValue("foo")); 170 &manifest, keys::kLaunchWebURL, new base::StringValue("foo"));
170 AssertType(manifest.get(), Manifest::TYPE_HOSTED_APP); 171 AssertType(manifest.get(), Manifest::TYPE_HOSTED_APP);
171 MutateManifest( 172 MutateManifest(
172 &manifest, keys::kLaunchWebURL, NULL); 173 &manifest, keys::kLaunchWebURL, NULL);
173 }; 174 };
174 175
175 // Verifies that the getters filter restricted keys. 176 // Verifies that the getters filter restricted keys.
176 TEST_F(ManifestTest, RestrictedKeys) { 177 TEST_F(ManifestUnitTest, RestrictedKeys) {
177 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 178 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
178 value->SetString(keys::kName, "extension"); 179 value->SetString(keys::kName, "extension");
179 value->SetString(keys::kVersion, "1"); 180 value->SetString(keys::kVersion, "1");
180 181
181 scoped_ptr<Manifest> manifest( 182 scoped_ptr<Manifest> manifest(
182 new Manifest(Manifest::INTERNAL, value.Pass())); 183 new Manifest(Manifest::INTERNAL, value.Pass()));
183 std::string error; 184 std::string error;
184 std::vector<InstallWarning> warnings; 185 std::vector<InstallWarning> warnings;
185 EXPECT_TRUE(manifest->ValidateManifest(&error, &warnings)); 186 EXPECT_TRUE(manifest->ValidateManifest(&error, &warnings));
186 EXPECT_TRUE(error.empty()); 187 EXPECT_TRUE(error.empty());
(...skipping 25 matching lines...) Expand all
212 EXPECT_FALSE(manifest->Get(keys::kPageAction, &output)); 213 EXPECT_FALSE(manifest->Get(keys::kPageAction, &output));
213 MutateManifest( 214 MutateManifest(
214 &manifest, keys::kPlatformAppBackground, NULL); 215 &manifest, keys::kPlatformAppBackground, NULL);
215 216
216 // Platform apps also can't have a "Commands" key. 217 // Platform apps also can't have a "Commands" key.
217 EXPECT_FALSE(manifest->HasKey(keys::kCommands)); 218 EXPECT_FALSE(manifest->HasKey(keys::kCommands));
218 EXPECT_FALSE(manifest->Get(keys::kCommands, &output)); 219 EXPECT_FALSE(manifest->Get(keys::kCommands, &output));
219 }; 220 };
220 221
221 } // namespace extensions 222 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698