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

Side by Side Diff: chrome/common/extensions/manifest_handlers/settings_overrides_handler_unittest.cc

Issue 1880143002: Convert chrome/common to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_handlers/settings_overrides_handler. h" 5 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler. h"
6 6
7 #include <memory>
8
7 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 11 #include "build/build_config.h"
10 #include "extensions/common/error_utils.h" 12 #include "extensions/common/error_utils.h"
11 #include "extensions/common/extension.h" 13 #include "extensions/common/extension.h"
12 #include "extensions/common/manifest_constants.h" 14 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/manifest_url_handlers.h" 15 #include "extensions/common/manifest_url_handlers.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace { 18 namespace {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 namespace manifest_keys = extensions::manifest_keys; 72 namespace manifest_keys = extensions::manifest_keys;
71 73
72 class OverrideSettingsTest : public testing::Test { 74 class OverrideSettingsTest : public testing::Test {
73 }; 75 };
74 76
75 77
76 TEST_F(OverrideSettingsTest, ParseManifest) { 78 TEST_F(OverrideSettingsTest, ParseManifest) {
77 std::string manifest(kManifest); 79 std::string manifest(kManifest);
78 JSONStringValueDeserializer json(manifest); 80 JSONStringValueDeserializer json(manifest);
79 std::string error; 81 std::string error;
80 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); 82 std::unique_ptr<base::Value> root(json.Deserialize(NULL, &error));
81 ASSERT_TRUE(root); 83 ASSERT_TRUE(root);
82 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); 84 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
83 scoped_refptr<Extension> extension = Extension::Create( 85 scoped_refptr<Extension> extension = Extension::Create(
84 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 86 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
85 Manifest::INVALID_LOCATION, 87 Manifest::INVALID_LOCATION,
86 *static_cast<base::DictionaryValue*>(root.get()), 88 *static_cast<base::DictionaryValue*>(root.get()),
87 Extension::NO_FLAGS, 89 Extension::NO_FLAGS,
88 &error); 90 &error);
89 ASSERT_TRUE(extension.get()); 91 ASSERT_TRUE(extension.get());
90 #if defined(OS_WIN) 92 #if defined(OS_WIN)
(...skipping 22 matching lines...) Expand all
113 #else 115 #else
114 EXPECT_FALSE( 116 EXPECT_FALSE(
115 extension->manifest()->HasPath(manifest_keys::kSettingsOverride)); 117 extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
116 #endif 118 #endif
117 } 119 }
118 120
119 TEST_F(OverrideSettingsTest, ParsePrepopulatedId) { 121 TEST_F(OverrideSettingsTest, ParsePrepopulatedId) {
120 std::string manifest(kPrepopulatedManifest); 122 std::string manifest(kPrepopulatedManifest);
121 JSONStringValueDeserializer json(manifest); 123 JSONStringValueDeserializer json(manifest);
122 std::string error; 124 std::string error;
123 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); 125 std::unique_ptr<base::Value> root(json.Deserialize(NULL, &error));
124 ASSERT_TRUE(root); 126 ASSERT_TRUE(root);
125 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); 127 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
126 scoped_refptr<Extension> extension = 128 scoped_refptr<Extension> extension =
127 Extension::Create(base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 129 Extension::Create(base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
128 Manifest::INVALID_LOCATION, 130 Manifest::INVALID_LOCATION,
129 *static_cast<base::DictionaryValue*>(root.get()), 131 *static_cast<base::DictionaryValue*>(root.get()),
130 Extension::NO_FLAGS, 132 Extension::NO_FLAGS,
131 &error); 133 &error);
132 ASSERT_TRUE(extension.get()); 134 ASSERT_TRUE(extension.get());
133 #if defined(OS_WIN) 135 #if defined(OS_WIN)
(...skipping 12 matching lines...) Expand all
146 #else 148 #else
147 EXPECT_FALSE( 149 EXPECT_FALSE(
148 extension->manifest()->HasPath(manifest_keys::kSettingsOverride)); 150 extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
149 #endif 151 #endif
150 } 152 }
151 153
152 TEST_F(OverrideSettingsTest, ParseBrokenManifest) { 154 TEST_F(OverrideSettingsTest, ParseBrokenManifest) {
153 std::string manifest(kBrokenManifest); 155 std::string manifest(kBrokenManifest);
154 JSONStringValueDeserializer json(manifest); 156 JSONStringValueDeserializer json(manifest);
155 std::string error; 157 std::string error;
156 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); 158 std::unique_ptr<base::Value> root(json.Deserialize(NULL, &error));
157 ASSERT_TRUE(root); 159 ASSERT_TRUE(root);
158 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); 160 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
159 scoped_refptr<Extension> extension = Extension::Create( 161 scoped_refptr<Extension> extension = Extension::Create(
160 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 162 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
161 Manifest::INVALID_LOCATION, 163 Manifest::INVALID_LOCATION,
162 *static_cast<base::DictionaryValue*>(root.get()), 164 *static_cast<base::DictionaryValue*>(root.get()),
163 Extension::NO_FLAGS, 165 Extension::NO_FLAGS,
164 &error); 166 &error);
165 #if defined(OS_WIN) 167 #if defined(OS_WIN)
166 EXPECT_FALSE(extension.get()); 168 EXPECT_FALSE(extension.get());
167 EXPECT_EQ( 169 EXPECT_EQ(
168 extensions::ErrorUtils::FormatErrorMessage( 170 extensions::ErrorUtils::FormatErrorMessage(
169 extensions::manifest_errors::kInvalidEmptyDictionary, 171 extensions::manifest_errors::kInvalidEmptyDictionary,
170 extensions::manifest_keys::kSettingsOverride), 172 extensions::manifest_keys::kSettingsOverride),
171 error); 173 error);
172 #else 174 #else
173 EXPECT_TRUE(extension.get()); 175 EXPECT_TRUE(extension.get());
174 EXPECT_FALSE( 176 EXPECT_FALSE(
175 extension->manifest()->HasPath(manifest_keys::kSettingsOverride)); 177 extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
176 #endif 178 #endif
177 } 179 }
178 180
179 } // namespace 181 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698