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

Side by Side Diff: extensions/common/manifest_test.cc

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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_test.h" 5 #include "extensions/common/manifest_test.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.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/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "extensions/common/extension_l10n_util.h" 13 #include "extensions/common/extension_l10n_util.h"
14 #include "extensions/common/extension_paths.h" 14 #include "extensions/common/extension_paths.h"
15 #include "extensions/common/test_util.h" 15 #include "extensions/common/test_util.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 namespace { 19 namespace {
20 20
21 // |manifest_path| is an absolute path to a manifest file. 21 // |manifest_path| is an absolute path to a manifest file.
22 base::DictionaryValue* LoadManifestFile(const base::FilePath& manifest_path, 22 base::DictionaryValue* LoadManifestFile(const base::FilePath& manifest_path,
23 std::string* error) { 23 std::string* error) {
24 base::FilePath extension_path = manifest_path.DirName(); 24 base::FilePath extension_path = manifest_path.DirName();
25 25
26 EXPECT_TRUE(base::PathExists(manifest_path)) << 26 EXPECT_TRUE(base::PathExists(manifest_path)) <<
27 "Couldn't find " << manifest_path.value(); 27 "Couldn't find " << manifest_path.value();
28 28
29 JSONFileValueSerializer serializer(manifest_path); 29 JSONFileValueSerializer serializer(manifest_path);
30 base::DictionaryValue* manifest = 30 base::DictionaryValue* manifest = static_cast<base::DictionaryValue*>(
31 static_cast<base::DictionaryValue*>(serializer.Deserialize(NULL, error)); 31 serializer.Deserialize(nullptr, error));
32 32
33 // Most unit tests don't need localization, and they'll fail if we try to 33 // Most unit tests don't need localization, and they'll fail if we try to
34 // localize them, since their manifests don't have a default_locale key. 34 // localize them, since their manifests don't have a default_locale key.
35 // Only localize manifests that indicate they want to be localized. 35 // Only localize manifests that indicate they want to be localized.
36 // Calling LocalizeExtension at this point mirrors file_util::LoadExtension. 36 // Calling LocalizeExtension at this point mirrors file_util::LoadExtension.
37 if (manifest && 37 if (manifest &&
38 manifest_path.value().find(FILE_PATH_LITERAL("localized")) != 38 manifest_path.value().find(FILE_PATH_LITERAL("localized")) !=
39 std::string::npos) 39 std::string::npos)
40 extension_l10n_util::LocalizeExtension(extension_path, manifest, error); 40 extension_l10n_util::LocalizeExtension(extension_path, manifest, error);
41 41
42 return manifest; 42 return manifest;
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 ManifestTest::ManifestTest() 47 ManifestTest::ManifestTest()
48 : enable_apps_(true) { 48 : enable_apps_(true) {
49 } 49 }
50 50
51 ManifestTest::~ManifestTest() { 51 ManifestTest::~ManifestTest() {
52 } 52 }
53 53
54 // Helper class that simplifies creating methods that take either a filename 54 // Helper class that simplifies creating methods that take either a filename
55 // to a manifest or the manifest itself. 55 // to a manifest or the manifest itself.
56 ManifestTest::ManifestData::ManifestData(const char* name) 56 ManifestTest::ManifestData::ManifestData(const char* name)
57 : name_(name), manifest_(NULL) { 57 : name_(name), manifest_(nullptr) {
58 } 58 }
59 59
60 ManifestTest::ManifestData::ManifestData(base::DictionaryValue* manifest, 60 ManifestTest::ManifestData::ManifestData(base::DictionaryValue* manifest,
61 const char* name) 61 const char* name)
62 : name_(name), manifest_(manifest) { 62 : name_(name), manifest_(manifest) {
63 CHECK(manifest_) << "Manifest NULL"; 63 CHECK(manifest_) << "Manifest NULL";
64 } 64 }
65 65
66 ManifestTest::ManifestData::ManifestData( 66 ManifestTest::ManifestData::ManifestData(
67 scoped_ptr<base::DictionaryValue> manifest) 67 scoped_ptr<base::DictionaryValue> manifest)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 scoped_refptr<Extension> ManifestTest::LoadExtension( 102 scoped_refptr<Extension> ManifestTest::LoadExtension(
103 const ManifestData& manifest, 103 const ManifestData& manifest,
104 std::string* error, 104 std::string* error,
105 extensions::Manifest::Location location, 105 extensions::Manifest::Location location,
106 int flags) { 106 int flags) {
107 base::FilePath test_data_dir = GetTestDataDir(); 107 base::FilePath test_data_dir = GetTestDataDir();
108 base::DictionaryValue* value = manifest.GetManifest(test_data_dir, error); 108 base::DictionaryValue* value = manifest.GetManifest(test_data_dir, error);
109 if (!value) 109 if (!value)
110 return NULL; 110 return nullptr;
111 return Extension::Create( 111 return Extension::Create(
112 test_data_dir.DirName(), location, *value, flags, error); 112 test_data_dir.DirName(), location, *value, flags, error);
113 } 113 }
114 114
115 scoped_refptr<Extension> ManifestTest::LoadAndExpectSuccess( 115 scoped_refptr<Extension> ManifestTest::LoadAndExpectSuccess(
116 const ManifestData& manifest, 116 const ManifestData& manifest,
117 extensions::Manifest::Location location, 117 extensions::Manifest::Location location,
118 int flags) { 118 int flags) {
119 std::string error; 119 std::string error;
120 scoped_refptr<Extension> extension = 120 scoped_refptr<Extension> extension =
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 break; 249 break;
250 case EXPECT_TYPE_SUCCESS: 250 case EXPECT_TYPE_SUCCESS:
251 LoadAndExpectSuccess(testcase.manifest_filename_.c_str(), 251 LoadAndExpectSuccess(testcase.manifest_filename_.c_str(),
252 testcase.location_, 252 testcase.location_,
253 testcase.flags_); 253 testcase.flags_);
254 break; 254 break;
255 } 255 }
256 } 256 }
257 257
258 } // namespace extensions 258 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698