Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "net/disk_cache/disk_cache_test_base.h" | 5 #include "net/disk_cache/disk_cache_test_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/field_trial.h" | |
| 12 #include "base/metrics/field_trial_param_associator.h" | |
| 11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/test/mock_entropy_provider.h" | |
| 17 #include "base/test/scoped_feature_list.h" | |
| 14 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 17 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 18 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
| 19 #include "net/disk_cache/blockfile/backend_impl.h" | 23 #include "net/disk_cache/blockfile/backend_impl.h" |
| 20 #include "net/disk_cache/cache_util.h" | 24 #include "net/disk_cache/cache_util.h" |
| 21 #include "net/disk_cache/disk_cache.h" | 25 #include "net/disk_cache/disk_cache.h" |
| 22 #include "net/disk_cache/disk_cache_test_util.h" | 26 #include "net/disk_cache/disk_cache_test_util.h" |
| 23 #include "net/disk_cache/memory/mem_backend_impl.h" | 27 #include "net/disk_cache/memory/mem_backend_impl.h" |
| 24 #include "net/disk_cache/simple/simple_backend_impl.h" | 28 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 29 #include "net/disk_cache/simple/simple_experiment.h" | |
| 25 #include "net/disk_cache/simple/simple_index.h" | 30 #include "net/disk_cache/simple/simple_index.h" |
| 26 #include "net/test/gtest_util.h" | 31 #include "net/test/gtest_util.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 34 |
| 30 using net::test::IsOk; | 35 using net::test::IsOk; |
| 31 | 36 |
| 32 DiskCacheTest::DiskCacheTest() { | 37 DiskCacheTest::DiskCacheTest() { |
| 33 CHECK(temp_dir_.CreateUniqueTempDir()); | 38 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 34 cache_path_ = temp_dir_.GetPath(); | 39 cache_path_ = temp_dir_.GetPath(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 type_(net::DISK_CACHE), | 85 type_(net::DISK_CACHE), |
| 81 memory_only_(false), | 86 memory_only_(false), |
| 82 simple_cache_mode_(false), | 87 simple_cache_mode_(false), |
| 83 simple_cache_wait_for_index_(true), | 88 simple_cache_wait_for_index_(true), |
| 84 force_creation_(false), | 89 force_creation_(false), |
| 85 new_eviction_(false), | 90 new_eviction_(false), |
| 86 first_cleanup_(true), | 91 first_cleanup_(true), |
| 87 integrity_(true), | 92 integrity_(true), |
| 88 use_current_thread_(false), | 93 use_current_thread_(false), |
| 89 cache_thread_("CacheThread") { | 94 cache_thread_("CacheThread") { |
| 95 // Make sure to cover the prefetch path in SimpleCache. | |
|
pasko
2017/07/18 14:02:56
doing work in constructors is generally discourage
morlovich
2017/07/18 14:32:31
Any keyword to search for/pointer for that mechani
pasko
2017/07/19 16:28:26
go/finch101 and search for "testing-config", but
Maks Orlovich
2017/07/25 16:06:29
Removed this from here (and added for the dedicate
| |
| 96 field_trial_list_ = base::MakeUnique<base::FieldTrialList>( | |
| 97 base::MakeUnique<base::MockEntropyProvider>()); | |
| 98 scoped_refptr<base::FieldTrial> trial = | |
| 99 base::FieldTrialList::CreateFieldTrial("UnitTest", "Group"); | |
| 100 std::map<std::string, std::string> params; | |
| 101 params[disk_cache::kSimplePrefetchBytesParam] = "32768"; | |
| 102 base::FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams( | |
| 103 "UnitTest", "Group", params); | |
| 104 | |
| 105 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 106 feature_list->RegisterFieldTrialOverride( | |
| 107 disk_cache::kSimpleCachePrefetchExperiment.name, | |
| 108 base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial.get()); | |
| 109 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); | |
| 90 } | 110 } |
| 91 | 111 |
| 92 DiskCacheTestWithCache::~DiskCacheTestWithCache() {} | 112 DiskCacheTestWithCache::~DiskCacheTestWithCache() {} |
| 93 | 113 |
| 94 void DiskCacheTestWithCache::InitCache() { | 114 void DiskCacheTestWithCache::InitCache() { |
| 95 if (memory_only_) | 115 if (memory_only_) |
| 96 InitMemoryCache(); | 116 InitMemoryCache(); |
| 97 else | 117 else |
| 98 InitDiskCache(); | 118 InitDiskCache(); |
| 99 | 119 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 if (size_) | 371 if (size_) |
| 352 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 372 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 353 if (new_eviction_) | 373 if (new_eviction_) |
| 354 cache_impl_->SetNewEviction(); | 374 cache_impl_->SetNewEviction(); |
| 355 cache_impl_->SetType(type_); | 375 cache_impl_->SetType(type_); |
| 356 cache_impl_->SetFlags(flags); | 376 cache_impl_->SetFlags(flags); |
| 357 net::TestCompletionCallback cb; | 377 net::TestCompletionCallback cb; |
| 358 int rv = cache_impl_->Init(cb.callback()); | 378 int rv = cache_impl_->Init(cb.callback()); |
| 359 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 379 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
| 360 } | 380 } |
| OLD | NEW |