[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 5 | #include <stdio.h> |
| 6 | |
| 7 | #include <map> |
| 8 | |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 9 | #include "base/files/file_enumerator.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 10 | #include "base/files/file_util.h" |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 11 | #include "base/files/safe_base_name.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 12 | #include "base/files/scoped_temp_dir.h" |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 13 | #include "base/run_loop.h" |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 14 | #include "base/strings/string_number_conversions.h" |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 15 | #include "base/test/bind.h" |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 16 | #include "base/test/scoped_feature_list.h" |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 17 | #include "base/test/task_environment.h" |
| 18 | #include "base/threading/platform_thread.h" |
Yuta Hijikata | 101ed2a | 2020-11-18 07:50:39 | [diff] [blame] | 19 | #include "build/chromeos_buildflags.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 20 | #include "net/disk_cache/cache_util.h" |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 21 | #include "testing/gtest/include/gtest/gtest.h" |
| 22 | #include "testing/platform_test.h" |
| 23 | |
| 24 | namespace disk_cache { |
| 25 | |
| 26 | class CacheUtilTest : public PlatformTest { |
| 27 | public: |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 28 | void SetUp() override { |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 29 | PlatformTest::SetUp(); |
| 30 | ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
vabr | b858232 | 2016-09-09 08:05:37 | [diff] [blame] | 31 | cache_dir_ = tmp_dir_.GetPath().Append(FILE_PATH_LITERAL("Cache")); |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 32 | file1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("file01"))); |
| 33 | file2_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL(".file02"))); |
| 34 | dir1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("dir01"))); |
[email protected] | 76ed979ee | 2013-07-17 15:50:45 | [diff] [blame] | 35 | file3_ = base::FilePath(dir1_.Append(FILE_PATH_LITERAL("file03"))); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 36 | ASSERT_TRUE(base::CreateDirectory(cache_dir_)); |
[email protected] | 7600d0b | 2013-12-08 21:43:30 | [diff] [blame] | 37 | FILE *fp = base::OpenFile(file1_, "w"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 38 | ASSERT_TRUE(fp != nullptr); |
[email protected] | 7600d0b | 2013-12-08 21:43:30 | [diff] [blame] | 39 | base::CloseFile(fp); |
| 40 | fp = base::OpenFile(file2_, "w"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 41 | ASSERT_TRUE(fp != nullptr); |
[email protected] | 7600d0b | 2013-12-08 21:43:30 | [diff] [blame] | 42 | base::CloseFile(fp); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 43 | ASSERT_TRUE(base::CreateDirectory(dir1_)); |
[email protected] | 7600d0b | 2013-12-08 21:43:30 | [diff] [blame] | 44 | fp = base::OpenFile(file3_, "w"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 45 | ASSERT_TRUE(fp != nullptr); |
[email protected] | 7600d0b | 2013-12-08 21:43:30 | [diff] [blame] | 46 | base::CloseFile(fp); |
vabr | b858232 | 2016-09-09 08:05:37 | [diff] [blame] | 47 | dest_dir_ = tmp_dir_.GetPath().Append(FILE_PATH_LITERAL("old_Cache_001")); |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 48 | dest_file1_ = base::FilePath(dest_dir_.Append(FILE_PATH_LITERAL("file01"))); |
| 49 | dest_file2_ = |
| 50 | base::FilePath(dest_dir_.Append(FILE_PATH_LITERAL(".file02"))); |
| 51 | dest_dir1_ = base::FilePath(dest_dir_.Append(FILE_PATH_LITERAL("dir01"))); |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | protected: |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 55 | base::ScopedTempDir tmp_dir_; |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 56 | base::FilePath cache_dir_; |
| 57 | base::FilePath file1_; |
| 58 | base::FilePath file2_; |
| 59 | base::FilePath dir1_; |
[email protected] | 76ed979ee | 2013-07-17 15:50:45 | [diff] [blame] | 60 | base::FilePath file3_; |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 61 | base::FilePath dest_dir_; |
| 62 | base::FilePath dest_file1_; |
| 63 | base::FilePath dest_file2_; |
| 64 | base::FilePath dest_dir1_; |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 65 | |
| 66 | base::test::TaskEnvironment task_environment_; |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | TEST_F(CacheUtilTest, MoveCache) { |
| 70 | EXPECT_TRUE(disk_cache::MoveCache(cache_dir_, dest_dir_)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 71 | EXPECT_TRUE(base::PathExists(dest_dir_)); |
| 72 | EXPECT_TRUE(base::PathExists(dest_file1_)); |
| 73 | EXPECT_TRUE(base::PathExists(dest_file2_)); |
| 74 | EXPECT_TRUE(base::PathExists(dest_dir1_)); |
Yuta Hijikata | 101ed2a | 2020-11-18 07:50:39 | [diff] [blame] | 75 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 76 | EXPECT_TRUE(base::PathExists(cache_dir_)); // old cache dir stays |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 77 | #else |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 78 | EXPECT_FALSE(base::PathExists(cache_dir_)); // old cache is gone |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 79 | #endif |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 80 | EXPECT_FALSE(base::PathExists(file1_)); |
| 81 | EXPECT_FALSE(base::PathExists(file2_)); |
| 82 | EXPECT_FALSE(base::PathExists(dir1_)); |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | TEST_F(CacheUtilTest, DeleteCache) { |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 86 | disk_cache::DeleteCache(cache_dir_, false); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 87 | EXPECT_TRUE(base::PathExists(cache_dir_)); // cache dir stays |
[email protected] | 76ed979ee | 2013-07-17 15:50:45 | [diff] [blame] | 88 | EXPECT_FALSE(base::PathExists(dir1_)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 89 | EXPECT_FALSE(base::PathExists(file1_)); |
| 90 | EXPECT_FALSE(base::PathExists(file2_)); |
[email protected] | 76ed979ee | 2013-07-17 15:50:45 | [diff] [blame] | 91 | EXPECT_FALSE(base::PathExists(file3_)); |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | TEST_F(CacheUtilTest, DeleteCacheAndDir) { |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 95 | disk_cache::DeleteCache(cache_dir_, true); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 96 | EXPECT_FALSE(base::PathExists(cache_dir_)); // cache dir is gone |
[email protected] | 76ed979ee | 2013-07-17 15:50:45 | [diff] [blame] | 97 | EXPECT_FALSE(base::PathExists(dir1_)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 98 | EXPECT_FALSE(base::PathExists(file1_)); |
| 99 | EXPECT_FALSE(base::PathExists(file2_)); |
[email protected] | 76ed979ee | 2013-07-17 15:50:45 | [diff] [blame] | 100 | EXPECT_FALSE(base::PathExists(file3_)); |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 101 | } |
| 102 | |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 103 | TEST_F(CacheUtilTest, CleanupDirectory) { |
| 104 | base::RunLoop run_loop; |
| 105 | disk_cache::CleanupDirectory(cache_dir_, |
| 106 | base::BindLambdaForTesting([&](bool result) { |
| 107 | EXPECT_TRUE(result); |
| 108 | run_loop.Quit(); |
| 109 | })); |
| 110 | run_loop.Run(); |
| 111 | |
| 112 | while (true) { |
| 113 | base::FileEnumerator enumerator(tmp_dir_.GetPath(), /*recursive=*/false, |
| 114 | /*file_type=*/base::FileEnumerator::FILES | |
| 115 | base::FileEnumerator::DIRECTORIES); |
| 116 | bool found = false; |
| 117 | while (true) { |
| 118 | base::FilePath path = enumerator.Next(); |
| 119 | if (path.empty()) { |
| 120 | break; |
| 121 | } |
| 122 | // We're not sure if we see an entry in the directory because it depends |
| 123 | // on timing, but if we do, it must be "old_Cache_000". |
| 124 | // Caveat: On ChromeOS, we leave the top-level directory ("Cache") so |
| 125 | // it must be "Cache" or "old_Cache_000". |
| 126 | const base::FilePath dirname = path.DirName(); |
| 127 | absl::optional<base::SafeBaseName> basename = |
| 128 | base::SafeBaseName::Create(path); |
| 129 | ASSERT_EQ(dirname, tmp_dir_.GetPath()); |
| 130 | ASSERT_TRUE(basename.has_value()); |
| 131 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 132 | if (basename->path().value() == FILE_PATH_LITERAL("Cache")) { |
| 133 | // See the comment above. |
| 134 | ASSERT_TRUE(base::IsDirectoryEmpty(dirname.Append(*basename))); |
| 135 | continue; |
| 136 | } |
| 137 | #endif |
| 138 | ASSERT_EQ(basename->path().value(), FILE_PATH_LITERAL("old_Cache_000")); |
| 139 | found = true; |
| 140 | } |
| 141 | if (!found) { |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | base::PlatformThread::Sleep(base::Milliseconds(10)); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #if BUILDFLAG(IS_POSIX) |
| 150 | TEST_F(CacheUtilTest, CleanupDirectoryFailsWhenParentDirectoryIsInaccessible) { |
| 151 | base::RunLoop run_loop; |
| 152 | |
| 153 | ASSERT_TRUE(base::SetPosixFilePermissions(tmp_dir_.GetPath(), /*mode=*/0)); |
| 154 | disk_cache::CleanupDirectory(cache_dir_, |
| 155 | base::BindLambdaForTesting([&](bool result) { |
| 156 | EXPECT_FALSE(result); |
| 157 | run_loop.Quit(); |
| 158 | })); |
| 159 | run_loop.Run(); |
| 160 | } |
| 161 | |
| 162 | TEST_F(CacheUtilTest, |
| 163 | CleanupDirectorySucceedsWhenTargetDirectoryIsInaccessible) { |
| 164 | base::RunLoop run_loop; |
| 165 | |
| 166 | ASSERT_TRUE(base::SetPosixFilePermissions(cache_dir_, /*mode=*/0)); |
| 167 | disk_cache::CleanupDirectory(cache_dir_, |
| 168 | base::BindLambdaForTesting([&](bool result) { |
| 169 | EXPECT_TRUE(result); |
| 170 | run_loop.Quit(); |
| 171 | })); |
| 172 | run_loop.Run(); |
| 173 | } |
| 174 | #endif |
| 175 | |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 176 | TEST_F(CacheUtilTest, PreferredCacheSize) { |
| 177 | const struct TestCase { |
| 178 | int64_t available; |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 179 | int expected_without_trial; |
| 180 | int expected_with_200_trial; |
| 181 | int expected_with_250_trial; |
| 182 | int expected_with_300_trial; |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 183 | } kTestCases[] = { |
Maks Orlovich | a789a6a4 | 2019-12-03 19:06:26 | [diff] [blame] | 184 | // Weird negative value for available --- return the "default" |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 185 | {-1000LL, 80 * 1024 * 1024, 160 * 1024 * 1024, 200 * 1024 * 1024, |
| 186 | 240 * 1024 * 1024}, |
| 187 | {-1LL, 80 * 1024 * 1024, 160 * 1024 * 1024, 200 * 1024 * 1024, |
| 188 | 240 * 1024 * 1024}, |
Maks Orlovich | a789a6a4 | 2019-12-03 19:06:26 | [diff] [blame] | 189 | |
| 190 | // 0 produces 0. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 191 | {0LL, 0, 0, 0, 0}, |
Maks Orlovich | a789a6a4 | 2019-12-03 19:06:26 | [diff] [blame] | 192 | |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 193 | // Cache is 80% of available space, when default cache size is larger than |
| 194 | // 80% of available space.. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 195 | {50 * 1024 * 1024LL, 40 * 1024 * 1024, 40 * 1024 * 1024, 40 * 1024 * 1024, |
| 196 | 40 * 1024 * 1024}, |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 197 | // Cache is default size, when default size is 10% to 80% of available |
| 198 | // space. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 199 | {100 * 1024 * 1024LL, 80 * 1024 * 1024, 80 * 1024 * 1024, |
| 200 | 80 * 1024 * 1024, 80 * 1024 * 1024}, |
| 201 | {200 * 1024 * 1024LL, 80 * 1024 * 1024, 80 * 1024 * 1024, |
| 202 | 80 * 1024 * 1024, 80 * 1024 * 1024}, |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 203 | // Cache is 10% of available space if 2.5 * default size is more than 10% |
| 204 | // of available space. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 205 | {1000 * 1024 * 1024LL, 100 * 1024 * 1024, 200 * 1024 * 1024, |
| 206 | 200 * 1024 * 1024, 200 * 1024 * 1024}, |
| 207 | {2000 * 1024 * 1024LL, 200 * 1024 * 1024, 400 * 1024 * 1024, |
| 208 | 400 * 1024 * 1024, 400 * 1024 * 1024}, |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 209 | // Cache is 2.5 * kDefaultCacheSize if 2.5 * kDefaultCacheSize uses from |
| 210 | // 1% to 10% of available space. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 211 | {10000 * 1024 * 1024LL, 200 * 1024 * 1024, 400 * 1024 * 1024, |
| 212 | 500 * 1024 * 1024, 600 * 1024 * 1024}, |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 213 | // Otherwise, cache is 1% of available space. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 214 | {20000 * 1024 * 1024LL, 200 * 1024 * 1024, 400 * 1024 * 1024, |
| 215 | 500 * 1024 * 1024, 600 * 1024 * 1024}, |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 216 | // Until it runs into the cache size cap. |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 217 | {32000 * 1024 * 1024LL, 320 * 1024 * 1024, 640 * 1024 * 1024, |
| 218 | 800 * 1024 * 1024, 960 * 1024 * 1024}, |
| 219 | {50000 * 1024 * 1024LL, 320 * 1024 * 1024, 640 * 1024 * 1024, |
| 220 | 800 * 1024 * 1024, 960 * 1024 * 1024}, |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | for (const auto& test_case : kTestCases) { |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 224 | EXPECT_EQ(test_case.expected_without_trial, |
| 225 | PreferredCacheSize(test_case.available)) |
Maks Orlovich | a789a6a4 | 2019-12-03 19:06:26 | [diff] [blame] | 226 | << test_case.available; |
Seth Brenith | ddc5035 | 2021-08-05 15:05:45 | [diff] [blame] | 227 | |
| 228 | // Preferred size for WebUI code cache matches expected_without_trial but |
| 229 | // should never be more than 5 MB. |
| 230 | int expected_webui_code_cache_size = |
| 231 | std::min(5 * 1024 * 1024, test_case.expected_without_trial); |
| 232 | EXPECT_EQ(expected_webui_code_cache_size, |
| 233 | PreferredCacheSize(test_case.available, |
| 234 | net::GENERATED_WEBUI_BYTE_CODE_CACHE)) |
| 235 | << test_case.available; |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 236 | } |
| 237 | |
Bill Budge | 1bb18a94 | 2019-12-02 22:19:54 | [diff] [blame] | 238 | // Check that the cache size cap is 50% higher for native code caches. |
| 239 | EXPECT_EQ(((320 * 1024 * 1024) / 2) * 3, |
| 240 | PreferredCacheSize(50000 * 1024 * 1024LL, |
| 241 | net::GENERATED_NATIVE_CODE_CACHE)); |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 242 | |
| 243 | for (int cache_size_exeriment : {100, 200, 250, 300}) { |
| 244 | base::test::ScopedFeatureList scoped_feature_list; |
| 245 | std::map<std::string, std::string> field_trial_params; |
| 246 | field_trial_params["percent_relative_size"] = |
| 247 | base::NumberToString(cache_size_exeriment); |
| 248 | scoped_feature_list.InitAndEnableFeatureWithParameters( |
| 249 | disk_cache::kChangeDiskCacheSizeExperiment, field_trial_params); |
| 250 | |
| 251 | for (const auto& test_case : kTestCases) { |
| 252 | int expected = 0; |
| 253 | switch (cache_size_exeriment) { |
| 254 | case 100: |
| 255 | expected = test_case.expected_without_trial; |
| 256 | break; |
| 257 | case 200: |
| 258 | expected = test_case.expected_with_200_trial; |
| 259 | break; |
| 260 | case 250: |
| 261 | expected = test_case.expected_with_250_trial; |
| 262 | break; |
| 263 | case 300: |
| 264 | expected = test_case.expected_with_300_trial; |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | EXPECT_EQ(expected, PreferredCacheSize(test_case.available)); |
| 269 | |
| 270 | // For caches other than disk cache, the size is not scaled. |
| 271 | EXPECT_EQ(test_case.expected_without_trial, |
| 272 | PreferredCacheSize(test_case.available, |
| 273 | net::GENERATED_BYTE_CODE_CACHE)); |
Seth Brenith | ddc5035 | 2021-08-05 15:05:45 | [diff] [blame] | 274 | |
| 275 | // Preferred size for WebUI code cache is not scaled by the trial, and |
| 276 | // should never be more than 5 MB. |
| 277 | int expected_webui_code_cache_size = |
| 278 | std::min(5 * 1024 * 1024, test_case.expected_without_trial); |
| 279 | EXPECT_EQ(expected_webui_code_cache_size, |
| 280 | PreferredCacheSize(test_case.available, |
| 281 | net::GENERATED_WEBUI_BYTE_CODE_CACHE)) |
| 282 | << test_case.available; |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | // Check that the cache size cap is 50% higher for native code caches but is |
| 286 | // not scaled for the experiment. |
| 287 | EXPECT_EQ(((320 * 1024 * 1024) / 2) * 3, |
| 288 | PreferredCacheSize(50000 * 1024 * 1024LL, |
| 289 | net::GENERATED_NATIVE_CODE_CACHE)); |
| 290 | } |
| 291 | |
| 292 | // Check no "percent_relative_size" matches default behavior. |
| 293 | { |
| 294 | base::test::ScopedFeatureList scoped_feature_list; |
| 295 | scoped_feature_list.InitAndEnableFeature( |
| 296 | disk_cache::kChangeDiskCacheSizeExperiment); |
| 297 | for (const auto& test_case : kTestCases) { |
| 298 | EXPECT_EQ(test_case.expected_without_trial, |
| 299 | PreferredCacheSize(test_case.available)); |
| 300 | } |
| 301 | // Check that the cache size cap is 50% higher for native code caches. |
| 302 | EXPECT_EQ(((320 * 1024 * 1024) / 2) * 3, |
| 303 | PreferredCacheSize(50000 * 1024 * 1024LL, |
| 304 | net::GENERATED_NATIVE_CODE_CACHE)); |
| 305 | } |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 308 | } // namespace disk_cache |