OLD | NEW |
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 "chrome/browser/extensions/updater/local_extension_cache.h" | 5 #include "chrome/browser/extensions/updater/local_extension_cache.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Wait for background task completion that sends replay to UI thread. | 132 // Wait for background task completion that sends replay to UI thread. |
133 pool_owner_->pool()->FlushForTesting(); | 133 pool_owner_->pool()->FlushForTesting(); |
134 // Wait for UI thread task completion. | 134 // Wait for UI thread task completion. |
135 base::RunLoop().RunUntilIdle(); | 135 base::RunLoop().RunUntilIdle(); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 private: | 139 private: |
140 content::TestBrowserThreadBundle thread_bundle_; | 140 content::TestBrowserThreadBundle thread_bundle_; |
141 | 141 |
142 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 142 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
143 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 143 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
144 | 144 |
145 base::ScopedTempDir cache_dir_; | 145 base::ScopedTempDir cache_dir_; |
146 base::ScopedTempDir temp_dir_; | 146 base::ScopedTempDir temp_dir_; |
147 | 147 |
148 DISALLOW_COPY_AND_ASSIGN(LocalExtensionCacheTest); | 148 DISALLOW_COPY_AND_ASSIGN(LocalExtensionCacheTest); |
149 }; | 149 }; |
150 | 150 |
151 static void SimpleCallback(bool* ptr) { | 151 static void SimpleCallback(bool* ptr) { |
152 *ptr = true; | 152 *ptr = true; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // without hash | 332 // without hash |
333 std::string version; | 333 std::string version; |
334 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, "", NULL, &version)); | 334 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, "", NULL, &version)); |
335 EXPECT_EQ(version, "2.0"); | 335 EXPECT_EQ(version, "2.0"); |
336 EXPECT_FALSE(cache.GetExtension(kTestExtensionId1, hash11, NULL, NULL)); | 336 EXPECT_FALSE(cache.GetExtension(kTestExtensionId1, hash11, NULL, NULL)); |
337 EXPECT_FALSE(cache.GetExtension(kTestExtensionId1, hash12, NULL, NULL)); | 337 EXPECT_FALSE(cache.GetExtension(kTestExtensionId1, hash12, NULL, NULL)); |
338 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash21, NULL, NULL)); | 338 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash21, NULL, NULL)); |
339 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash22, NULL, NULL)); | 339 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash22, NULL, NULL)); |
340 } | 340 } |
341 | 341 |
342 static void OnPutExtension(scoped_ptr<base::RunLoop>* run_loop, | 342 static void OnPutExtension(std::unique_ptr<base::RunLoop>* run_loop, |
343 const base::FilePath& file_path, | 343 const base::FilePath& file_path, |
344 bool file_ownership_passed) { | 344 bool file_ownership_passed) { |
345 ASSERT_TRUE(*run_loop); | 345 ASSERT_TRUE(*run_loop); |
346 (*run_loop)->Quit(); | 346 (*run_loop)->Quit(); |
347 } | 347 } |
348 | 348 |
349 static void PutExtensionAndWait(LocalExtensionCache& cache, | 349 static void PutExtensionAndWait(LocalExtensionCache& cache, |
350 const std::string& id, | 350 const std::string& id, |
351 const std::string& expected_hash, | 351 const std::string& expected_hash, |
352 const base::FilePath& path, | 352 const base::FilePath& path, |
353 const std::string& version) { | 353 const std::string& version) { |
354 scoped_ptr<base::RunLoop> run_loop; | 354 std::unique_ptr<base::RunLoop> run_loop; |
355 run_loop.reset(new base::RunLoop); | 355 run_loop.reset(new base::RunLoop); |
356 cache.PutExtension(id, expected_hash, path, version, | 356 cache.PutExtension(id, expected_hash, path, version, |
357 base::Bind(&OnPutExtension, &run_loop)); | 357 base::Bind(&OnPutExtension, &run_loop)); |
358 run_loop->Run(); | 358 run_loop->Run(); |
359 } | 359 } |
360 | 360 |
361 TEST_F(LocalExtensionCacheTest, PutExtensionCases) { | 361 TEST_F(LocalExtensionCacheTest, PutExtensionCases) { |
362 base::FilePath cache_dir(CreateCacheDir(false)); | 362 base::FilePath cache_dir(CreateCacheDir(false)); |
363 | 363 |
364 LocalExtensionCache cache(cache_dir, 1000, base::TimeDelta::FromDays(30), | 364 LocalExtensionCache cache(cache_dir, 1000, base::TimeDelta::FromDays(30), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const base::FilePath hashed2 = | 480 const base::FilePath hashed2 = |
481 GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); | 481 GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); |
482 EXPECT_TRUE(base::PathExists(hashed2)); | 482 EXPECT_TRUE(base::PathExists(hashed2)); |
483 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); | 483 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); |
484 // Old file kept | 484 // Old file kept |
485 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); | 485 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); |
486 EXPECT_TRUE(base::DeleteFile(temp7, false)); | 486 EXPECT_TRUE(base::DeleteFile(temp7, false)); |
487 } | 487 } |
488 | 488 |
489 } // namespace extensions | 489 } // namespace extensions |
OLD | NEW |