Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2010 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/platform_thread.h" | 6 #include "base/platform_thread.h" |
| 7 #include "base/timer.h" | 7 #include "base/timer.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1280 InitCache(); | 1280 InitCache(); |
| 1281 DoomSparseEntry(); | 1281 DoomSparseEntry(); |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) { | 1284 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) { |
| 1285 SetMemoryOnlyMode(); | 1285 SetMemoryOnlyMode(); |
| 1286 InitCache(); | 1286 InitCache(); |
| 1287 DoomSparseEntry(); | 1287 DoomSparseEntry(); |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 // A CompletionCallback that deletes the cache from within the callback. The way | |
| 1291 // a TestCompletionCallback works means that all tasks (even new ones) are | |
| 1292 // executed by the message loop before returning to the caller so the only way | |
| 1293 // to simulate a race is to execute what we want on the callback. | |
| 1294 class SparseTestCompletionCallback : public TestCompletionCallback { | |
| 1295 public: | |
|
gavinp
2010/07/27 15:29:44
" public:"
http://google-styleguide.googlecode.co
| |
| 1296 explicit SparseTestCompletionCallback(disk_cache::Backend* cache) | |
| 1297 : cache_(cache) {} | |
| 1298 | |
| 1299 virtual void RunWithParams(const Tuple1<int>& params) { | |
| 1300 delete cache_; | |
| 1301 TestCompletionCallback::RunWithParams(params); | |
| 1302 } | |
| 1303 private: | |
|
gavinp
2010/07/27 15:29:44
" private:"
http://google-styleguide.googlecode.c
| |
| 1304 disk_cache::Backend* cache_; | |
| 1305 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback); | |
| 1306 }; | |
| 1307 | |
| 1308 // Tests that we don't crash when the backend is deleted while we are working | |
| 1309 // deleting the sub-entries of a sparse entry. | |
| 1310 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { | |
| 1311 SetDirectMode(); | |
| 1312 UseCurrentThread(); | |
| 1313 InitCache(); | |
| 1314 std::string key("the key"); | |
| 1315 disk_cache::Entry* entry; | |
| 1316 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | |
| 1317 | |
| 1318 const int kSize = 4 * 1024; | |
| 1319 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | |
| 1320 CacheTestFillBuffer(buf->data(), kSize, false); | |
| 1321 | |
| 1322 int64 offset = 1024; | |
| 1323 // Write to a bunch of ranges. | |
| 1324 for (int i = 0; i < 12; i++) { | |
| 1325 EXPECT_EQ(kSize, entry->WriteSparseData(offset, buf, kSize, NULL)); | |
| 1326 offset *= 4; | |
| 1327 } | |
| 1328 EXPECT_EQ(9, cache_->GetEntryCount()); | |
| 1329 | |
| 1330 entry->Close(); | |
| 1331 SparseTestCompletionCallback cb(cache_); | |
| 1332 int rv = cache_->DoomEntry(key, &cb); | |
| 1333 EXPECT_EQ(net::ERR_IO_PENDING, rv); | |
| 1334 EXPECT_EQ(net::OK, cb.WaitForResult()); | |
| 1335 | |
| 1336 cache_ = NULL; | |
|
gavinp
2010/07/27 15:29:44
What does this do?
rvargas (doing something else)
2010/07/27 18:26:30
We deleted the cache in the callback, but the test
| |
| 1337 } | |
| 1338 | |
| 1290 void DiskCacheEntryTest::PartialSparseEntry() { | 1339 void DiskCacheEntryTest::PartialSparseEntry() { |
| 1291 std::string key("the first key"); | 1340 std::string key("the first key"); |
| 1292 disk_cache::Entry* entry; | 1341 disk_cache::Entry* entry; |
| 1293 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1342 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 1294 | 1343 |
| 1295 // We should be able to deal with IO that is not aligned to the block size | 1344 // We should be able to deal with IO that is not aligned to the block size |
| 1296 // of a sparse entry, at least to write a big range without leaving holes. | 1345 // of a sparse entry, at least to write a big range without leaving holes. |
| 1297 const int kSize = 4 * 1024; | 1346 const int kSize = 4 * 1024; |
| 1298 const int kSmallSize = 128; | 1347 const int kSmallSize = 128; |
| 1299 scoped_refptr<net::IOBuffer> buf1 = new net::IOBuffer(kSize); | 1348 scoped_refptr<net::IOBuffer> buf1 = new net::IOBuffer(kSize); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1478 rv = cb1.WaitForResult(); | 1527 rv = cb1.WaitForResult(); |
| 1479 EXPECT_TRUE(rv == 4096 || rv == kSize); | 1528 EXPECT_TRUE(rv == 4096 || rv == kSize); |
| 1480 EXPECT_EQ(net::OK, cb2.WaitForResult()); | 1529 EXPECT_EQ(net::OK, cb2.WaitForResult()); |
| 1481 EXPECT_EQ(net::OK, cb3.WaitForResult()); | 1530 EXPECT_EQ(net::OK, cb3.WaitForResult()); |
| 1482 EXPECT_EQ(net::OK, cb4.WaitForResult()); | 1531 EXPECT_EQ(net::OK, cb4.WaitForResult()); |
| 1483 | 1532 |
| 1484 rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); | 1533 rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); |
| 1485 EXPECT_EQ(0, cb5.GetResult(rv)); | 1534 EXPECT_EQ(0, cb5.GetResult(rv)); |
| 1486 entry->Close(); | 1535 entry->Close(); |
| 1487 } | 1536 } |
| OLD | NEW |