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

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

Issue 12042096: Move page action manifest parsing out of Extension; the first multi-key manifest handler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/extension_l10n_util.h" 14 #include "chrome/common/extensions/extension_l10n_util.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 16
17 using extensions::Extension; 17 using extensions::Extension;
18 18
19 ExtensionManifestTest::ExtensionManifestTest() 19 namespace {
20 : enable_apps_(true),
21 // UNKNOWN == trunk.
22 current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
23 20
24 // static 21 // If filename is a relative path, LoadManifestFile will treat it relative to
25 DictionaryValue* ExtensionManifestTest::LoadManifestFile( 22 // the appropriate test directory.
26 const std::string& filename, 23 DictionaryValue* LoadManifestFile(
27 std::string* error) { 24 const FilePath& filename_path, std::string* error) {
28 FilePath filename_path(FilePath::FromUTF8Unsafe(filename));
29 FilePath extension_path; 25 FilePath extension_path;
30 FilePath manifest_path; 26 FilePath manifest_path;
31 27
32 if (filename_path.IsAbsolute()) { 28 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path);
33 extension_path = filename_path.DirName(); 29 manifest_path = manifest_path.Append(filename_path);
34 manifest_path = filename_path; 30 extension_path = manifest_path.DirName();
35 } else {
36 PathService::Get(chrome::DIR_TEST_DATA, &extension_path);
37 extension_path = extension_path.AppendASCII("extensions")
38 .AppendASCII("manifest_tests");
39 manifest_path = extension_path.AppendASCII(filename.c_str());
40 }
41 31
42 EXPECT_TRUE(file_util::PathExists(manifest_path)) << 32 EXPECT_TRUE(file_util::PathExists(manifest_path)) <<
43 "Couldn't find " << manifest_path.value(); 33 "Couldn't find " << manifest_path.value();
44 34
45 JSONFileValueSerializer serializer(manifest_path); 35 JSONFileValueSerializer serializer(manifest_path);
46 DictionaryValue* manifest = 36 DictionaryValue* manifest =
47 static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); 37 static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
48 38
49 // Most unit tests don't need localization, and they'll fail if we try to 39 // Most unit tests don't need localization, and they'll fail if we try to
50 // localize them, since their manifests don't have a default_locale key. 40 // localize them, since their manifests don't have a default_locale key.
51 // Only localize manifests that indicate they want to be localized. 41 // Only localize manifests that indicate they want to be localized.
52 // Calling LocalizeExtension at this point mirrors 42 // Calling LocalizeExtension at this point mirrors
53 // extension_file_util::LoadExtension. 43 // extension_file_util::LoadExtension.
54 if (manifest && filename.find("localized") != std::string::npos) 44 if (manifest && filename_path.value().find("localized") != std::string::npos)
55 extension_l10n_util::LocalizeExtension(extension_path, manifest, error); 45 extension_l10n_util::LocalizeExtension(extension_path, manifest, error);
56 46
57 return manifest; 47 return manifest;
58 } 48 }
59 49
50 } // namespace
51
52 ExtensionManifestTest::ExtensionManifestTest()
53 : enable_apps_(true),
54 // UNKNOWN == trunk.
55 current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
56
60 // Helper class that simplifies creating methods that take either a filename 57 // Helper class that simplifies creating methods that take either a filename
61 // to a manifest or the manifest itself. 58 // to a manifest or the manifest itself.
62 ExtensionManifestTest::Manifest::Manifest(const char* name) 59 ExtensionManifestTest::Manifest::Manifest(const char* name)
63 : name_(name), manifest_(NULL) { 60 : name_(name), manifest_(NULL) {
64 } 61 }
65 62
66 ExtensionManifestTest::Manifest::Manifest(DictionaryValue* manifest, 63 ExtensionManifestTest::Manifest::Manifest(DictionaryValue* manifest,
67 const char* name) 64 const char* name)
68 : name_(name), manifest_(manifest) { 65 : name_(name), manifest_(manifest) {
69 CHECK(manifest_) << "Manifest NULL"; 66 CHECK(manifest_) << "Manifest NULL";
70 } 67 }
71 68
72 ExtensionManifestTest::Manifest::Manifest(const Manifest& m) { 69 ExtensionManifestTest::Manifest::Manifest(const Manifest& m) {
73 NOTREACHED(); 70 NOTREACHED();
74 } 71 }
75 72
76 ExtensionManifestTest::Manifest::~Manifest() { 73 ExtensionManifestTest::Manifest::~Manifest() {
77 } 74 }
78 75
79 DictionaryValue* ExtensionManifestTest::Manifest::GetManifest( 76 DictionaryValue* ExtensionManifestTest::Manifest::GetManifest(
80 std::string* error) const { 77 char const* test_data_dir, std::string* error) const {
81 if (manifest_) 78 if (manifest_)
82 return manifest_; 79 return manifest_;
83 80
84 manifest_ = LoadManifestFile(name_, error); 81 FilePath filename_path;
82 filename_path = filename_path.AppendASCII("extensions")
83 .AppendASCII(test_data_dir)
84 .AppendASCII(name_);
85 manifest_ = LoadManifestFile(filename_path, error);
85 manifest_holder_.reset(manifest_); 86 manifest_holder_.reset(manifest_);
86 return manifest_; 87 return manifest_;
87 } 88 }
88 89
90 scoped_ptr<DictionaryValue> ExtensionManifestTest::LoadManifest(
91 char const* manifest_name, std::string* error) {
92 FilePath filename_path;
93 filename_path = filename_path.AppendASCII("extensions")
94 .AppendASCII(test_data_dir())
95 .AppendASCII(manifest_name);
96 return make_scoped_ptr(LoadManifestFile(filename_path, error));
97 }
98
89 scoped_refptr<Extension> ExtensionManifestTest::LoadExtension( 99 scoped_refptr<Extension> ExtensionManifestTest::LoadExtension(
90 const Manifest& manifest, 100 const Manifest& manifest,
91 std::string* error, 101 std::string* error,
92 Extension::Location location, 102 Extension::Location location,
93 int flags) { 103 int flags) {
94 DictionaryValue* value = manifest.GetManifest(error); 104 DictionaryValue* value = manifest.GetManifest(test_data_dir(), error);
95 if (!value) 105 if (!value)
96 return NULL; 106 return NULL;
97 FilePath path; 107 FilePath path;
98 PathService::Get(chrome::DIR_TEST_DATA, &path); 108 PathService::Get(chrome::DIR_TEST_DATA, &path);
99 path = path.AppendASCII("extensions").AppendASCII("manifest_tests"); 109 path = path.AppendASCII("extensions").AppendASCII(test_data_dir());
100 return Extension::Create(path.DirName(), location, *value, flags, error); 110 return Extension::Create(path.DirName(), location, *value, flags, error);
101 } 111 }
102 112
103 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess( 113 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess(
104 const Manifest& manifest, 114 const Manifest& manifest,
105 Extension::Location location, 115 Extension::Location location,
106 int flags) { 116 int flags) {
107 std::string error; 117 std::string error;
108 scoped_refptr<Extension> extension = 118 scoped_refptr<Extension> extension =
109 LoadExtension(manifest, &error, location, flags); 119 LoadExtension(manifest, &error, location, flags);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 break; 247 break;
238 case EXPECT_TYPE_SUCCESS: 248 case EXPECT_TYPE_SUCCESS:
239 for (size_t i = 0; i < num_testcases; ++i) { 249 for (size_t i = 0; i < num_testcases; ++i) {
240 LoadAndExpectSuccess(testcases[i].manifest_filename_.c_str(), 250 LoadAndExpectSuccess(testcases[i].manifest_filename_.c_str(),
241 testcases[i].location_, 251 testcases[i].location_,
242 testcases[i].flags_); 252 testcases[i].flags_);
243 } 253 }
244 break; 254 break;
245 } 255 }
246 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698