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

Side by Side Diff: chrome/common/extensions/manifest_tests/extension_manifest_test.cc

Issue 178253007: Parse manifest file with app.service_worker.script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved test utils out of base Created 6 years, 9 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
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_tests/extension_manifest_test.h" 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/extensions/extension_l10n_util.h" 13 #include "chrome/common/extensions/extension_l10n_util.h"
14 #include "extensions/common/test_util.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 16
16 using extensions::Extension; 17 using extensions::Extension;
17 18
18 namespace { 19 namespace {
19 20
20 // If filename is a relative path, LoadManifestFile will treat it relative to 21 // If filename is a relative path, LoadManifestFile will treat it relative to
21 // the appropriate test directory. 22 // the appropriate test directory.
22 base::DictionaryValue* LoadManifestFile(const base::FilePath& filename_path, 23 base::DictionaryValue* LoadManifestFile(const base::FilePath& filename_path,
23 std::string* error) { 24 std::string* error) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 ExtensionManifestTest::Manifest::Manifest(const char* name) 61 ExtensionManifestTest::Manifest::Manifest(const char* name)
61 : name_(name), manifest_(NULL) { 62 : name_(name), manifest_(NULL) {
62 } 63 }
63 64
64 ExtensionManifestTest::Manifest::Manifest(base::DictionaryValue* manifest, 65 ExtensionManifestTest::Manifest::Manifest(base::DictionaryValue* manifest,
65 const char* name) 66 const char* name)
66 : name_(name), manifest_(manifest) { 67 : name_(name), manifest_(manifest) {
67 CHECK(manifest_) << "Manifest NULL"; 68 CHECK(manifest_) << "Manifest NULL";
68 } 69 }
69 70
71 ExtensionManifestTest::Manifest::Manifest(
72 scoped_ptr<base::DictionaryValue> manifest)
73 : manifest_(manifest.get()), manifest_holder_(manifest.Pass()) {
74 CHECK(manifest_) << "Manifest NULL";
75 }
76
70 ExtensionManifestTest::Manifest::Manifest(const Manifest& m) { 77 ExtensionManifestTest::Manifest::Manifest(const Manifest& m) {
71 NOTREACHED(); 78 NOTREACHED();
72 } 79 }
73 80
74 ExtensionManifestTest::Manifest::~Manifest() { 81 ExtensionManifestTest::Manifest::~Manifest() {
75 } 82 }
76 83
77 base::DictionaryValue* ExtensionManifestTest::Manifest::GetManifest( 84 base::DictionaryValue* ExtensionManifestTest::Manifest::GetManifest(
78 char const* test_data_dir, std::string* error) const { 85 char const* test_data_dir, std::string* error) const {
79 if (manifest_) 86 if (manifest_)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return extension; 134 return extension;
128 } 135 }
129 136
130 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess( 137 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess(
131 char const* manifest_name, 138 char const* manifest_name,
132 extensions::Manifest::Location location, 139 extensions::Manifest::Location location,
133 int flags) { 140 int flags) {
134 return LoadAndExpectSuccess(Manifest(manifest_name), location, flags); 141 return LoadAndExpectSuccess(Manifest(manifest_name), location, flags);
135 } 142 }
136 143
144 scoped_refptr<Extension> ExtensionManifestTest::LoadFromStringAndExpectSuccess(
145 char const* manifest_json) {
146 return LoadAndExpectSuccess(
147 Manifest(extensions::test_util::ParseJsonDictionaryWithSingleQuotes(
148 manifest_json)));
149 }
150
137 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning( 151 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning(
138 const Manifest& manifest, 152 const Manifest& manifest,
139 const std::string& expected_warning, 153 const std::string& expected_warning,
140 extensions::Manifest::Location location, 154 extensions::Manifest::Location location,
141 int flags) { 155 int flags) {
142 std::string error; 156 std::string error;
143 scoped_refptr<Extension> extension = 157 scoped_refptr<Extension> extension =
144 LoadExtension(manifest, &error, location, flags); 158 LoadExtension(manifest, &error, location, flags);
145 EXPECT_TRUE(extension.get()) << manifest.name(); 159 EXPECT_TRUE(extension.get()) << manifest.name();
146 EXPECT_EQ("", error) << manifest.name(); 160 EXPECT_EQ("", error) << manifest.name();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 198
185 void ExtensionManifestTest::LoadAndExpectError( 199 void ExtensionManifestTest::LoadAndExpectError(
186 char const* manifest_name, 200 char const* manifest_name,
187 const std::string& expected_error, 201 const std::string& expected_error,
188 extensions::Manifest::Location location, 202 extensions::Manifest::Location location,
189 int flags) { 203 int flags) {
190 return LoadAndExpectError( 204 return LoadAndExpectError(
191 Manifest(manifest_name), expected_error, location, flags); 205 Manifest(manifest_name), expected_error, location, flags);
192 } 206 }
193 207
208 void ExtensionManifestTest::LoadFromStringAndExpectError(
209 char const* manifest_json,
210 const std::string& expected_error) {
211 return LoadAndExpectError(
212 Manifest(extensions::test_util::ParseJsonDictionaryWithSingleQuotes(
213 manifest_json)),
214 expected_error);
215 }
216
194 void ExtensionManifestTest::AddPattern(extensions::URLPatternSet* extent, 217 void ExtensionManifestTest::AddPattern(extensions::URLPatternSet* extent,
195 const std::string& pattern) { 218 const std::string& pattern) {
196 int schemes = URLPattern::SCHEME_ALL; 219 int schemes = URLPattern::SCHEME_ALL;
197 extent->AddPattern(URLPattern(schemes, pattern)); 220 extent->AddPattern(URLPattern(schemes, pattern));
198 } 221 }
199 222
200 ExtensionManifestTest::Testcase::Testcase( 223 ExtensionManifestTest::Testcase::Testcase(
201 std::string manifest_filename, 224 std::string manifest_filename,
202 std::string expected_error, 225 std::string expected_error,
203 extensions::Manifest::Location location, 226 extensions::Manifest::Location location,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 testcase.location_, 273 testcase.location_,
251 testcase.flags_); 274 testcase.flags_);
252 break; 275 break;
253 case EXPECT_TYPE_SUCCESS: 276 case EXPECT_TYPE_SUCCESS:
254 LoadAndExpectSuccess(testcase.manifest_filename_.c_str(), 277 LoadAndExpectSuccess(testcase.manifest_filename_.c_str(),
255 testcase.location_, 278 testcase.location_,
256 testcase.flags_); 279 testcase.flags_);
257 break; 280 break;
258 } 281 }
259 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698