| OLD | NEW |
| 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_test.h" | 5 #include "extensions/common/manifest_test.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/pattern.h" | 13 #include "base/strings/pattern.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "extensions/common/extension_l10n_util.h" | 16 #include "extensions/common/extension_l10n_util.h" |
| 17 #include "extensions/common/extension_paths.h" | 17 #include "extensions/common/extension_paths.h" |
| 18 #include "extensions/common/test_util.h" | 18 #include "extensions/common/test_util.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // |manifest_path| is an absolute path to a manifest file. | 24 // |manifest_path| is an absolute path to a manifest file. |
| 25 scoped_ptr<base::DictionaryValue> LoadManifestFile( | 25 std::unique_ptr<base::DictionaryValue> LoadManifestFile( |
| 26 const base::FilePath& manifest_path, | 26 const base::FilePath& manifest_path, |
| 27 std::string* error) { | 27 std::string* error) { |
| 28 base::FilePath extension_path = manifest_path.DirName(); | 28 base::FilePath extension_path = manifest_path.DirName(); |
| 29 | 29 |
| 30 EXPECT_TRUE(base::PathExists(manifest_path)) << | 30 EXPECT_TRUE(base::PathExists(manifest_path)) << |
| 31 "Couldn't find " << manifest_path.value(); | 31 "Couldn't find " << manifest_path.value(); |
| 32 | 32 |
| 33 JSONFileValueDeserializer deserializer(manifest_path); | 33 JSONFileValueDeserializer deserializer(manifest_path); |
| 34 scoped_ptr<base::DictionaryValue> manifest = | 34 std::unique_ptr<base::DictionaryValue> manifest = |
| 35 base::DictionaryValue::From(deserializer.Deserialize(NULL, error)); | 35 base::DictionaryValue::From(deserializer.Deserialize(NULL, error)); |
| 36 | 36 |
| 37 // Most unit tests don't need localization, and they'll fail if we try to | 37 // Most unit tests don't need localization, and they'll fail if we try to |
| 38 // localize them, since their manifests don't have a default_locale key. | 38 // localize them, since their manifests don't have a default_locale key. |
| 39 // Only localize manifests that indicate they want to be localized. | 39 // Only localize manifests that indicate they want to be localized. |
| 40 // Calling LocalizeExtension at this point mirrors file_util::LoadExtension. | 40 // Calling LocalizeExtension at this point mirrors file_util::LoadExtension. |
| 41 if (manifest && | 41 if (manifest && |
| 42 manifest_path.value().find(FILE_PATH_LITERAL("localized")) != | 42 manifest_path.value().find(FILE_PATH_LITERAL("localized")) != |
| 43 std::string::npos) | 43 std::string::npos) |
| 44 extension_l10n_util::LocalizeExtension(extension_path, manifest.get(), | 44 extension_l10n_util::LocalizeExtension(extension_path, manifest.get(), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 62 : name_(name), manifest_(nullptr) {} | 62 : name_(name), manifest_(nullptr) {} |
| 63 | 63 |
| 64 // This does not take ownership of |manifest|. | 64 // This does not take ownership of |manifest|. |
| 65 ManifestTest::ManifestData::ManifestData(base::DictionaryValue* manifest, | 65 ManifestTest::ManifestData::ManifestData(base::DictionaryValue* manifest, |
| 66 const char* name) | 66 const char* name) |
| 67 : name_(name), manifest_(manifest) { | 67 : name_(name), manifest_(manifest) { |
| 68 CHECK(manifest_) << "Manifest NULL"; | 68 CHECK(manifest_) << "Manifest NULL"; |
| 69 } | 69 } |
| 70 | 70 |
| 71 ManifestTest::ManifestData::ManifestData( | 71 ManifestTest::ManifestData::ManifestData( |
| 72 scoped_ptr<base::DictionaryValue> manifest) | 72 std::unique_ptr<base::DictionaryValue> manifest) |
| 73 : manifest_(manifest.get()), manifest_holder_(std::move(manifest)) { | 73 : manifest_(manifest.get()), manifest_holder_(std::move(manifest)) { |
| 74 CHECK(manifest_) << "Manifest NULL"; | 74 CHECK(manifest_) << "Manifest NULL"; |
| 75 } | 75 } |
| 76 | 76 |
| 77 ManifestTest::ManifestData::ManifestData( | 77 ManifestTest::ManifestData::ManifestData( |
| 78 scoped_ptr<base::DictionaryValue> manifest, | 78 std::unique_ptr<base::DictionaryValue> manifest, |
| 79 const char* name) | 79 const char* name) |
| 80 : name_(name), | 80 : name_(name), |
| 81 manifest_(manifest.get()), | 81 manifest_(manifest.get()), |
| 82 manifest_holder_(std::move(manifest)) { | 82 manifest_holder_(std::move(manifest)) { |
| 83 CHECK(manifest_) << "Manifest NULL"; | 83 CHECK(manifest_) << "Manifest NULL"; |
| 84 } | 84 } |
| 85 | 85 |
| 86 ManifestTest::ManifestData::ManifestData(const ManifestData& m) { | 86 ManifestTest::ManifestData::ManifestData(const ManifestData& m) { |
| 87 NOTREACHED(); | 87 NOTREACHED(); |
| 88 } | 88 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 std::string ManifestTest::GetTestExtensionID() const { | 104 std::string ManifestTest::GetTestExtensionID() const { |
| 105 return std::string(); | 105 return std::string(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 base::FilePath ManifestTest::GetTestDataDir() { | 108 base::FilePath ManifestTest::GetTestDataDir() { |
| 109 base::FilePath path; | 109 base::FilePath path; |
| 110 PathService::Get(DIR_TEST_DATA, &path); | 110 PathService::Get(DIR_TEST_DATA, &path); |
| 111 return path.AppendASCII("manifest_tests"); | 111 return path.AppendASCII("manifest_tests"); |
| 112 } | 112 } |
| 113 | 113 |
| 114 scoped_ptr<base::DictionaryValue> ManifestTest::LoadManifest( | 114 std::unique_ptr<base::DictionaryValue> ManifestTest::LoadManifest( |
| 115 char const* manifest_name, std::string* error) { | 115 char const* manifest_name, |
| 116 std::string* error) { |
| 116 base::FilePath manifest_path = GetTestDataDir().AppendASCII(manifest_name); | 117 base::FilePath manifest_path = GetTestDataDir().AppendASCII(manifest_name); |
| 117 return LoadManifestFile(manifest_path, error); | 118 return LoadManifestFile(manifest_path, error); |
| 118 } | 119 } |
| 119 | 120 |
| 120 scoped_refptr<Extension> ManifestTest::LoadExtension( | 121 scoped_refptr<Extension> ManifestTest::LoadExtension( |
| 121 const ManifestData& manifest, | 122 const ManifestData& manifest, |
| 122 std::string* error, | 123 std::string* error, |
| 123 extensions::Manifest::Location location, | 124 extensions::Manifest::Location location, |
| 124 int flags) { | 125 int flags) { |
| 125 base::FilePath test_data_dir = GetTestDataDir(); | 126 base::FilePath test_data_dir = GetTestDataDir(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 break; | 266 break; |
| 266 case EXPECT_TYPE_SUCCESS: | 267 case EXPECT_TYPE_SUCCESS: |
| 267 LoadAndExpectSuccess(testcase.manifest_filename_.c_str(), | 268 LoadAndExpectSuccess(testcase.manifest_filename_.c_str(), |
| 268 testcase.location_, | 269 testcase.location_, |
| 269 testcase.flags_); | 270 testcase.flags_); |
| 270 break; | 271 break; |
| 271 } | 272 } |
| 272 } | 273 } |
| 273 | 274 |
| 274 } // namespace extensions | 275 } // namespace extensions |
| OLD | NEW |