| Index: chrome/common/extensions/manifest_tests/extension_manifest_test.cc
|
| diff --git a/extensions/common/manifest_test.cc b/chrome/common/extensions/manifest_tests/extension_manifest_test.cc
|
| similarity index 61%
|
| rename from extensions/common/manifest_test.cc
|
| rename to chrome/common/extensions/manifest_tests/extension_manifest_test.cc
|
| index b1ab11551c0dc5e99593ae489918f1b96f2ec71d..c2936d84aa57f585b95fce990790582a2b70b1d1 100644
|
| --- a/extensions/common/manifest_test.cc
|
| +++ b/chrome/common/extensions/manifest_tests/extension_manifest_test.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "extensions/common/manifest_test.h"
|
| +#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
|
|
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| @@ -10,18 +10,25 @@
|
| #include "base/path_service.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/values.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| #include "extensions/common/extension_l10n_util.h"
|
| -#include "extensions/common/extension_paths.h"
|
| #include "extensions/common/test_util.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| -namespace extensions {
|
| +using extensions::Extension;
|
| +
|
| namespace {
|
|
|
| -// |manifest_path| is an absolute path to a manifest file.
|
| -base::DictionaryValue* LoadManifestFile(const base::FilePath& manifest_path,
|
| +// If filename is a relative path, LoadManifestFile will treat it relative to
|
| +// the appropriate test directory.
|
| +base::DictionaryValue* LoadManifestFile(const base::FilePath& filename_path,
|
| std::string* error) {
|
| - base::FilePath extension_path = manifest_path.DirName();
|
| + base::FilePath extension_path;
|
| + base::FilePath manifest_path;
|
| +
|
| + PathService::Get(chrome::DIR_TEST_DATA, &manifest_path);
|
| + manifest_path = manifest_path.Append(filename_path);
|
| + extension_path = manifest_path.DirName();
|
|
|
| EXPECT_TRUE(base::PathExists(manifest_path)) <<
|
| "Couldn't find " << manifest_path.value();
|
| @@ -35,7 +42,7 @@ base::DictionaryValue* LoadManifestFile(const base::FilePath& manifest_path,
|
| // Only localize manifests that indicate they want to be localized.
|
| // Calling LocalizeExtension at this point mirrors file_util::LoadExtension.
|
| if (manifest &&
|
| - manifest_path.value().find(FILE_PATH_LITERAL("localized")) !=
|
| + filename_path.value().find(FILE_PATH_LITERAL("localized")) !=
|
| std::string::npos)
|
| extension_l10n_util::LocalizeExtension(extension_path, manifest, error);
|
|
|
| @@ -44,76 +51,79 @@ base::DictionaryValue* LoadManifestFile(const base::FilePath& manifest_path,
|
|
|
| } // namespace
|
|
|
| -ManifestTest::ManifestTest()
|
| - : enable_apps_(true) {
|
| -}
|
| -
|
| -ManifestTest::~ManifestTest() {
|
| -}
|
| +ExtensionManifestTest::ExtensionManifestTest()
|
| + : enable_apps_(true),
|
| + // UNKNOWN == trunk.
|
| + current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
|
|
|
| // Helper class that simplifies creating methods that take either a filename
|
| // to a manifest or the manifest itself.
|
| -ManifestTest::ManifestData::ManifestData(const char* name)
|
| +ExtensionManifestTest::Manifest::Manifest(const char* name)
|
| : name_(name), manifest_(NULL) {
|
| }
|
|
|
| -ManifestTest::ManifestData::ManifestData(base::DictionaryValue* manifest,
|
| +ExtensionManifestTest::Manifest::Manifest(base::DictionaryValue* manifest,
|
| const char* name)
|
| : name_(name), manifest_(manifest) {
|
| CHECK(manifest_) << "Manifest NULL";
|
| }
|
|
|
| -ManifestTest::ManifestData::ManifestData(
|
| +ExtensionManifestTest::Manifest::Manifest(
|
| scoped_ptr<base::DictionaryValue> manifest)
|
| : manifest_(manifest.get()), manifest_holder_(manifest.Pass()) {
|
| CHECK(manifest_) << "Manifest NULL";
|
| }
|
|
|
| -ManifestTest::ManifestData::ManifestData(const ManifestData& m) {
|
| +ExtensionManifestTest::Manifest::Manifest(const Manifest& m) {
|
| NOTREACHED();
|
| }
|
|
|
| -ManifestTest::ManifestData::~ManifestData() {
|
| +ExtensionManifestTest::Manifest::~Manifest() {
|
| }
|
|
|
| -base::DictionaryValue* ManifestTest::ManifestData::GetManifest(
|
| - base::FilePath test_data_dir, std::string* error) const {
|
| +base::DictionaryValue* ExtensionManifestTest::Manifest::GetManifest(
|
| + char const* test_data_dir, std::string* error) const {
|
| if (manifest_)
|
| return manifest_;
|
|
|
| - base::FilePath manifest_path = test_data_dir.AppendASCII(name_);
|
| - manifest_ = LoadManifestFile(manifest_path, error);
|
| + base::FilePath filename_path;
|
| + filename_path = filename_path.AppendASCII("extensions")
|
| + .AppendASCII(test_data_dir)
|
| + .AppendASCII(name_);
|
| + manifest_ = LoadManifestFile(filename_path, error);
|
| manifest_holder_.reset(manifest_);
|
| return manifest_;
|
| }
|
|
|
| -base::FilePath ManifestTest::GetTestDataDir() {
|
| - base::FilePath path;
|
| - PathService::Get(DIR_TEST_DATA, &path);
|
| - return path.AppendASCII("manifest_tests");
|
| +char const* ExtensionManifestTest::test_data_dir() {
|
| + return "manifest_tests";
|
| }
|
|
|
| -scoped_ptr<base::DictionaryValue> ManifestTest::LoadManifest(
|
| +scoped_ptr<base::DictionaryValue> ExtensionManifestTest::LoadManifest(
|
| char const* manifest_name, std::string* error) {
|
| - base::FilePath manifest_path = GetTestDataDir().AppendASCII(manifest_name);
|
| - return make_scoped_ptr(LoadManifestFile(manifest_path, error));
|
| + base::FilePath filename_path;
|
| + filename_path = filename_path.AppendASCII("extensions")
|
| + .AppendASCII(test_data_dir())
|
| + .AppendASCII(manifest_name);
|
| + return make_scoped_ptr(LoadManifestFile(filename_path, error));
|
| }
|
|
|
| -scoped_refptr<Extension> ManifestTest::LoadExtension(
|
| - const ManifestData& manifest,
|
| +scoped_refptr<Extension> ExtensionManifestTest::LoadExtension(
|
| + const Manifest& manifest,
|
| std::string* error,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| - base::FilePath test_data_dir = GetTestDataDir();
|
| - base::DictionaryValue* value = manifest.GetManifest(test_data_dir, error);
|
| + base::DictionaryValue* value = manifest.GetManifest(test_data_dir(), error);
|
| if (!value)
|
| return NULL;
|
| - return Extension::Create(
|
| - test_data_dir.DirName(), location, *value, flags, error);
|
| + base::FilePath path;
|
| + PathService::Get(chrome::DIR_TEST_DATA, &path);
|
| + path = path.AppendASCII("extensions").AppendASCII(test_data_dir());
|
| + return Extension::Create(path.DirName(), location, *value, flags, error);
|
| }
|
|
|
| -scoped_refptr<Extension> ManifestTest::LoadAndExpectSuccess(
|
| - const ManifestData& manifest,
|
| +scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess(
|
| + const Manifest& manifest,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| std::string error;
|
| @@ -124,15 +134,22 @@ scoped_refptr<Extension> ManifestTest::LoadAndExpectSuccess(
|
| return extension;
|
| }
|
|
|
| -scoped_refptr<Extension> ManifestTest::LoadAndExpectSuccess(
|
| +scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess(
|
| char const* manifest_name,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| - return LoadAndExpectSuccess(ManifestData(manifest_name), location, flags);
|
| + return LoadAndExpectSuccess(Manifest(manifest_name), location, flags);
|
| }
|
|
|
| -scoped_refptr<Extension> ManifestTest::LoadAndExpectWarning(
|
| - const ManifestData& manifest,
|
| +scoped_refptr<Extension> ExtensionManifestTest::LoadFromStringAndExpectSuccess(
|
| + char const* manifest_json) {
|
| + return LoadAndExpectSuccess(
|
| + Manifest(extensions::test_util::ParseJsonDictionaryWithSingleQuotes(
|
| + manifest_json)));
|
| +}
|
| +
|
| +scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning(
|
| + const Manifest& manifest,
|
| const std::string& expected_warning,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| @@ -146,16 +163,16 @@ scoped_refptr<Extension> ManifestTest::LoadAndExpectWarning(
|
| return extension;
|
| }
|
|
|
| -scoped_refptr<Extension> ManifestTest::LoadAndExpectWarning(
|
| +scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning(
|
| char const* manifest_name,
|
| const std::string& expected_warning,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| return LoadAndExpectWarning(
|
| - ManifestData(manifest_name), expected_warning, location, flags);
|
| + Manifest(manifest_name), expected_warning, location, flags);
|
| }
|
|
|
| -void ManifestTest::VerifyExpectedError(
|
| +void ExtensionManifestTest::VerifyExpectedError(
|
| Extension* extension,
|
| const std::string& name,
|
| const std::string& error,
|
| @@ -167,8 +184,8 @@ void ManifestTest::VerifyExpectedError(
|
| " expected '" << expected_error << "' but got '" << error << "'";
|
| }
|
|
|
| -void ManifestTest::LoadAndExpectError(
|
| - const ManifestData& manifest,
|
| +void ExtensionManifestTest::LoadAndExpectError(
|
| + const Manifest& manifest,
|
| const std::string& expected_error,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| @@ -179,22 +196,31 @@ void ManifestTest::LoadAndExpectError(
|
| expected_error);
|
| }
|
|
|
| -void ManifestTest::LoadAndExpectError(
|
| +void ExtensionManifestTest::LoadAndExpectError(
|
| char const* manifest_name,
|
| const std::string& expected_error,
|
| extensions::Manifest::Location location,
|
| int flags) {
|
| return LoadAndExpectError(
|
| - ManifestData(manifest_name), expected_error, location, flags);
|
| + Manifest(manifest_name), expected_error, location, flags);
|
| }
|
|
|
| -void ManifestTest::AddPattern(extensions::URLPatternSet* extent,
|
| +void ExtensionManifestTest::LoadFromStringAndExpectError(
|
| + char const* manifest_json,
|
| + const std::string& expected_error) {
|
| + return LoadAndExpectError(
|
| + Manifest(extensions::test_util::ParseJsonDictionaryWithSingleQuotes(
|
| + manifest_json)),
|
| + expected_error);
|
| +}
|
| +
|
| +void ExtensionManifestTest::AddPattern(extensions::URLPatternSet* extent,
|
| const std::string& pattern) {
|
| int schemes = URLPattern::SCHEME_ALL;
|
| extent->AddPattern(URLPattern(schemes, pattern));
|
| }
|
|
|
| -ManifestTest::Testcase::Testcase(
|
| +ExtensionManifestTest::Testcase::Testcase(
|
| std::string manifest_filename,
|
| std::string expected_error,
|
| extensions::Manifest::Location location,
|
| @@ -204,7 +230,7 @@ ManifestTest::Testcase::Testcase(
|
| location_(location), flags_(flags) {
|
| }
|
|
|
| -ManifestTest::Testcase::Testcase(std::string manifest_filename,
|
| +ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename,
|
| std::string expected_error)
|
| : manifest_filename_(manifest_filename),
|
| expected_error_(expected_error),
|
| @@ -212,12 +238,12 @@ ManifestTest::Testcase::Testcase(std::string manifest_filename,
|
| flags_(Extension::NO_FLAGS) {
|
| }
|
|
|
| -ManifestTest::Testcase::Testcase(std::string manifest_filename)
|
| +ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename)
|
| : manifest_filename_(manifest_filename),
|
| location_(extensions::Manifest::INTERNAL),
|
| flags_(Extension::NO_FLAGS) {}
|
|
|
| -ManifestTest::Testcase::Testcase(
|
| +ExtensionManifestTest::Testcase::Testcase(
|
| std::string manifest_filename,
|
| extensions::Manifest::Location location,
|
| int flags)
|
| @@ -225,14 +251,14 @@ ManifestTest::Testcase::Testcase(
|
| location_(location),
|
| flags_(flags) {}
|
|
|
| -void ManifestTest::RunTestcases(const Testcase* testcases,
|
| +void ExtensionManifestTest::RunTestcases(const Testcase* testcases,
|
| size_t num_testcases,
|
| ExpectType type) {
|
| for (size_t i = 0; i < num_testcases; ++i)
|
| RunTestcase(testcases[i], type);
|
| }
|
|
|
| -void ManifestTest::RunTestcase(const Testcase& testcase,
|
| +void ExtensionManifestTest::RunTestcase(const Testcase& testcase,
|
| ExpectType type) {
|
| switch (type) {
|
| case EXPECT_TYPE_ERROR:
|
| @@ -254,5 +280,3 @@ void ManifestTest::RunTestcase(const Testcase& testcase,
|
| break;
|
| }
|
| }
|
| -
|
| -} // namespace extensions
|
|
|