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

Side by Side Diff: extensions/browser/updater/update_service_unittest.cc

Issue 2314363002: extensions: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Comment addressed Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 fake_extension_system_factory_; 202 fake_extension_system_factory_;
203 }; 203 };
204 204
205 TEST_F(UpdateServiceTest, BasicUpdateOperations) { 205 TEST_F(UpdateServiceTest, BasicUpdateOperations) {
206 // Create a temporary directory that a fake extension will live in and fill 206 // Create a temporary directory that a fake extension will live in and fill
207 // it with some test files. 207 // it with some test files.
208 base::ScopedTempDir temp_dir; 208 base::ScopedTempDir temp_dir;
209 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 209 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
210 base::FilePath foo_js(FILE_PATH_LITERAL("foo.js")); 210 base::FilePath foo_js(FILE_PATH_LITERAL("foo.js"));
211 base::FilePath bar_html(FILE_PATH_LITERAL("bar/bar.html")); 211 base::FilePath bar_html(FILE_PATH_LITERAL("bar/bar.html"));
212 ASSERT_TRUE(AddFileToDirectory(temp_dir.path(), foo_js, "hello")) 212 ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), foo_js, "hello"))
213 << "Failed to write " << temp_dir.path().value() << "/" << foo_js.value(); 213 << "Failed to write " << temp_dir.GetPath().value() << "/"
214 ASSERT_TRUE(AddFileToDirectory(temp_dir.path(), bar_html, "world")); 214 << foo_js.value();
215 ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), bar_html, "world"));
215 216
216 ExtensionBuilder builder; 217 ExtensionBuilder builder;
217 builder.SetManifest(DictionaryBuilder() 218 builder.SetManifest(DictionaryBuilder()
218 .Set("name", "Foo") 219 .Set("name", "Foo")
219 .Set("version", "1.0") 220 .Set("version", "1.0")
220 .Set("manifest_version", 2) 221 .Set("manifest_version", 2)
221 .Build()); 222 .Build());
222 builder.SetID(crx_file::id_util::GenerateId("whatever")); 223 builder.SetID(crx_file::id_util::GenerateId("whatever"));
223 builder.SetPath(temp_dir.path()); 224 builder.SetPath(temp_dir.GetPath());
224 225
225 scoped_refptr<Extension> extension1(builder.Build()); 226 scoped_refptr<Extension> extension1(builder.Build());
226 227
227 ExtensionRegistry::Get(browser_context())->AddEnabled(extension1); 228 ExtensionRegistry::Get(browser_context())->AddEnabled(extension1);
228 std::vector<std::string> ids; 229 std::vector<std::string> ids;
229 ids.push_back(extension1->id()); 230 ids.push_back(extension1->id());
230 231
231 // Start an update check and verify that the UpdateClient was sent the right 232 // Start an update check and verify that the UpdateClient was sent the right
232 // data. 233 // data.
233 update_service()->StartUpdateCheck(ids); 234 update_service()->StartUpdateCheck(ids);
234 std::vector<update_client::CrxComponent>* data = update_client()->data(); 235 std::vector<update_client::CrxComponent>* data = update_client()->data();
235 ASSERT_NE(nullptr, data); 236 ASSERT_NE(nullptr, data);
236 ASSERT_EQ(1u, data->size()); 237 ASSERT_EQ(1u, data->size());
237 238
238 ASSERT_EQ(data->at(0).version, *extension1->version()); 239 ASSERT_EQ(data->at(0).version, *extension1->version());
239 update_client::CrxInstaller* installer = data->at(0).installer.get(); 240 update_client::CrxInstaller* installer = data->at(0).installer.get();
240 ASSERT_NE(installer, nullptr); 241 ASSERT_NE(installer, nullptr);
241 242
242 // The GetInstalledFile method is used when processing differential updates 243 // The GetInstalledFile method is used when processing differential updates
243 // to get a path to an existing file in an extension. We want to test a 244 // to get a path to an existing file in an extension. We want to test a
244 // number of scenarios to be user we handle invalid relative paths, don't 245 // number of scenarios to be user we handle invalid relative paths, don't
245 // accidentally return paths outside the extension's dir, etc. 246 // accidentally return paths outside the extension's dir, etc.
246 base::FilePath tmp; 247 base::FilePath tmp;
247 EXPECT_TRUE(installer->GetInstalledFile(foo_js.MaybeAsASCII(), &tmp)); 248 EXPECT_TRUE(installer->GetInstalledFile(foo_js.MaybeAsASCII(), &tmp));
248 EXPECT_EQ(temp_dir.path().Append(foo_js), tmp) << tmp.value(); 249 EXPECT_EQ(temp_dir.GetPath().Append(foo_js), tmp) << tmp.value();
249 250
250 EXPECT_TRUE(installer->GetInstalledFile(bar_html.MaybeAsASCII(), &tmp)); 251 EXPECT_TRUE(installer->GetInstalledFile(bar_html.MaybeAsASCII(), &tmp));
251 EXPECT_EQ(temp_dir.path().Append(bar_html), tmp) << tmp.value(); 252 EXPECT_EQ(temp_dir.GetPath().Append(bar_html), tmp) << tmp.value();
252 253
253 EXPECT_FALSE(installer->GetInstalledFile("does_not_exist", &tmp)); 254 EXPECT_FALSE(installer->GetInstalledFile("does_not_exist", &tmp));
254 EXPECT_FALSE(installer->GetInstalledFile("does/not/exist", &tmp)); 255 EXPECT_FALSE(installer->GetInstalledFile("does/not/exist", &tmp));
255 EXPECT_FALSE(installer->GetInstalledFile("/does/not/exist", &tmp)); 256 EXPECT_FALSE(installer->GetInstalledFile("/does/not/exist", &tmp));
256 EXPECT_FALSE(installer->GetInstalledFile("C:\\tmp", &tmp)); 257 EXPECT_FALSE(installer->GetInstalledFile("C:\\tmp", &tmp));
257 258
258 base::FilePath system_temp_dir; 259 base::FilePath system_temp_dir;
259 ASSERT_TRUE(base::GetTempDir(&system_temp_dir)); 260 ASSERT_TRUE(base::GetTempDir(&system_temp_dir));
260 EXPECT_FALSE( 261 EXPECT_FALSE(
261 installer->GetInstalledFile(system_temp_dir.MaybeAsASCII(), &tmp)); 262 installer->GetInstalledFile(system_temp_dir.MaybeAsASCII(), &tmp));
262 263
263 // Test the install callback. 264 // Test the install callback.
264 base::ScopedTempDir new_version_dir; 265 base::ScopedTempDir new_version_dir;
265 ASSERT_TRUE(new_version_dir.CreateUniqueTempDir()); 266 ASSERT_TRUE(new_version_dir.CreateUniqueTempDir());
266 std::unique_ptr<base::DictionaryValue> new_manifest( 267 std::unique_ptr<base::DictionaryValue> new_manifest(
267 extension1->manifest()->value()->DeepCopy()); 268 extension1->manifest()->value()->DeepCopy());
268 new_manifest->SetString("version", "2.0"); 269 new_manifest->SetString("version", "2.0");
269 270
270 installer->Install(*new_manifest, new_version_dir.path()); 271 installer->Install(*new_manifest, new_version_dir.GetPath());
271 272
272 scoped_refptr<content::MessageLoopRunner> loop_runner = 273 scoped_refptr<content::MessageLoopRunner> loop_runner =
273 new content::MessageLoopRunner(); 274 new content::MessageLoopRunner();
274 extension_system()->set_install_callback(loop_runner->QuitClosure()); 275 extension_system()->set_install_callback(loop_runner->QuitClosure());
275 loop_runner->Run(); 276 loop_runner->Run();
276 277
277 std::vector<FakeExtensionSystem::InstallUpdateRequest>* requests = 278 std::vector<FakeExtensionSystem::InstallUpdateRequest>* requests =
278 extension_system()->install_requests(); 279 extension_system()->install_requests();
279 ASSERT_EQ(1u, requests->size()); 280 ASSERT_EQ(1u, requests->size());
280 EXPECT_EQ(requests->at(0).extension_id, extension1->id()); 281 EXPECT_EQ(requests->at(0).extension_id, extension1->id());
281 EXPECT_NE(requests->at(0).temp_dir.value(), new_version_dir.path().value()); 282 EXPECT_NE(requests->at(0).temp_dir.value(),
283 new_version_dir.GetPath().value());
282 } 284 }
283 285
284 TEST_F(UpdateServiceTest, UninstallPings) { 286 TEST_F(UpdateServiceTest, UninstallPings) {
285 UninstallPingSender sender(ExtensionRegistry::Get(browser_context()), 287 UninstallPingSender sender(ExtensionRegistry::Get(browser_context()),
286 base::Bind(&ShouldPing)); 288 base::Bind(&ShouldPing));
287 289
288 // Build 3 extensions. 290 // Build 3 extensions.
289 scoped_refptr<Extension> extension1 = 291 scoped_refptr<Extension> extension1 =
290 test_util::BuildExtension(ExtensionBuilder()) 292 test_util::BuildExtension(ExtensionBuilder())
291 .SetID(crx_file::id_util::GenerateId("1")) 293 .SetID(crx_file::id_util::GenerateId("1"))
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 EXPECT_EQ(*extension3->version(), pings[1].version) << reason; 346 EXPECT_EQ(*extension3->version(), pings[1].version) << reason;
345 EXPECT_EQ(reason, pings[1].reason) << reason; 347 EXPECT_EQ(reason, pings[1].reason) << reason;
346 348
347 pings.clear(); 349 pings.clear();
348 } 350 }
349 } 351 }
350 352
351 } // namespace 353 } // namespace
352 354
353 } // namespace extensions 355 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/updater/update_install_shim.cc ('k') | extensions/browser/value_store/leveldb_scoped_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698