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

Side by Side Diff: chrome/browser/extensions/component_loader_unittest.cc

Issue 2504333003: Fix DictionaryValue leak in component_loader.cc (Closed)
Patch Set: address comments + rewrite all loops Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/extensions/component_loader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/extensions/component_loader.h" 5 #include "chrome/browser/extensions/component_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 base::FilePath test_data_dir; 127 base::FilePath test_data_dir;
128 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 128 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
129 return test_data_dir.AppendASCII("extensions"); 129 return test_data_dir.AppendASCII("extensions");
130 } 130 }
131 }; 131 };
132 132
133 TEST_F(ComponentLoaderTest, ParseManifest) { 133 TEST_F(ComponentLoaderTest, ParseManifest) {
134 std::unique_ptr<base::DictionaryValue> manifest; 134 std::unique_ptr<base::DictionaryValue> manifest;
135 135
136 // Test invalid JSON. 136 // Test invalid JSON.
137 manifest.reset( 137 manifest = component_loader_.ParseManifest("{ 'test': 3 } invalid");
138 component_loader_.ParseManifest("{ 'test': 3 } invalid")); 138 EXPECT_FALSE(manifest);
139 EXPECT_FALSE(manifest.get());
140 139
141 // Test manifests that are valid JSON, but don't have an object literal 140 // Test manifests that are valid JSON, but don't have an object literal
142 // at the root. ParseManifest() should always return NULL. 141 // at the root. ParseManifest() should always return NULL.
143 142
144 manifest.reset(component_loader_.ParseManifest(std::string())); 143 manifest = component_loader_.ParseManifest(std::string());
145 EXPECT_FALSE(manifest.get()); 144 EXPECT_FALSE(manifest);
146 145
147 manifest.reset(component_loader_.ParseManifest("[{ \"foo\": 3 }]")); 146 manifest = component_loader_.ParseManifest("[{ \"foo\": 3 }]");
148 EXPECT_FALSE(manifest.get()); 147 EXPECT_FALSE(manifest);
149 148
150 manifest.reset(component_loader_.ParseManifest("\"Test\"")); 149 manifest = component_loader_.ParseManifest("\"Test\"");
151 EXPECT_FALSE(manifest.get()); 150 EXPECT_FALSE(manifest);
152 151
153 manifest.reset(component_loader_.ParseManifest("42")); 152 manifest = component_loader_.ParseManifest("42");
154 EXPECT_FALSE(manifest.get()); 153 EXPECT_FALSE(manifest);
155 154
156 manifest.reset(component_loader_.ParseManifest("true")); 155 manifest = component_loader_.ParseManifest("true");
157 EXPECT_FALSE(manifest.get()); 156 EXPECT_FALSE(manifest);
158 157
159 manifest.reset(component_loader_.ParseManifest("false")); 158 manifest = component_loader_.ParseManifest("false");
160 EXPECT_FALSE(manifest.get()); 159 EXPECT_FALSE(manifest);
161 160
162 manifest.reset(component_loader_.ParseManifest("null")); 161 manifest = component_loader_.ParseManifest("null");
163 EXPECT_FALSE(manifest.get()); 162 EXPECT_FALSE(manifest);
164 163
165 // Test parsing valid JSON. 164 // Test parsing valid JSON.
166 165
167 int value = 0; 166 int value = 0;
168 manifest.reset(component_loader_.ParseManifest( 167 manifest = component_loader_.ParseManifest(
169 "{ \"test\": { \"one\": 1 }, \"two\": 2 }")); 168 "{ \"test\": { \"one\": 1 }, \"two\": 2 }");
170 ASSERT_TRUE(manifest.get()); 169 ASSERT_TRUE(manifest);
171 EXPECT_TRUE(manifest->GetInteger("test.one", &value)); 170 EXPECT_TRUE(manifest->GetInteger("test.one", &value));
172 EXPECT_EQ(1, value); 171 EXPECT_EQ(1, value);
173 ASSERT_TRUE(manifest->GetInteger("two", &value)); 172 ASSERT_TRUE(manifest->GetInteger("two", &value));
174 EXPECT_EQ(2, value); 173 EXPECT_EQ(2, value);
175 174
176 std::string string_value; 175 std::string string_value;
177 manifest.reset(component_loader_.ParseManifest(manifest_contents_)); 176 manifest = component_loader_.ParseManifest(manifest_contents_);
178 ASSERT_TRUE(manifest->GetString("background.page", &string_value)); 177 ASSERT_TRUE(manifest->GetString("background.page", &string_value));
179 EXPECT_EQ("backgroundpage.html", string_value); 178 EXPECT_EQ("backgroundpage.html", string_value);
180 } 179 }
181 180
182 // Test that the extension isn't loaded if the extension service isn't ready. 181 // Test that the extension isn't loaded if the extension service isn't ready.
183 TEST_F(ComponentLoaderTest, AddWhenNotReady) { 182 TEST_F(ComponentLoaderTest, AddWhenNotReady) {
184 extension_service_.set_ready(false); 183 extension_service_.set_ready(false);
185 std::string extension_id = 184 std::string extension_id =
186 component_loader_.Add(manifest_contents_, extension_path_); 185 component_loader_.Add(manifest_contents_, extension_path_);
187 EXPECT_NE("", extension_id); 186 EXPECT_NE("", extension_id);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 component_loader_.AddOrReplace(known_extension); 278 component_loader_.AddOrReplace(known_extension);
280 EXPECT_EQ(default_count + 1, registry->enabled_extensions().size()); 279 EXPECT_EQ(default_count + 1, registry->enabled_extensions().size());
281 EXPECT_EQ(1u, extension_service_.unloaded_count()); 280 EXPECT_EQ(1u, extension_service_.unloaded_count());
282 281
283 // Add an invalid component extension. 282 // Add an invalid component extension.
284 std::string extension_id = component_loader_.AddOrReplace(invalid_extension); 283 std::string extension_id = component_loader_.AddOrReplace(invalid_extension);
285 EXPECT_TRUE(extension_id.empty()); 284 EXPECT_TRUE(extension_id.empty());
286 } 285 }
287 286
288 } // namespace extensions 287 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/component_loader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698