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

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

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

Powered by Google App Engine
This is Rietveld 408576698