OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void BackendInvalidRankings2(); | 67 void BackendInvalidRankings2(); |
68 void BackendDisable(); | 68 void BackendDisable(); |
69 void BackendDisable2(); | 69 void BackendDisable2(); |
70 void BackendDisable3(); | 70 void BackendDisable3(); |
71 void BackendDisable4(); | 71 void BackendDisable4(); |
72 }; | 72 }; |
73 | 73 |
74 void DiskCacheBackendTest::BackendBasics() { | 74 void DiskCacheBackendTest::BackendBasics() { |
75 InitCache(); | 75 InitCache(); |
76 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; | 76 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; |
77 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); | 77 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); |
78 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); | 78 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1)); |
79 ASSERT_TRUE(NULL != entry1); | 79 ASSERT_TRUE(NULL != entry1); |
80 entry1->Close(); | 80 entry1->Close(); |
81 entry1 = NULL; | 81 entry1 = NULL; |
82 | 82 |
83 ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1)); | 83 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); |
84 ASSERT_TRUE(NULL != entry1); | 84 ASSERT_TRUE(NULL != entry1); |
85 entry1->Close(); | 85 entry1->Close(); |
86 entry1 = NULL; | 86 entry1 = NULL; |
87 | 87 |
88 EXPECT_FALSE(cache_->CreateEntry("the first key", &entry1)); | 88 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1)); |
89 ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1)); | 89 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); |
90 EXPECT_FALSE(cache_->OpenEntry("some other key", &entry2)); | 90 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); |
91 ASSERT_TRUE(cache_->CreateEntry("some other key", &entry2)); | 91 ASSERT_EQ(net::OK, CreateEntry("some other key", &entry2)); |
92 ASSERT_TRUE(NULL != entry1); | 92 ASSERT_TRUE(NULL != entry1); |
93 ASSERT_TRUE(NULL != entry2); | 93 ASSERT_TRUE(NULL != entry2); |
94 EXPECT_EQ(2, cache_->GetEntryCount()); | 94 EXPECT_EQ(2, cache_->GetEntryCount()); |
95 | 95 |
96 disk_cache::Entry* entry3 = NULL; | 96 disk_cache::Entry* entry3 = NULL; |
97 ASSERT_TRUE(cache_->OpenEntry("some other key", &entry3)); | 97 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry3)); |
98 ASSERT_TRUE(NULL != entry3); | 98 ASSERT_TRUE(NULL != entry3); |
99 EXPECT_TRUE(entry2 == entry3); | 99 EXPECT_TRUE(entry2 == entry3); |
100 EXPECT_EQ(2, cache_->GetEntryCount()); | 100 EXPECT_EQ(2, cache_->GetEntryCount()); |
101 | 101 |
102 EXPECT_TRUE(cache_->DoomEntry("some other key")); | 102 EXPECT_EQ(net::OK, DoomEntry("some other key")); |
103 EXPECT_EQ(1, cache_->GetEntryCount()); | 103 EXPECT_EQ(1, cache_->GetEntryCount()); |
104 entry1->Close(); | 104 entry1->Close(); |
105 entry2->Close(); | 105 entry2->Close(); |
106 entry3->Close(); | 106 entry3->Close(); |
107 | 107 |
108 EXPECT_TRUE(cache_->DoomEntry("the first key")); | 108 EXPECT_EQ(net::OK, DoomEntry("the first key")); |
109 EXPECT_EQ(0, cache_->GetEntryCount()); | 109 EXPECT_EQ(0, cache_->GetEntryCount()); |
110 | 110 |
111 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); | 111 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1)); |
112 ASSERT_TRUE(cache_->CreateEntry("some other key", &entry2)); | 112 ASSERT_EQ(net::OK, CreateEntry("some other key", &entry2)); |
113 entry1->Doom(); | 113 entry1->Doom(); |
114 entry1->Close(); | 114 entry1->Close(); |
115 EXPECT_TRUE(cache_->DoomEntry("some other key")); | 115 EXPECT_EQ(net::OK, DoomEntry("some other key")); |
116 EXPECT_EQ(0, cache_->GetEntryCount()); | 116 EXPECT_EQ(0, cache_->GetEntryCount()); |
117 entry2->Close(); | 117 entry2->Close(); |
118 } | 118 } |
119 | 119 |
120 TEST_F(DiskCacheBackendTest, Basics) { | 120 TEST_F(DiskCacheBackendTest, Basics) { |
121 BackendBasics(); | 121 BackendBasics(); |
122 } | 122 } |
123 | 123 |
124 TEST_F(DiskCacheBackendTest, NewEvictionBasics) { | 124 TEST_F(DiskCacheBackendTest, NewEvictionBasics) { |
125 SetNewEviction(); | 125 SetNewEviction(); |
126 BackendBasics(); | 126 BackendBasics(); |
127 } | 127 } |
128 | 128 |
129 TEST_F(DiskCacheBackendTest, MemoryOnlyBasics) { | 129 TEST_F(DiskCacheBackendTest, MemoryOnlyBasics) { |
130 SetMemoryOnlyMode(); | 130 SetMemoryOnlyMode(); |
131 BackendBasics(); | 131 BackendBasics(); |
132 } | 132 } |
133 | 133 |
134 void DiskCacheBackendTest::BackendKeying() { | 134 void DiskCacheBackendTest::BackendKeying() { |
135 InitCache(); | 135 InitCache(); |
136 const char* kName1 = "the first key"; | 136 const char* kName1 = "the first key"; |
137 const char* kName2 = "the first Key"; | 137 const char* kName2 = "the first Key"; |
138 disk_cache::Entry *entry1, *entry2; | 138 disk_cache::Entry *entry1, *entry2; |
139 ASSERT_TRUE(cache_->CreateEntry(kName1, &entry1)); | 139 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1)); |
140 | 140 |
141 ASSERT_TRUE(cache_->CreateEntry(kName2, &entry2)); | 141 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2)); |
142 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; | 142 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; |
143 entry2->Close(); | 143 entry2->Close(); |
144 | 144 |
145 char buffer[30]; | 145 char buffer[30]; |
146 base::strlcpy(buffer, kName1, arraysize(buffer)); | 146 base::strlcpy(buffer, kName1, arraysize(buffer)); |
147 ASSERT_TRUE(cache_->OpenEntry(buffer, &entry2)); | 147 ASSERT_EQ(net::OK, OpenEntry(buffer, &entry2)); |
148 EXPECT_TRUE(entry1 == entry2); | 148 EXPECT_TRUE(entry1 == entry2); |
149 entry2->Close(); | 149 entry2->Close(); |
150 | 150 |
151 base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1); | 151 base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1); |
152 ASSERT_TRUE(cache_->OpenEntry(buffer + 1, &entry2)); | 152 ASSERT_EQ(net::OK, OpenEntry(buffer + 1, &entry2)); |
153 EXPECT_TRUE(entry1 == entry2); | 153 EXPECT_TRUE(entry1 == entry2); |
154 entry2->Close(); | 154 entry2->Close(); |
155 | 155 |
156 base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3); | 156 base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3); |
157 ASSERT_TRUE(cache_->OpenEntry(buffer + 3, &entry2)); | 157 ASSERT_EQ(net::OK, OpenEntry(buffer + 3, &entry2)); |
158 EXPECT_TRUE(entry1 == entry2); | 158 EXPECT_TRUE(entry1 == entry2); |
159 entry2->Close(); | 159 entry2->Close(); |
160 | 160 |
161 // Now verify long keys. | 161 // Now verify long keys. |
162 char buffer2[20000]; | 162 char buffer2[20000]; |
163 memset(buffer2, 's', sizeof(buffer2)); | 163 memset(buffer2, 's', sizeof(buffer2)); |
164 buffer2[1023] = '\0'; | 164 buffer2[1023] = '\0'; |
165 ASSERT_TRUE(cache_->CreateEntry(buffer2, &entry2)) << "key on block file"; | 165 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on block file"; |
166 entry2->Close(); | 166 entry2->Close(); |
167 | 167 |
168 buffer2[1023] = 'g'; | 168 buffer2[1023] = 'g'; |
169 buffer2[19999] = '\0'; | 169 buffer2[19999] = '\0'; |
170 ASSERT_TRUE(cache_->CreateEntry(buffer2, &entry2)) << "key on external file"; | 170 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on external file"; |
171 entry2->Close(); | 171 entry2->Close(); |
172 entry1->Close(); | 172 entry1->Close(); |
173 } | 173 } |
174 | 174 |
175 TEST_F(DiskCacheBackendTest, Keying) { | 175 TEST_F(DiskCacheBackendTest, Keying) { |
176 BackendKeying(); | 176 BackendKeying(); |
177 } | 177 } |
178 | 178 |
179 TEST_F(DiskCacheBackendTest, NewEvictionKeying) { | 179 TEST_F(DiskCacheBackendTest, NewEvictionKeying) { |
180 SetNewEviction(); | 180 SetNewEviction(); |
(...skipping 10 matching lines...) Expand all Loading... |
191 // First, lets create a file on the folder. | 191 // First, lets create a file on the folder. |
192 FilePath filename = GetCacheFilePath().AppendASCII("f_000001"); | 192 FilePath filename = GetCacheFilePath().AppendASCII("f_000001"); |
193 | 193 |
194 const int kSize = 50; | 194 const int kSize = 50; |
195 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 195 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); |
196 CacheTestFillBuffer(buffer1->data(), kSize, false); | 196 CacheTestFillBuffer(buffer1->data(), kSize, false); |
197 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); | 197 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); |
198 | 198 |
199 // Now let's create a file with the cache. | 199 // Now let's create a file with the cache. |
200 disk_cache::Entry* entry; | 200 disk_cache::Entry* entry; |
201 ASSERT_TRUE(cache_->CreateEntry("key", &entry)); | 201 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
202 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); | 202 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); |
203 entry->Close(); | 203 entry->Close(); |
204 | 204 |
205 // And verify that the first file is still there. | 205 // And verify that the first file is still there. |
206 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 206 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); |
207 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 207 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
208 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 208 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
209 } | 209 } |
210 | 210 |
211 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { | 211 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 void DiskCacheBackendTest::BackendSetSize() { | 244 void DiskCacheBackendTest::BackendSetSize() { |
245 SetDirectMode(); | 245 SetDirectMode(); |
246 const int cache_size = 0x10000; // 64 kB | 246 const int cache_size = 0x10000; // 64 kB |
247 SetMaxSize(cache_size); | 247 SetMaxSize(cache_size); |
248 InitCache(); | 248 InitCache(); |
249 | 249 |
250 std::string first("some key"); | 250 std::string first("some key"); |
251 std::string second("something else"); | 251 std::string second("something else"); |
252 disk_cache::Entry* entry; | 252 disk_cache::Entry* entry; |
253 ASSERT_TRUE(cache_->CreateEntry(first, &entry)); | 253 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); |
254 | 254 |
255 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(cache_size); | 255 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(cache_size); |
256 memset(buffer->data(), 0, cache_size); | 256 memset(buffer->data(), 0, cache_size); |
257 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, | 257 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, |
258 NULL, false)) << "normal file"; | 258 NULL, false)) << "normal file"; |
259 | 259 |
260 EXPECT_EQ(net::ERR_FAILED, entry->WriteData(1, 0, buffer, cache_size / 5, | 260 EXPECT_EQ(net::ERR_FAILED, entry->WriteData(1, 0, buffer, cache_size / 5, |
261 NULL, false)) << "file size above the limit"; | 261 NULL, false)) << "file size above the limit"; |
262 | 262 |
263 // By doubling the total size, we make this file cacheable. | 263 // By doubling the total size, we make this file cacheable. |
264 SetMaxSize(cache_size * 2); | 264 SetMaxSize(cache_size * 2); |
265 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, | 265 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, |
266 NULL, false)); | 266 NULL, false)); |
267 | 267 |
268 // Let's fill up the cache!. | 268 // Let's fill up the cache!. |
269 SetMaxSize(cache_size * 10); | 269 SetMaxSize(cache_size * 10); |
270 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, | 270 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, |
271 cache_size * 3 / 4, NULL, false)); | 271 cache_size * 3 / 4, NULL, false)); |
272 entry->Close(); | 272 entry->Close(); |
273 | 273 |
274 SetMaxSize(cache_size); | 274 SetMaxSize(cache_size); |
275 | 275 |
276 // The cache is 95% full. | 276 // The cache is 95% full. |
277 | 277 |
278 ASSERT_TRUE(cache_->CreateEntry(second, &entry)); | 278 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
279 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, | 279 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, |
280 NULL, false)) << "trim the cache"; | 280 NULL, false)) << "trim the cache"; |
281 entry->Close(); | 281 entry->Close(); |
282 | 282 |
283 EXPECT_FALSE(cache_->OpenEntry(first, &entry)); | 283 EXPECT_NE(net::OK, OpenEntry(first, &entry)); |
284 ASSERT_TRUE(cache_->OpenEntry(second, &entry)); | 284 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); |
285 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); | 285 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); |
286 entry->Close(); | 286 entry->Close(); |
287 } | 287 } |
288 | 288 |
289 TEST_F(DiskCacheBackendTest, SetSize) { | 289 TEST_F(DiskCacheBackendTest, SetSize) { |
290 BackendSetSize(); | 290 BackendSetSize(); |
291 } | 291 } |
292 | 292 |
293 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { | 293 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { |
294 SetNewEviction(); | 294 SetNewEviction(); |
295 BackendSetSize(); | 295 BackendSetSize(); |
296 } | 296 } |
297 | 297 |
298 TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) { | 298 TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) { |
299 SetMemoryOnlyMode(); | 299 SetMemoryOnlyMode(); |
300 BackendSetSize(); | 300 BackendSetSize(); |
301 } | 301 } |
302 | 302 |
303 void DiskCacheBackendTest::BackendLoad() { | 303 void DiskCacheBackendTest::BackendLoad() { |
304 InitCache(); | 304 InitCache(); |
305 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 305 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
306 srand(seed); | 306 srand(seed); |
307 | 307 |
308 disk_cache::Entry* entries[100]; | 308 disk_cache::Entry* entries[100]; |
309 for (int i = 0; i < 100; i++) { | 309 for (int i = 0; i < 100; i++) { |
310 std::string key = GenerateKey(true); | 310 std::string key = GenerateKey(true); |
311 ASSERT_TRUE(cache_->CreateEntry(key, &entries[i])); | 311 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i])); |
312 } | 312 } |
313 EXPECT_EQ(100, cache_->GetEntryCount()); | 313 EXPECT_EQ(100, cache_->GetEntryCount()); |
314 | 314 |
315 for (int i = 0; i < 100; i++) { | 315 for (int i = 0; i < 100; i++) { |
316 int source1 = rand() % 100; | 316 int source1 = rand() % 100; |
317 int source2 = rand() % 100; | 317 int source2 = rand() % 100; |
318 disk_cache::Entry* temp = entries[source1]; | 318 disk_cache::Entry* temp = entries[source1]; |
319 entries[source1] = entries[source2]; | 319 entries[source1] = entries[source2]; |
320 entries[source2] = temp; | 320 entries[source2] = temp; |
321 } | 321 } |
322 | 322 |
323 for (int i = 0; i < 100; i++) { | 323 for (int i = 0; i < 100; i++) { |
324 disk_cache::Entry* entry; | 324 disk_cache::Entry* entry; |
325 ASSERT_TRUE(cache_->OpenEntry(entries[i]->GetKey(), &entry)); | 325 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); |
326 EXPECT_TRUE(entry == entries[i]); | 326 EXPECT_TRUE(entry == entries[i]); |
327 entry->Close(); | 327 entry->Close(); |
328 entries[i]->Doom(); | 328 entries[i]->Doom(); |
329 entries[i]->Close(); | 329 entries[i]->Close(); |
330 } | 330 } |
331 EXPECT_EQ(0, cache_->GetEntryCount()); | 331 EXPECT_EQ(0, cache_->GetEntryCount()); |
332 } | 332 } |
333 | 333 |
334 TEST_F(DiskCacheBackendTest, Load) { | 334 TEST_F(DiskCacheBackendTest, Load) { |
335 // Work with a tiny index table (16 entries) | 335 // Work with a tiny index table (16 entries) |
(...skipping 17 matching lines...) Expand all Loading... |
353 BackendLoad(); | 353 BackendLoad(); |
354 } | 354 } |
355 | 355 |
356 // Before looking for invalid entries, let's check a valid entry. | 356 // Before looking for invalid entries, let's check a valid entry. |
357 void DiskCacheBackendTest::BackendValidEntry() { | 357 void DiskCacheBackendTest::BackendValidEntry() { |
358 SetDirectMode(); | 358 SetDirectMode(); |
359 InitCache(); | 359 InitCache(); |
360 | 360 |
361 std::string key("Some key"); | 361 std::string key("Some key"); |
362 disk_cache::Entry* entry1; | 362 disk_cache::Entry* entry1; |
363 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); | 363 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
364 | 364 |
365 const int kSize = 50; | 365 const int kSize = 50; |
366 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 366 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); |
367 memset(buffer1->data(), 0, kSize); | 367 memset(buffer1->data(), 0, kSize); |
368 base::strlcpy(buffer1->data(), "And the data to save", kSize); | 368 base::strlcpy(buffer1->data(), "And the data to save", kSize); |
369 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); | 369 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); |
370 entry1->Close(); | 370 entry1->Close(); |
371 SimulateCrash(); | 371 SimulateCrash(); |
372 | 372 |
373 ASSERT_TRUE(cache_->OpenEntry(key, &entry1)); | 373 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); |
374 | 374 |
375 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 375 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); |
376 memset(buffer2->data(), 0, kSize); | 376 memset(buffer2->data(), 0, kSize); |
377 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer2, kSize, NULL)); | 377 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer2, kSize, NULL)); |
378 entry1->Close(); | 378 entry1->Close(); |
379 EXPECT_STREQ(buffer1->data(), buffer2->data()); | 379 EXPECT_STREQ(buffer1->data(), buffer2->data()); |
380 } | 380 } |
381 | 381 |
382 TEST_F(DiskCacheBackendTest, ValidEntry) { | 382 TEST_F(DiskCacheBackendTest, ValidEntry) { |
383 BackendValidEntry(); | 383 BackendValidEntry(); |
384 } | 384 } |
385 | 385 |
386 TEST_F(DiskCacheBackendTest, NewEvictionValidEntry) { | 386 TEST_F(DiskCacheBackendTest, NewEvictionValidEntry) { |
387 SetNewEviction(); | 387 SetNewEviction(); |
388 BackendValidEntry(); | 388 BackendValidEntry(); |
389 } | 389 } |
390 | 390 |
391 // The same logic of the previous test (ValidEntry), but this time force the | 391 // The same logic of the previous test (ValidEntry), but this time force the |
392 // entry to be invalid, simulating a crash in the middle. | 392 // entry to be invalid, simulating a crash in the middle. |
393 // We'll be leaking memory from this test. | 393 // We'll be leaking memory from this test. |
394 void DiskCacheBackendTest::BackendInvalidEntry() { | 394 void DiskCacheBackendTest::BackendInvalidEntry() { |
395 // Use the implementation directly... we need to simulate a crash. | 395 // Use the implementation directly... we need to simulate a crash. |
396 SetDirectMode(); | 396 SetDirectMode(); |
397 InitCache(); | 397 InitCache(); |
398 | 398 |
399 std::string key("Some key"); | 399 std::string key("Some key"); |
400 disk_cache::Entry* entry1; | 400 disk_cache::Entry* entry1; |
401 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); | 401 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
402 | 402 |
403 const int kSize = 50; | 403 const int kSize = 50; |
404 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 404 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); |
405 memset(buffer1->data(), 0, kSize); | 405 memset(buffer1->data(), 0, kSize); |
406 base::strlcpy(buffer1->data(), "And the data to save", kSize); | 406 base::strlcpy(buffer1->data(), "And the data to save", kSize); |
407 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); | 407 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); |
408 SimulateCrash(); | 408 SimulateCrash(); |
409 | 409 |
410 EXPECT_FALSE(cache_->OpenEntry(key, &entry1)); | 410 EXPECT_NE(net::OK, OpenEntry(key, &entry1)); |
411 EXPECT_EQ(0, cache_->GetEntryCount()); | 411 EXPECT_EQ(0, cache_->GetEntryCount()); |
412 } | 412 } |
413 | 413 |
414 // This and the other intentionally leaky tests below are excluded from | 414 // This and the other intentionally leaky tests below are excluded from |
415 // purify and valgrind runs by naming them in the files | 415 // purify and valgrind runs by naming them in the files |
416 // net/data/purify/net_unittests.exe.gtest.txt and | 416 // net/data/purify/net_unittests.exe.gtest.txt and |
417 // net/data/valgrind/net_unittests.gtest.txt | 417 // net/data/valgrind/net_unittests.gtest.txt |
418 // The scripts tools/{purify,valgrind}/chrome_tests.sh | 418 // The scripts tools/{purify,valgrind}/chrome_tests.sh |
419 // read those files and pass the appropriate --gtest_filter to net_unittests. | 419 // read those files and pass the appropriate --gtest_filter to net_unittests. |
420 TEST_F(DiskCacheBackendTest, InvalidEntry) { | 420 TEST_F(DiskCacheBackendTest, InvalidEntry) { |
421 BackendInvalidEntry(); | 421 BackendInvalidEntry(); |
422 } | 422 } |
423 | 423 |
424 // We'll be leaking memory from this test. | 424 // We'll be leaking memory from this test. |
425 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry) { | 425 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry) { |
426 SetNewEviction(); | 426 SetNewEviction(); |
427 BackendInvalidEntry(); | 427 BackendInvalidEntry(); |
428 } | 428 } |
429 | 429 |
430 // Almost the same test, but this time crash the cache after reading an entry. | 430 // Almost the same test, but this time crash the cache after reading an entry. |
431 // We'll be leaking memory from this test. | 431 // We'll be leaking memory from this test. |
432 void DiskCacheBackendTest::BackendInvalidEntryRead() { | 432 void DiskCacheBackendTest::BackendInvalidEntryRead() { |
433 // Use the implementation directly... we need to simulate a crash. | 433 // Use the implementation directly... we need to simulate a crash. |
434 SetDirectMode(); | 434 SetDirectMode(); |
435 InitCache(); | 435 InitCache(); |
436 | 436 |
437 std::string key("Some key"); | 437 std::string key("Some key"); |
438 disk_cache::Entry* entry1; | 438 disk_cache::Entry* entry1; |
439 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); | 439 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
440 | 440 |
441 const int kSize = 50; | 441 const int kSize = 50; |
442 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 442 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); |
443 memset(buffer1->data(), 0, kSize); | 443 memset(buffer1->data(), 0, kSize); |
444 base::strlcpy(buffer1->data(), "And the data to save", kSize); | 444 base::strlcpy(buffer1->data(), "And the data to save", kSize); |
445 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); | 445 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); |
446 entry1->Close(); | 446 entry1->Close(); |
447 ASSERT_TRUE(cache_->OpenEntry(key, &entry1)); | 447 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); |
448 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL)); | 448 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL)); |
449 | 449 |
450 SimulateCrash(); | 450 SimulateCrash(); |
451 | 451 |
452 EXPECT_FALSE(cache_->OpenEntry(key, &entry1)); | 452 EXPECT_NE(net::OK, OpenEntry(key, &entry1)); |
453 EXPECT_EQ(0, cache_->GetEntryCount()); | 453 EXPECT_EQ(0, cache_->GetEntryCount()); |
454 } | 454 } |
455 | 455 |
456 // We'll be leaking memory from this test. | 456 // We'll be leaking memory from this test. |
457 TEST_F(DiskCacheBackendTest, InvalidEntryRead) { | 457 TEST_F(DiskCacheBackendTest, InvalidEntryRead) { |
458 BackendInvalidEntryRead(); | 458 BackendInvalidEntryRead(); |
459 } | 459 } |
460 | 460 |
461 // We'll be leaking memory from this test. | 461 // We'll be leaking memory from this test. |
462 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntryRead) { | 462 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntryRead) { |
463 SetNewEviction(); | 463 SetNewEviction(); |
464 BackendInvalidEntryRead(); | 464 BackendInvalidEntryRead(); |
465 } | 465 } |
466 | 466 |
467 // We'll be leaking memory from this test. | 467 // We'll be leaking memory from this test. |
468 void DiskCacheBackendTest::BackendInvalidEntryWithLoad() { | 468 void DiskCacheBackendTest::BackendInvalidEntryWithLoad() { |
469 // Work with a tiny index table (16 entries) | 469 // Work with a tiny index table (16 entries) |
470 SetMask(0xf); | 470 SetMask(0xf); |
471 SetMaxSize(0x100000); | 471 SetMaxSize(0x100000); |
472 InitCache(); | 472 InitCache(); |
473 | 473 |
474 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 474 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
475 srand(seed); | 475 srand(seed); |
476 | 476 |
477 const int kNumEntries = 100; | 477 const int kNumEntries = 100; |
478 disk_cache::Entry* entries[kNumEntries]; | 478 disk_cache::Entry* entries[kNumEntries]; |
479 for (int i = 0; i < kNumEntries; i++) { | 479 for (int i = 0; i < kNumEntries; i++) { |
480 std::string key = GenerateKey(true); | 480 std::string key = GenerateKey(true); |
481 ASSERT_TRUE(cache_->CreateEntry(key, &entries[i])); | 481 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i])); |
482 } | 482 } |
483 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); | 483 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); |
484 | 484 |
485 for (int i = 0; i < kNumEntries; i++) { | 485 for (int i = 0; i < kNumEntries; i++) { |
486 int source1 = rand() % kNumEntries; | 486 int source1 = rand() % kNumEntries; |
487 int source2 = rand() % kNumEntries; | 487 int source2 = rand() % kNumEntries; |
488 disk_cache::Entry* temp = entries[source1]; | 488 disk_cache::Entry* temp = entries[source1]; |
489 entries[source1] = entries[source2]; | 489 entries[source1] = entries[source2]; |
490 entries[source2] = temp; | 490 entries[source2] = temp; |
491 } | 491 } |
492 | 492 |
493 std::string keys[kNumEntries]; | 493 std::string keys[kNumEntries]; |
494 for (int i = 0; i < kNumEntries; i++) { | 494 for (int i = 0; i < kNumEntries; i++) { |
495 keys[i] = entries[i]->GetKey(); | 495 keys[i] = entries[i]->GetKey(); |
496 if (i < kNumEntries / 2) | 496 if (i < kNumEntries / 2) |
497 entries[i]->Close(); | 497 entries[i]->Close(); |
498 } | 498 } |
499 | 499 |
500 SimulateCrash(); | 500 SimulateCrash(); |
501 | 501 |
502 for (int i = kNumEntries / 2; i < kNumEntries; i++) { | 502 for (int i = kNumEntries / 2; i < kNumEntries; i++) { |
503 disk_cache::Entry* entry; | 503 disk_cache::Entry* entry; |
504 EXPECT_FALSE(cache_->OpenEntry(keys[i], &entry)); | 504 EXPECT_NE(net::OK, OpenEntry(keys[i], &entry)); |
505 } | 505 } |
506 | 506 |
507 for (int i = 0; i < kNumEntries / 2; i++) { | 507 for (int i = 0; i < kNumEntries / 2; i++) { |
508 disk_cache::Entry* entry; | 508 disk_cache::Entry* entry; |
509 EXPECT_TRUE(cache_->OpenEntry(keys[i], &entry)); | 509 EXPECT_EQ(net::OK, OpenEntry(keys[i], &entry)); |
510 entry->Close(); | 510 entry->Close(); |
511 } | 511 } |
512 | 512 |
513 EXPECT_EQ(kNumEntries / 2, cache_->GetEntryCount()); | 513 EXPECT_EQ(kNumEntries / 2, cache_->GetEntryCount()); |
514 } | 514 } |
515 | 515 |
516 // We'll be leaking memory from this test. | 516 // We'll be leaking memory from this test. |
517 TEST_F(DiskCacheBackendTest, InvalidEntryWithLoad) { | 517 TEST_F(DiskCacheBackendTest, InvalidEntryWithLoad) { |
518 BackendInvalidEntryWithLoad(); | 518 BackendInvalidEntryWithLoad(); |
519 } | 519 } |
520 | 520 |
521 // We'll be leaking memory from this test. | 521 // We'll be leaking memory from this test. |
522 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntryWithLoad) { | 522 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntryWithLoad) { |
523 SetNewEviction(); | 523 SetNewEviction(); |
524 BackendInvalidEntryWithLoad(); | 524 BackendInvalidEntryWithLoad(); |
525 } | 525 } |
526 | 526 |
527 // We'll be leaking memory from this test. | 527 // We'll be leaking memory from this test. |
528 void DiskCacheBackendTest::BackendTrimInvalidEntry() { | 528 void DiskCacheBackendTest::BackendTrimInvalidEntry() { |
529 // Use the implementation directly... we need to simulate a crash. | 529 // Use the implementation directly... we need to simulate a crash. |
530 SetDirectMode(); | 530 SetDirectMode(); |
531 | 531 |
532 const int kSize = 0x3000; // 12 kB | 532 const int kSize = 0x3000; // 12 kB |
533 SetMaxSize(kSize * 10); | 533 SetMaxSize(kSize * 10); |
534 InitCache(); | 534 InitCache(); |
535 | 535 |
536 std::string first("some key"); | 536 std::string first("some key"); |
537 std::string second("something else"); | 537 std::string second("something else"); |
538 disk_cache::Entry* entry; | 538 disk_cache::Entry* entry; |
539 ASSERT_TRUE(cache_->CreateEntry(first, &entry)); | 539 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); |
540 | 540 |
541 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 541 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
542 memset(buffer->data(), 0, kSize); | 542 memset(buffer->data(), 0, kSize); |
543 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 543 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
544 | 544 |
545 // Simulate a crash. | 545 // Simulate a crash. |
546 SimulateCrash(); | 546 SimulateCrash(); |
547 | 547 |
548 ASSERT_TRUE(cache_->CreateEntry(second, &entry)); | 548 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
549 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 549 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
550 | 550 |
551 EXPECT_EQ(2, cache_->GetEntryCount()); | 551 EXPECT_EQ(2, cache_->GetEntryCount()); |
552 SetMaxSize(kSize); | 552 SetMaxSize(kSize); |
553 entry->Close(); // Trim the cache. | 553 entry->Close(); // Trim the cache. |
554 | 554 |
555 // If we evicted the entry in less than 20mS, we have one entry in the cache; | 555 // If we evicted the entry in less than 20mS, we have one entry in the cache; |
556 // if it took more than that, we posted a task and we'll delete the second | 556 // if it took more than that, we posted a task and we'll delete the second |
557 // entry too. | 557 // entry too. |
558 MessageLoop::current()->RunAllPending(); | 558 MessageLoop::current()->RunAllPending(); |
559 EXPECT_GE(1, cache_->GetEntryCount()); | 559 EXPECT_GE(1, cache_->GetEntryCount()); |
560 EXPECT_FALSE(cache_->OpenEntry(first, &entry)); | 560 EXPECT_NE(net::OK, OpenEntry(first, &entry)); |
561 } | 561 } |
562 | 562 |
563 // We'll be leaking memory from this test. | 563 // We'll be leaking memory from this test. |
564 TEST_F(DiskCacheBackendTest, TrimInvalidEntry) { | 564 TEST_F(DiskCacheBackendTest, TrimInvalidEntry) { |
565 BackendTrimInvalidEntry(); | 565 BackendTrimInvalidEntry(); |
566 } | 566 } |
567 | 567 |
568 // We'll be leaking memory from this test. | 568 // We'll be leaking memory from this test. |
569 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry) { | 569 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry) { |
570 SetNewEviction(); | 570 SetNewEviction(); |
(...skipping 10 matching lines...) Expand all Loading... |
581 SetMaxSize(kSize * 40); | 581 SetMaxSize(kSize * 40); |
582 InitCache(); | 582 InitCache(); |
583 | 583 |
584 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 584 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
585 memset(buffer->data(), 0, kSize); | 585 memset(buffer->data(), 0, kSize); |
586 disk_cache::Entry* entry; | 586 disk_cache::Entry* entry; |
587 | 587 |
588 // Writing 32 entries to this cache chains most of them. | 588 // Writing 32 entries to this cache chains most of them. |
589 for (int i = 0; i < 32; i++) { | 589 for (int i = 0; i < 32; i++) { |
590 std::string key(StringPrintf("some key %d", i)); | 590 std::string key(StringPrintf("some key %d", i)); |
591 ASSERT_TRUE(cache_->CreateEntry(key, &entry)); | 591 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
592 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 592 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
593 entry->Close(); | 593 entry->Close(); |
594 ASSERT_TRUE(cache_->OpenEntry(key, &entry)); | 594 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
595 // Note that we are not closing the entries. | 595 // Note that we are not closing the entries. |
596 } | 596 } |
597 | 597 |
598 // Simulate a crash. | 598 // Simulate a crash. |
599 SimulateCrash(); | 599 SimulateCrash(); |
600 | 600 |
601 ASSERT_TRUE(cache_->CreateEntry("Something else", &entry)); | 601 ASSERT_EQ(net::OK, CreateEntry("Something else", &entry)); |
602 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 602 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
603 | 603 |
604 EXPECT_EQ(33, cache_->GetEntryCount()); | 604 EXPECT_EQ(33, cache_->GetEntryCount()); |
605 SetMaxSize(kSize); | 605 SetMaxSize(kSize); |
606 | 606 |
607 // For the new eviction code, all corrupt entries are on the second list so | 607 // For the new eviction code, all corrupt entries are on the second list so |
608 // they are not going away that easy. | 608 // they are not going away that easy. |
609 if (new_eviction_) | 609 if (new_eviction_) { |
610 cache_->DoomAllEntries(); | 610 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 611 } |
611 | 612 |
612 entry->Close(); // Trim the cache. | 613 entry->Close(); // Trim the cache. |
613 | 614 |
614 // We may abort the eviction before cleaning up everything. | 615 // We may abort the eviction before cleaning up everything. |
615 MessageLoop::current()->RunAllPending(); | 616 MessageLoop::current()->RunAllPending(); |
616 EXPECT_GE(30, cache_->GetEntryCount()); | 617 EXPECT_GE(30, cache_->GetEntryCount()); |
617 } | 618 } |
618 | 619 |
619 // We'll be leaking memory from this test. | 620 // We'll be leaking memory from this test. |
620 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { | 621 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { |
621 BackendTrimInvalidEntry2(); | 622 BackendTrimInvalidEntry2(); |
622 } | 623 } |
623 | 624 |
624 // We'll be leaking memory from this test. | 625 // We'll be leaking memory from this test. |
625 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry2) { | 626 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry2) { |
626 SetNewEviction(); | 627 SetNewEviction(); |
627 BackendTrimInvalidEntry2(); | 628 BackendTrimInvalidEntry2(); |
628 } | 629 } |
629 | 630 |
630 void DiskCacheBackendTest::BackendEnumerations() { | 631 void DiskCacheBackendTest::BackendEnumerations() { |
631 InitCache(); | 632 InitCache(); |
632 Time initial = Time::Now(); | 633 Time initial = Time::Now(); |
633 int seed = static_cast<int>(initial.ToInternalValue()); | 634 int seed = static_cast<int>(initial.ToInternalValue()); |
634 srand(seed); | 635 srand(seed); |
635 | 636 |
636 const int kNumEntries = 100; | 637 const int kNumEntries = 100; |
637 for (int i = 0; i < kNumEntries; i++) { | 638 for (int i = 0; i < kNumEntries; i++) { |
638 std::string key = GenerateKey(true); | 639 std::string key = GenerateKey(true); |
639 disk_cache::Entry* entry; | 640 disk_cache::Entry* entry; |
640 ASSERT_TRUE(cache_->CreateEntry(key, &entry)); | 641 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
641 entry->Close(); | 642 entry->Close(); |
642 } | 643 } |
643 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); | 644 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); |
644 Time final = Time::Now(); | 645 Time final = Time::Now(); |
645 | 646 |
646 disk_cache::Entry* entry; | 647 disk_cache::Entry* entry; |
647 void* iter = NULL; | 648 void* iter = NULL; |
648 int count = 0; | 649 int count = 0; |
649 Time last_modified[kNumEntries]; | 650 Time last_modified[kNumEntries]; |
650 Time last_used[kNumEntries]; | 651 Time last_used[kNumEntries]; |
651 while (cache_->OpenNextEntry(&iter, &entry)) { | 652 while (OpenNextEntry(&iter, &entry) == net::OK) { |
652 ASSERT_TRUE(NULL != entry); | 653 ASSERT_TRUE(NULL != entry); |
653 if (count < kNumEntries) { | 654 if (count < kNumEntries) { |
654 last_modified[count] = entry->GetLastModified(); | 655 last_modified[count] = entry->GetLastModified(); |
655 last_used[count] = entry->GetLastUsed(); | 656 last_used[count] = entry->GetLastUsed(); |
656 EXPECT_TRUE(initial <= last_modified[count]); | 657 EXPECT_TRUE(initial <= last_modified[count]); |
657 EXPECT_TRUE(final >= last_modified[count]); | 658 EXPECT_TRUE(final >= last_modified[count]); |
658 } | 659 } |
659 | 660 |
660 entry->Close(); | 661 entry->Close(); |
661 count++; | 662 count++; |
662 }; | 663 }; |
663 EXPECT_EQ(kNumEntries, count); | 664 EXPECT_EQ(kNumEntries, count); |
664 | 665 |
665 iter = NULL; | 666 iter = NULL; |
666 count = 0; | 667 count = 0; |
667 // The previous enumeration should not have changed the timestamps. | 668 // The previous enumeration should not have changed the timestamps. |
668 while (cache_->OpenNextEntry(&iter, &entry)) { | 669 while (OpenNextEntry(&iter, &entry) == net::OK) { |
669 ASSERT_TRUE(NULL != entry); | 670 ASSERT_TRUE(NULL != entry); |
670 if (count < kNumEntries) { | 671 if (count < kNumEntries) { |
671 EXPECT_TRUE(last_modified[count] == entry->GetLastModified()); | 672 EXPECT_TRUE(last_modified[count] == entry->GetLastModified()); |
672 EXPECT_TRUE(last_used[count] == entry->GetLastUsed()); | 673 EXPECT_TRUE(last_used[count] == entry->GetLastUsed()); |
673 } | 674 } |
674 entry->Close(); | 675 entry->Close(); |
675 count++; | 676 count++; |
676 }; | 677 }; |
677 EXPECT_EQ(kNumEntries, count); | 678 EXPECT_EQ(kNumEntries, count); |
678 } | 679 } |
(...skipping 11 matching lines...) Expand all Loading... |
690 SetMemoryOnlyMode(); | 691 SetMemoryOnlyMode(); |
691 BackendEnumerations(); | 692 BackendEnumerations(); |
692 } | 693 } |
693 | 694 |
694 // Verifies enumerations while entries are open. | 695 // Verifies enumerations while entries are open. |
695 void DiskCacheBackendTest::BackendEnumerations2() { | 696 void DiskCacheBackendTest::BackendEnumerations2() { |
696 InitCache(); | 697 InitCache(); |
697 const std::string first("first"); | 698 const std::string first("first"); |
698 const std::string second("second"); | 699 const std::string second("second"); |
699 disk_cache::Entry *entry1, *entry2; | 700 disk_cache::Entry *entry1, *entry2; |
700 ASSERT_TRUE(cache_->CreateEntry(first, &entry1)); | 701 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); |
701 entry1->Close(); | 702 entry1->Close(); |
702 ASSERT_TRUE(cache_->CreateEntry(second, &entry2)); | 703 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); |
703 entry2->Close(); | 704 entry2->Close(); |
704 | 705 |
705 // Make sure that the timestamp is not the same. | 706 // Make sure that the timestamp is not the same. |
706 PlatformThread::Sleep(20); | 707 PlatformThread::Sleep(20); |
707 ASSERT_TRUE(cache_->OpenEntry(second, &entry1)); | 708 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); |
708 void* iter = NULL; | 709 void* iter = NULL; |
709 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry2)); | 710 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); |
710 ASSERT_EQ(entry2->GetKey(), second); | 711 ASSERT_EQ(entry2->GetKey(), second); |
711 | 712 |
712 // Two entries and the iterator pointing at "first". | 713 // Two entries and the iterator pointing at "first". |
713 entry1->Close(); | 714 entry1->Close(); |
714 entry2->Close(); | 715 entry2->Close(); |
715 | 716 |
716 // The iterator should still be valid, se we should not crash. | 717 // The iterator should still be valid, so we should not crash. |
717 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry2)); | 718 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); |
718 ASSERT_EQ(entry2->GetKey(), first); | 719 ASSERT_EQ(entry2->GetKey(), first); |
719 entry2->Close(); | 720 entry2->Close(); |
720 cache_->EndEnumeration(&iter); | 721 cache_->EndEnumeration(&iter); |
721 } | 722 } |
722 | 723 |
723 TEST_F(DiskCacheBackendTest, Enumerations2) { | 724 TEST_F(DiskCacheBackendTest, Enumerations2) { |
724 BackendEnumerations2(); | 725 BackendEnumerations2(); |
725 } | 726 } |
726 | 727 |
727 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { | 728 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { |
728 SetNewEviction(); | 729 SetNewEviction(); |
729 BackendEnumerations2(); | 730 BackendEnumerations2(); |
730 } | 731 } |
731 | 732 |
732 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) { | 733 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) { |
733 SetMemoryOnlyMode(); | 734 SetMemoryOnlyMode(); |
734 BackendEnumerations2(); | 735 BackendEnumerations2(); |
735 } | 736 } |
736 | 737 |
737 | 738 |
738 // Verify handling of invalid entries while doing enumerations. | 739 // Verify handling of invalid entries while doing enumerations. |
739 // We'll be leaking memory from this test. | 740 // We'll be leaking memory from this test. |
740 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { | 741 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { |
741 // Use the implementation directly... we need to simulate a crash. | 742 // Use the implementation directly... we need to simulate a crash. |
742 SetDirectMode(); | 743 SetDirectMode(); |
743 InitCache(); | 744 InitCache(); |
744 | 745 |
745 std::string key("Some key"); | 746 std::string key("Some key"); |
746 disk_cache::Entry *entry, *entry1, *entry2; | 747 disk_cache::Entry *entry, *entry1, *entry2; |
747 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); | 748 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
748 | 749 |
749 const int kSize = 50; | 750 const int kSize = 50; |
750 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 751 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); |
751 memset(buffer1->data(), 0, kSize); | 752 memset(buffer1->data(), 0, kSize); |
752 base::strlcpy(buffer1->data(), "And the data to save", kSize); | 753 base::strlcpy(buffer1->data(), "And the data to save", kSize); |
753 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); | 754 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); |
754 entry1->Close(); | 755 entry1->Close(); |
755 ASSERT_TRUE(cache_->OpenEntry(key, &entry1)); | 756 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); |
756 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL)); | 757 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL)); |
757 | 758 |
758 std::string key2("Another key"); | 759 std::string key2("Another key"); |
759 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2)); | 760 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); |
760 entry2->Close(); | 761 entry2->Close(); |
761 ASSERT_EQ(2, cache_->GetEntryCount()); | 762 ASSERT_EQ(2, cache_->GetEntryCount()); |
762 | 763 |
763 SimulateCrash(); | 764 SimulateCrash(); |
764 | 765 |
765 void* iter = NULL; | 766 void* iter = NULL; |
766 int count = 0; | 767 int count = 0; |
767 while (cache_->OpenNextEntry(&iter, &entry)) { | 768 while (OpenNextEntry(&iter, &entry) == net::OK) { |
768 ASSERT_TRUE(NULL != entry); | 769 ASSERT_TRUE(NULL != entry); |
769 EXPECT_EQ(key2, entry->GetKey()); | 770 EXPECT_EQ(key2, entry->GetKey()); |
770 entry->Close(); | 771 entry->Close(); |
771 count++; | 772 count++; |
772 }; | 773 }; |
773 EXPECT_EQ(1, count); | 774 EXPECT_EQ(1, count); |
774 EXPECT_EQ(1, cache_->GetEntryCount()); | 775 EXPECT_EQ(1, cache_->GetEntryCount()); |
775 } | 776 } |
776 | 777 |
777 // We'll be leaking memory from this test. | 778 // We'll be leaking memory from this test. |
(...skipping 12 matching lines...) Expand all Loading... |
790 void DiskCacheBackendTest::BackendFixEnumerators() { | 791 void DiskCacheBackendTest::BackendFixEnumerators() { |
791 InitCache(); | 792 InitCache(); |
792 | 793 |
793 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 794 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
794 srand(seed); | 795 srand(seed); |
795 | 796 |
796 const int kNumEntries = 10; | 797 const int kNumEntries = 10; |
797 for (int i = 0; i < kNumEntries; i++) { | 798 for (int i = 0; i < kNumEntries; i++) { |
798 std::string key = GenerateKey(true); | 799 std::string key = GenerateKey(true); |
799 disk_cache::Entry* entry; | 800 disk_cache::Entry* entry; |
800 ASSERT_TRUE(cache_->CreateEntry(key, &entry)); | 801 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
801 entry->Close(); | 802 entry->Close(); |
802 } | 803 } |
803 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); | 804 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); |
804 | 805 |
805 disk_cache::Entry *entry1, *entry2; | 806 disk_cache::Entry *entry1, *entry2; |
806 void* iter1 = NULL; | 807 void* iter1 = NULL; |
807 void* iter2 = NULL; | 808 void* iter2 = NULL; |
808 ASSERT_TRUE(cache_->OpenNextEntry(&iter1, &entry1)); | 809 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1)); |
809 ASSERT_TRUE(NULL != entry1); | 810 ASSERT_TRUE(NULL != entry1); |
810 entry1->Close(); | 811 entry1->Close(); |
811 entry1 = NULL; | 812 entry1 = NULL; |
812 | 813 |
813 // Let's go to the middle of the list. | 814 // Let's go to the middle of the list. |
814 for (int i = 0; i < kNumEntries / 2; i++) { | 815 for (int i = 0; i < kNumEntries / 2; i++) { |
815 if (entry1) | 816 if (entry1) |
816 entry1->Close(); | 817 entry1->Close(); |
817 ASSERT_TRUE(cache_->OpenNextEntry(&iter1, &entry1)); | 818 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1)); |
818 ASSERT_TRUE(NULL != entry1); | 819 ASSERT_TRUE(NULL != entry1); |
819 | 820 |
820 ASSERT_TRUE(cache_->OpenNextEntry(&iter2, &entry2)); | 821 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2)); |
821 ASSERT_TRUE(NULL != entry2); | 822 ASSERT_TRUE(NULL != entry2); |
822 entry2->Close(); | 823 entry2->Close(); |
823 } | 824 } |
824 | 825 |
825 // Messing up with entry1 will modify entry2->next. | 826 // Messing up with entry1 will modify entry2->next. |
826 entry1->Doom(); | 827 entry1->Doom(); |
827 ASSERT_TRUE(cache_->OpenNextEntry(&iter2, &entry2)); | 828 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2)); |
828 ASSERT_TRUE(NULL != entry2); | 829 ASSERT_TRUE(NULL != entry2); |
829 | 830 |
830 // The link entry2->entry1 should be broken. | 831 // The link entry2->entry1 should be broken. |
831 EXPECT_NE(entry2->GetKey(), entry1->GetKey()); | 832 EXPECT_NE(entry2->GetKey(), entry1->GetKey()); |
832 entry1->Close(); | 833 entry1->Close(); |
833 entry2->Close(); | 834 entry2->Close(); |
834 | 835 |
835 // And the second iterator should keep working. | 836 // And the second iterator should keep working. |
836 ASSERT_TRUE(cache_->OpenNextEntry(&iter2, &entry2)); | 837 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2)); |
837 ASSERT_TRUE(NULL != entry2); | 838 ASSERT_TRUE(NULL != entry2); |
838 entry2->Close(); | 839 entry2->Close(); |
839 | 840 |
840 cache_->EndEnumeration(&iter1); | 841 cache_->EndEnumeration(&iter1); |
841 cache_->EndEnumeration(&iter2); | 842 cache_->EndEnumeration(&iter2); |
842 } | 843 } |
843 | 844 |
844 TEST_F(DiskCacheBackendTest, FixEnumerators) { | 845 TEST_F(DiskCacheBackendTest, FixEnumerators) { |
845 BackendFixEnumerators(); | 846 BackendFixEnumerators(); |
846 } | 847 } |
847 | 848 |
848 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) { | 849 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) { |
849 SetNewEviction(); | 850 SetNewEviction(); |
850 BackendFixEnumerators(); | 851 BackendFixEnumerators(); |
851 } | 852 } |
852 | 853 |
853 void DiskCacheBackendTest::BackendDoomRecent() { | 854 void DiskCacheBackendTest::BackendDoomRecent() { |
854 InitCache(); | 855 InitCache(); |
855 Time initial = Time::Now(); | 856 Time initial = Time::Now(); |
856 | 857 |
857 disk_cache::Entry *entry; | 858 disk_cache::Entry *entry; |
858 ASSERT_TRUE(cache_->CreateEntry("first", &entry)); | 859 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); |
859 entry->Close(); | 860 entry->Close(); |
860 ASSERT_TRUE(cache_->CreateEntry("second", &entry)); | 861 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); |
861 entry->Close(); | 862 entry->Close(); |
862 | 863 |
863 PlatformThread::Sleep(20); | 864 PlatformThread::Sleep(20); |
864 Time middle = Time::Now(); | 865 Time middle = Time::Now(); |
865 | 866 |
866 ASSERT_TRUE(cache_->CreateEntry("third", &entry)); | 867 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); |
867 entry->Close(); | 868 entry->Close(); |
868 ASSERT_TRUE(cache_->CreateEntry("fourth", &entry)); | 869 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry)); |
869 entry->Close(); | 870 entry->Close(); |
870 | 871 |
871 PlatformThread::Sleep(20); | 872 PlatformThread::Sleep(20); |
872 Time final = Time::Now(); | 873 Time final = Time::Now(); |
873 | 874 |
874 ASSERT_EQ(4, cache_->GetEntryCount()); | 875 ASSERT_EQ(4, cache_->GetEntryCount()); |
875 EXPECT_TRUE(cache_->DoomEntriesSince(final)); | 876 EXPECT_EQ(net::OK, DoomEntriesSince(final)); |
876 ASSERT_EQ(4, cache_->GetEntryCount()); | 877 ASSERT_EQ(4, cache_->GetEntryCount()); |
877 | 878 |
878 EXPECT_TRUE(cache_->DoomEntriesSince(middle)); | 879 EXPECT_EQ(net::OK, DoomEntriesSince(middle)); |
879 ASSERT_EQ(2, cache_->GetEntryCount()); | 880 ASSERT_EQ(2, cache_->GetEntryCount()); |
880 | 881 |
881 ASSERT_TRUE(cache_->OpenEntry("second", &entry)); | 882 ASSERT_EQ(net::OK, OpenEntry("second", &entry)); |
882 entry->Close(); | 883 entry->Close(); |
883 } | 884 } |
884 | 885 |
885 TEST_F(DiskCacheBackendTest, DoomRecent) { | 886 TEST_F(DiskCacheBackendTest, DoomRecent) { |
886 BackendDoomRecent(); | 887 BackendDoomRecent(); |
887 } | 888 } |
888 | 889 |
889 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { | 890 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { |
890 SetNewEviction(); | 891 SetNewEviction(); |
891 BackendDoomRecent(); | 892 BackendDoomRecent(); |
892 } | 893 } |
893 | 894 |
894 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { | 895 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { |
895 SetMemoryOnlyMode(); | 896 SetMemoryOnlyMode(); |
896 BackendDoomRecent(); | 897 BackendDoomRecent(); |
897 } | 898 } |
898 | 899 |
899 void DiskCacheBackendTest::BackendDoomBetween() { | 900 void DiskCacheBackendTest::BackendDoomBetween() { |
900 InitCache(); | 901 InitCache(); |
901 Time initial = Time::Now(); | 902 Time initial = Time::Now(); |
902 | 903 |
903 disk_cache::Entry *entry; | 904 disk_cache::Entry *entry; |
904 ASSERT_TRUE(cache_->CreateEntry("first", &entry)); | 905 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); |
905 entry->Close(); | 906 entry->Close(); |
906 | 907 |
907 PlatformThread::Sleep(20); | 908 PlatformThread::Sleep(20); |
908 Time middle_start = Time::Now(); | 909 Time middle_start = Time::Now(); |
909 | 910 |
910 ASSERT_TRUE(cache_->CreateEntry("second", &entry)); | 911 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); |
911 entry->Close(); | 912 entry->Close(); |
912 ASSERT_TRUE(cache_->CreateEntry("third", &entry)); | 913 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); |
913 entry->Close(); | 914 entry->Close(); |
914 | 915 |
915 PlatformThread::Sleep(20); | 916 PlatformThread::Sleep(20); |
916 Time middle_end = Time::Now(); | 917 Time middle_end = Time::Now(); |
917 | 918 |
918 ASSERT_TRUE(cache_->CreateEntry("fourth", &entry)); | 919 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry)); |
919 entry->Close(); | 920 entry->Close(); |
920 ASSERT_TRUE(cache_->OpenEntry("fourth", &entry)); | 921 ASSERT_EQ(net::OK, OpenEntry("fourth", &entry)); |
921 entry->Close(); | 922 entry->Close(); |
922 | 923 |
923 PlatformThread::Sleep(20); | 924 PlatformThread::Sleep(20); |
924 Time final = Time::Now(); | 925 Time final = Time::Now(); |
925 | 926 |
926 ASSERT_EQ(4, cache_->GetEntryCount()); | 927 ASSERT_EQ(4, cache_->GetEntryCount()); |
927 EXPECT_TRUE(cache_->DoomEntriesBetween(middle_start, middle_end)); | 928 EXPECT_EQ(net::OK, DoomEntriesBetween(middle_start, middle_end)); |
928 ASSERT_EQ(2, cache_->GetEntryCount()); | 929 ASSERT_EQ(2, cache_->GetEntryCount()); |
929 | 930 |
930 ASSERT_TRUE(cache_->OpenEntry("fourth", &entry)); | 931 ASSERT_EQ(net::OK, OpenEntry("fourth", &entry)); |
931 entry->Close(); | 932 entry->Close(); |
932 | 933 |
933 EXPECT_TRUE(cache_->DoomEntriesBetween(middle_start, final)); | 934 EXPECT_EQ(net::OK, DoomEntriesBetween(middle_start, final)); |
934 ASSERT_EQ(1, cache_->GetEntryCount()); | 935 ASSERT_EQ(1, cache_->GetEntryCount()); |
935 | 936 |
936 ASSERT_TRUE(cache_->OpenEntry("first", &entry)); | 937 ASSERT_EQ(net::OK, OpenEntry("first", &entry)); |
937 entry->Close(); | 938 entry->Close(); |
938 } | 939 } |
939 | 940 |
940 TEST_F(DiskCacheBackendTest, DoomBetween) { | 941 TEST_F(DiskCacheBackendTest, DoomBetween) { |
941 BackendDoomBetween(); | 942 BackendDoomBetween(); |
942 } | 943 } |
943 | 944 |
944 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { | 945 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { |
945 SetNewEviction(); | 946 SetNewEviction(); |
946 BackendDoomBetween(); | 947 BackendDoomBetween(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 helper.WaitUntilCacheIoFinished(1); | 1091 helper.WaitUntilCacheIoFinished(1); |
1091 } | 1092 } |
1092 | 1093 |
1093 // We want to be able to deal with messed up entries on disk. | 1094 // We want to be able to deal with messed up entries on disk. |
1094 void DiskCacheBackendTest::BackendInvalidEntry2() { | 1095 void DiskCacheBackendTest::BackendInvalidEntry2() { |
1095 ASSERT_TRUE(CopyTestCache(L"bad_entry")); | 1096 ASSERT_TRUE(CopyTestCache(L"bad_entry")); |
1096 DisableFirstCleanup(); | 1097 DisableFirstCleanup(); |
1097 InitCache(); | 1098 InitCache(); |
1098 | 1099 |
1099 disk_cache::Entry *entry1, *entry2; | 1100 disk_cache::Entry *entry1, *entry2; |
1100 ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1)); | 1101 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); |
1101 EXPECT_FALSE(cache_->OpenEntry("some other key", &entry2)); | 1102 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); |
1102 entry1->Close(); | 1103 entry1->Close(); |
1103 | 1104 |
1104 // CheckCacheIntegrity will fail at this point. | 1105 // CheckCacheIntegrity will fail at this point. |
1105 DisableIntegrityCheck(); | 1106 DisableIntegrityCheck(); |
1106 } | 1107 } |
1107 | 1108 |
1108 TEST_F(DiskCacheBackendTest, InvalidEntry2) { | 1109 TEST_F(DiskCacheBackendTest, InvalidEntry2) { |
1109 BackendInvalidEntry2(); | 1110 BackendInvalidEntry2(); |
1110 } | 1111 } |
1111 | 1112 |
1112 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { | 1113 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { |
1113 SetNewEviction(); | 1114 SetNewEviction(); |
1114 BackendInvalidEntry2(); | 1115 BackendInvalidEntry2(); |
1115 } | 1116 } |
1116 | 1117 |
1117 // We want to be able to deal with abnormal dirty entries. | 1118 // We want to be able to deal with abnormal dirty entries. |
1118 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::wstring& name) { | 1119 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::wstring& name) { |
1119 ASSERT_TRUE(CopyTestCache(name)); | 1120 ASSERT_TRUE(CopyTestCache(name)); |
1120 DisableFirstCleanup(); | 1121 DisableFirstCleanup(); |
1121 InitCache(); | 1122 InitCache(); |
1122 | 1123 |
1123 disk_cache::Entry *entry1, *entry2; | 1124 disk_cache::Entry *entry1, *entry2; |
1124 ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1)); | 1125 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); |
1125 EXPECT_FALSE(cache_->OpenEntry("some other key", &entry2)); | 1126 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); |
1126 entry1->Close(); | 1127 entry1->Close(); |
1127 } | 1128 } |
1128 | 1129 |
1129 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) { | 1130 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) { |
1130 BackendNotMarkedButDirty(L"dirty_entry"); | 1131 BackendNotMarkedButDirty(L"dirty_entry"); |
1131 } | 1132 } |
1132 | 1133 |
1133 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) { | 1134 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) { |
1134 SetNewEviction(); | 1135 SetNewEviction(); |
1135 BackendNotMarkedButDirty(L"dirty_entry"); | 1136 BackendNotMarkedButDirty(L"dirty_entry"); |
1136 } | 1137 } |
1137 | 1138 |
1138 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) { | 1139 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) { |
1139 BackendNotMarkedButDirty(L"dirty_entry2"); | 1140 BackendNotMarkedButDirty(L"dirty_entry2"); |
1140 } | 1141 } |
1141 | 1142 |
1142 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { | 1143 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { |
1143 SetNewEviction(); | 1144 SetNewEviction(); |
1144 BackendNotMarkedButDirty(L"dirty_entry2"); | 1145 BackendNotMarkedButDirty(L"dirty_entry2"); |
1145 } | 1146 } |
1146 | 1147 |
1147 // We want to be able to deal with messed up entries on disk. | 1148 // We want to be able to deal with messed up entries on disk. |
1148 void DiskCacheBackendTest::BackendInvalidRankings2() { | 1149 void DiskCacheBackendTest::BackendInvalidRankings2() { |
1149 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1150 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1150 FilePath path = GetCacheFilePath(); | 1151 FilePath path = GetCacheFilePath(); |
1151 DisableFirstCleanup(); | 1152 DisableFirstCleanup(); |
1152 InitCache(); | 1153 InitCache(); |
1153 | 1154 |
1154 disk_cache::Entry *entry1, *entry2; | 1155 disk_cache::Entry *entry1, *entry2; |
1155 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); | 1156 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); |
1156 ASSERT_TRUE(cache_->OpenEntry("some other key", &entry2)); | 1157 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); |
1157 entry2->Close(); | 1158 entry2->Close(); |
1158 | 1159 |
1159 // CheckCacheIntegrity will fail at this point. | 1160 // CheckCacheIntegrity will fail at this point. |
1160 DisableIntegrityCheck(); | 1161 DisableIntegrityCheck(); |
1161 } | 1162 } |
1162 | 1163 |
1163 TEST_F(DiskCacheBackendTest, InvalidRankings2) { | 1164 TEST_F(DiskCacheBackendTest, InvalidRankings2) { |
1164 BackendInvalidRankings2(); | 1165 BackendInvalidRankings2(); |
1165 } | 1166 } |
1166 | 1167 |
1167 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) { | 1168 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) { |
1168 SetNewEviction(); | 1169 SetNewEviction(); |
1169 BackendInvalidRankings2(); | 1170 BackendInvalidRankings2(); |
1170 } | 1171 } |
1171 | 1172 |
1172 // If the LRU is corrupt, we delete the cache. | 1173 // If the LRU is corrupt, we delete the cache. |
1173 void DiskCacheBackendTest::BackendInvalidRankings() { | 1174 void DiskCacheBackendTest::BackendInvalidRankings() { |
1174 disk_cache::Entry* entry; | 1175 disk_cache::Entry* entry; |
1175 void* iter = NULL; | 1176 void* iter = NULL; |
1176 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry)); | 1177 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); |
1177 entry->Close(); | 1178 entry->Close(); |
1178 EXPECT_EQ(2, cache_->GetEntryCount()); | 1179 EXPECT_EQ(2, cache_->GetEntryCount()); |
1179 | 1180 |
1180 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry)); | 1181 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); |
1181 MessageLoop::current()->RunAllPending(); | 1182 MessageLoop::current()->RunAllPending(); |
1182 EXPECT_EQ(0, cache_->GetEntryCount()); | 1183 EXPECT_EQ(0, cache_->GetEntryCount()); |
1183 } | 1184 } |
1184 | 1185 |
1185 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 1186 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
1186 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1187 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1187 DisableFirstCleanup(); | 1188 DisableFirstCleanup(); |
1188 SetDirectMode(); | 1189 SetDirectMode(); |
1189 InitCache(); | 1190 InitCache(); |
1190 BackendInvalidRankings(); | 1191 BackendInvalidRankings(); |
(...skipping 24 matching lines...) Expand all Loading... |
1215 SetNewEviction(); | 1216 SetNewEviction(); |
1216 InitCache(); | 1217 InitCache(); |
1217 SetTestMode(); // Fail cache reinitialization. | 1218 SetTestMode(); // Fail cache reinitialization. |
1218 BackendInvalidRankings(); | 1219 BackendInvalidRankings(); |
1219 } | 1220 } |
1220 | 1221 |
1221 // If the LRU is corrupt and we have open entries, we disable the cache. | 1222 // If the LRU is corrupt and we have open entries, we disable the cache. |
1222 void DiskCacheBackendTest::BackendDisable() { | 1223 void DiskCacheBackendTest::BackendDisable() { |
1223 disk_cache::Entry *entry1, *entry2; | 1224 disk_cache::Entry *entry1, *entry2; |
1224 void* iter = NULL; | 1225 void* iter = NULL; |
1225 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); | 1226 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1226 | 1227 |
1227 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); | 1228 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1228 EXPECT_EQ(2, cache_->GetEntryCount()); | 1229 EXPECT_EQ(2, cache_->GetEntryCount()); |
1229 EXPECT_FALSE(cache_->CreateEntry("Something new", &entry2)); | 1230 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); |
1230 | 1231 |
1231 entry1->Close(); | 1232 entry1->Close(); |
1232 MessageLoop::current()->RunAllPending(); | 1233 MessageLoop::current()->RunAllPending(); |
1233 | 1234 |
1234 EXPECT_EQ(0, cache_->GetEntryCount()); | 1235 EXPECT_EQ(0, cache_->GetEntryCount()); |
1235 } | 1236 } |
1236 | 1237 |
1237 TEST_F(DiskCacheBackendTest, DisableSuccess) { | 1238 TEST_F(DiskCacheBackendTest, DisableSuccess) { |
1238 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1239 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1239 DisableFirstCleanup(); | 1240 DisableFirstCleanup(); |
(...skipping 30 matching lines...) Expand all Loading... |
1270 BackendDisable(); | 1271 BackendDisable(); |
1271 } | 1272 } |
1272 | 1273 |
1273 // This is another type of corruption on the LRU; disable the cache. | 1274 // This is another type of corruption on the LRU; disable the cache. |
1274 void DiskCacheBackendTest::BackendDisable2() { | 1275 void DiskCacheBackendTest::BackendDisable2() { |
1275 EXPECT_EQ(8, cache_->GetEntryCount()); | 1276 EXPECT_EQ(8, cache_->GetEntryCount()); |
1276 | 1277 |
1277 disk_cache::Entry* entry; | 1278 disk_cache::Entry* entry; |
1278 void* iter = NULL; | 1279 void* iter = NULL; |
1279 int count = 0; | 1280 int count = 0; |
1280 while (cache_->OpenNextEntry(&iter, &entry)) { | 1281 while (OpenNextEntry(&iter, &entry) == net::OK) { |
1281 ASSERT_TRUE(NULL != entry); | 1282 ASSERT_TRUE(NULL != entry); |
1282 entry->Close(); | 1283 entry->Close(); |
1283 count++; | 1284 count++; |
1284 ASSERT_LT(count, 9); | 1285 ASSERT_LT(count, 9); |
1285 }; | 1286 }; |
1286 | 1287 |
1287 MessageLoop::current()->RunAllPending(); | 1288 MessageLoop::current()->RunAllPending(); |
1288 EXPECT_EQ(0, cache_->GetEntryCount()); | 1289 EXPECT_EQ(0, cache_->GetEntryCount()); |
1289 } | 1290 } |
1290 | 1291 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 InitCache(); | 1323 InitCache(); |
1323 SetTestMode(); // Fail cache reinitialization. | 1324 SetTestMode(); // Fail cache reinitialization. |
1324 BackendDisable2(); | 1325 BackendDisable2(); |
1325 } | 1326 } |
1326 | 1327 |
1327 // If the index size changes when we disable the cache, we should not crash. | 1328 // If the index size changes when we disable the cache, we should not crash. |
1328 void DiskCacheBackendTest::BackendDisable3() { | 1329 void DiskCacheBackendTest::BackendDisable3() { |
1329 disk_cache::Entry *entry1, *entry2; | 1330 disk_cache::Entry *entry1, *entry2; |
1330 void* iter = NULL; | 1331 void* iter = NULL; |
1331 EXPECT_EQ(2, cache_->GetEntryCount()); | 1332 EXPECT_EQ(2, cache_->GetEntryCount()); |
1332 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); | 1333 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1333 entry1->Close(); | 1334 entry1->Close(); |
1334 | 1335 |
1335 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); | 1336 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1336 MessageLoop::current()->RunAllPending(); | 1337 MessageLoop::current()->RunAllPending(); |
1337 | 1338 |
1338 ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2)); | 1339 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); |
1339 entry2->Close(); | 1340 entry2->Close(); |
1340 | 1341 |
1341 EXPECT_EQ(1, cache_->GetEntryCount()); | 1342 EXPECT_EQ(1, cache_->GetEntryCount()); |
1342 } | 1343 } |
1343 | 1344 |
1344 TEST_F(DiskCacheBackendTest, DisableSuccess3) { | 1345 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
1345 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1346 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
1346 DisableFirstCleanup(); | 1347 DisableFirstCleanup(); |
1347 SetMaxSize(20 * 1024 * 1024); | 1348 SetMaxSize(20 * 1024 * 1024); |
1348 InitCache(); | 1349 InitCache(); |
1349 BackendDisable3(); | 1350 BackendDisable3(); |
1350 } | 1351 } |
1351 | 1352 |
1352 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { | 1353 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { |
1353 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1354 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
1354 DisableFirstCleanup(); | 1355 DisableFirstCleanup(); |
1355 SetMaxSize(20 * 1024 * 1024); | 1356 SetMaxSize(20 * 1024 * 1024); |
1356 SetNewEviction(); | 1357 SetNewEviction(); |
1357 InitCache(); | 1358 InitCache(); |
1358 BackendDisable3(); | 1359 BackendDisable3(); |
1359 } | 1360 } |
1360 | 1361 |
1361 // If we disable the cache, already open entries should work as far as possible. | 1362 // If we disable the cache, already open entries should work as far as possible. |
1362 void DiskCacheBackendTest::BackendDisable4() { | 1363 void DiskCacheBackendTest::BackendDisable4() { |
1363 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; | 1364 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; |
1364 void* iter = NULL; | 1365 void* iter = NULL; |
1365 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); | 1366 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1366 | 1367 |
1367 char key2[2000]; | 1368 char key2[2000]; |
1368 char key3[20000]; | 1369 char key3[20000]; |
1369 CacheTestFillBuffer(key2, sizeof(key2), true); | 1370 CacheTestFillBuffer(key2, sizeof(key2), true); |
1370 CacheTestFillBuffer(key3, sizeof(key3), true); | 1371 CacheTestFillBuffer(key3, sizeof(key3), true); |
1371 key2[sizeof(key2) - 1] = '\0'; | 1372 key2[sizeof(key2) - 1] = '\0'; |
1372 key3[sizeof(key3) - 1] = '\0'; | 1373 key3[sizeof(key3) - 1] = '\0'; |
1373 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2)); | 1374 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); |
1374 ASSERT_TRUE(cache_->CreateEntry(key3, &entry3)); | 1375 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3)); |
1375 | 1376 |
1376 const int kBufSize = 20000; | 1377 const int kBufSize = 20000; |
1377 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kBufSize); | 1378 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kBufSize); |
1378 memset(buf->data(), 0, kBufSize); | 1379 memset(buf->data(), 0, kBufSize); |
1379 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); | 1380 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); |
1380 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); | 1381 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); |
1381 | 1382 |
1382 // This line should disable the cache but not delete it. | 1383 // This line should disable the cache but not delete it. |
1383 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry4)); | 1384 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry4)); |
1384 EXPECT_EQ(4, cache_->GetEntryCount()); | 1385 EXPECT_EQ(4, cache_->GetEntryCount()); |
1385 | 1386 |
1386 EXPECT_FALSE(cache_->CreateEntry("cache is disabled", &entry4)); | 1387 EXPECT_NE(net::OK, CreateEntry("cache is disabled", &entry4)); |
1387 | 1388 |
1388 EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL)); | 1389 EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL)); |
1389 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); | 1390 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); |
1390 EXPECT_EQ(100, entry2->WriteData(1, 0, buf, 100, NULL, false)); | 1391 EXPECT_EQ(100, entry2->WriteData(1, 0, buf, 100, NULL, false)); |
1391 | 1392 |
1392 EXPECT_EQ(kBufSize, entry3->ReadData(0, 0, buf, kBufSize, NULL)); | 1393 EXPECT_EQ(kBufSize, entry3->ReadData(0, 0, buf, kBufSize, NULL)); |
1393 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); | 1394 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); |
1394 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); | 1395 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); |
1395 | 1396 |
1396 std::string key = entry2->GetKey(); | 1397 std::string key = entry2->GetKey(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 // Wait for a callback that never comes... about 2 secs :). The message loop | 1440 // Wait for a callback that never comes... about 2 secs :). The message loop |
1440 // has to run to allow invocation of the usage timer. | 1441 // has to run to allow invocation of the usage timer. |
1441 helper.WaitUntilCacheIoFinished(1); | 1442 helper.WaitUntilCacheIoFinished(1); |
1442 } | 1443 } |
1443 | 1444 |
1444 void DiskCacheBackendTest::BackendDoomAll() { | 1445 void DiskCacheBackendTest::BackendDoomAll() { |
1445 InitCache(); | 1446 InitCache(); |
1446 Time initial = Time::Now(); | 1447 Time initial = Time::Now(); |
1447 | 1448 |
1448 disk_cache::Entry *entry1, *entry2; | 1449 disk_cache::Entry *entry1, *entry2; |
1449 ASSERT_TRUE(cache_->CreateEntry("first", &entry1)); | 1450 ASSERT_EQ(net::OK, CreateEntry("first", &entry1)); |
1450 ASSERT_TRUE(cache_->CreateEntry("second", &entry2)); | 1451 ASSERT_EQ(net::OK, CreateEntry("second", &entry2)); |
1451 entry1->Close(); | 1452 entry1->Close(); |
1452 entry2->Close(); | 1453 entry2->Close(); |
1453 | 1454 |
1454 ASSERT_TRUE(cache_->CreateEntry("third", &entry1)); | 1455 ASSERT_EQ(net::OK, CreateEntry("third", &entry1)); |
1455 ASSERT_TRUE(cache_->CreateEntry("fourth", &entry2)); | 1456 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry2)); |
1456 | 1457 |
1457 ASSERT_EQ(4, cache_->GetEntryCount()); | 1458 ASSERT_EQ(4, cache_->GetEntryCount()); |
1458 EXPECT_TRUE(cache_->DoomAllEntries()); | 1459 EXPECT_EQ(net::OK, DoomAllEntries()); |
1459 ASSERT_EQ(0, cache_->GetEntryCount()); | 1460 ASSERT_EQ(0, cache_->GetEntryCount()); |
1460 | 1461 |
1461 // We should stop posting tasks at some point (if we post any). | 1462 // We should stop posting tasks at some point (if we post any). |
1462 MessageLoop::current()->RunAllPending(); | 1463 MessageLoop::current()->RunAllPending(); |
1463 | 1464 |
1464 disk_cache::Entry *entry3, *entry4; | 1465 disk_cache::Entry *entry3, *entry4; |
1465 ASSERT_TRUE(cache_->CreateEntry("third", &entry3)); | 1466 ASSERT_EQ(net::OK, CreateEntry("third", &entry3)); |
1466 ASSERT_TRUE(cache_->CreateEntry("fourth", &entry4)); | 1467 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4)); |
1467 | 1468 |
1468 EXPECT_TRUE(cache_->DoomAllEntries()); | 1469 EXPECT_EQ(net::OK, DoomAllEntries()); |
1469 ASSERT_EQ(0, cache_->GetEntryCount()); | 1470 ASSERT_EQ(0, cache_->GetEntryCount()); |
1470 | 1471 |
1471 entry1->Close(); | 1472 entry1->Close(); |
1472 entry2->Close(); | 1473 entry2->Close(); |
1473 entry3->Doom(); // The entry should be already doomed, but this must work. | 1474 entry3->Doom(); // The entry should be already doomed, but this must work. |
1474 entry3->Close(); | 1475 entry3->Close(); |
1475 entry4->Close(); | 1476 entry4->Close(); |
1476 | 1477 |
1477 // Now try with all references released. | 1478 // Now try with all references released. |
1478 ASSERT_TRUE(cache_->CreateEntry("third", &entry1)); | 1479 ASSERT_EQ(net::OK, CreateEntry("third", &entry1)); |
1479 ASSERT_TRUE(cache_->CreateEntry("fourth", &entry2)); | 1480 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry2)); |
1480 entry1->Close(); | 1481 entry1->Close(); |
1481 entry2->Close(); | 1482 entry2->Close(); |
1482 | 1483 |
1483 ASSERT_EQ(2, cache_->GetEntryCount()); | 1484 ASSERT_EQ(2, cache_->GetEntryCount()); |
1484 EXPECT_TRUE(cache_->DoomAllEntries()); | 1485 EXPECT_EQ(net::OK, DoomAllEntries()); |
1485 ASSERT_EQ(0, cache_->GetEntryCount()); | 1486 ASSERT_EQ(0, cache_->GetEntryCount()); |
1486 } | 1487 } |
1487 | 1488 |
1488 TEST_F(DiskCacheBackendTest, DoomAll) { | 1489 TEST_F(DiskCacheBackendTest, DoomAll) { |
1489 BackendDoomAll(); | 1490 BackendDoomAll(); |
1490 } | 1491 } |
1491 | 1492 |
1492 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { | 1493 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { |
1493 SetNewEviction(); | 1494 SetNewEviction(); |
1494 BackendDoomAll(); | 1495 BackendDoomAll(); |
1495 } | 1496 } |
1496 | 1497 |
1497 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { | 1498 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { |
1498 SetMemoryOnlyMode(); | 1499 SetMemoryOnlyMode(); |
1499 BackendDoomAll(); | 1500 BackendDoomAll(); |
1500 } | 1501 } |
1501 | 1502 |
1502 // If the index size changes when we doom the cache, we should not crash. | 1503 // If the index size changes when we doom the cache, we should not crash. |
1503 void DiskCacheBackendTest::BackendDoomAll2() { | 1504 void DiskCacheBackendTest::BackendDoomAll2() { |
1504 EXPECT_EQ(2, cache_->GetEntryCount()); | 1505 EXPECT_EQ(2, cache_->GetEntryCount()); |
1505 EXPECT_TRUE(cache_->DoomAllEntries()); | 1506 EXPECT_EQ(net::OK, DoomAllEntries()); |
1506 | 1507 |
1507 disk_cache::Entry* entry; | 1508 disk_cache::Entry* entry; |
1508 ASSERT_TRUE(cache_->CreateEntry("Something new", &entry)); | 1509 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry)); |
1509 entry->Close(); | 1510 entry->Close(); |
1510 | 1511 |
1511 EXPECT_EQ(1, cache_->GetEntryCount()); | 1512 EXPECT_EQ(1, cache_->GetEntryCount()); |
1512 } | 1513 } |
1513 | 1514 |
1514 TEST_F(DiskCacheBackendTest, DoomAll2) { | 1515 TEST_F(DiskCacheBackendTest, DoomAll2) { |
1515 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1516 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
1516 DisableFirstCleanup(); | 1517 DisableFirstCleanup(); |
1517 SetMaxSize(20 * 1024 * 1024); | 1518 SetMaxSize(20 * 1024 * 1024); |
1518 InitCache(); | 1519 InitCache(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 EXPECT_EQ(kDefaultSize * 5 / 2, | 1576 EXPECT_EQ(kDefaultSize * 5 / 2, |
1576 disk_cache::PreferedCacheSize(large_size * 100 / 2)); | 1577 disk_cache::PreferedCacheSize(large_size * 100 / 2)); |
1577 EXPECT_EQ(kDefaultSize * 5 / 2, | 1578 EXPECT_EQ(kDefaultSize * 5 / 2, |
1578 disk_cache::PreferedCacheSize(large_size * 500 / 2)); | 1579 disk_cache::PreferedCacheSize(large_size * 500 / 2)); |
1579 | 1580 |
1580 EXPECT_EQ(kDefaultSize * 6 / 2, | 1581 EXPECT_EQ(kDefaultSize * 6 / 2, |
1581 disk_cache::PreferedCacheSize(large_size * 600 / 2)); | 1582 disk_cache::PreferedCacheSize(large_size * 600 / 2)); |
1582 EXPECT_EQ(kDefaultSize * 7 / 2, | 1583 EXPECT_EQ(kDefaultSize * 7 / 2, |
1583 disk_cache::PreferedCacheSize(large_size * 700 / 2)); | 1584 disk_cache::PreferedCacheSize(large_size * 700 / 2)); |
1584 } | 1585 } |
OLD | NEW |