Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 256090: Disk cache: Add a method to cancel pending sparse operations.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/mem_entry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 EXPECT_EQ(kSize, entry->WriteSparseData(k1Meg + 16384, buf1, kSize, NULL)); 1336 EXPECT_EQ(kSize, entry->WriteSparseData(k1Meg + 16384, buf1, kSize, NULL));
1337 EXPECT_EQ(0, entry->ReadSparseData(k1Meg + 8192, buf1, kSize, NULL)); 1337 EXPECT_EQ(0, entry->ReadSparseData(k1Meg + 8192, buf1, kSize, NULL));
1338 1338
1339 // We never touched this one. 1339 // We never touched this one.
1340 EXPECT_EQ(kSize, entry->ReadSparseData(8192, buf1, kSize, NULL)); 1340 EXPECT_EQ(kSize, entry->ReadSparseData(8192, buf1, kSize, NULL));
1341 entry->Close(); 1341 entry->Close();
1342 1342
1343 // We re-created one of the corrupt children. 1343 // We re-created one of the corrupt children.
1344 EXPECT_EQ(3, cache_->GetEntryCount()); 1344 EXPECT_EQ(3, cache_->GetEntryCount());
1345 } 1345 }
1346
1347 TEST_F(DiskCacheEntryTest, CancelSparseIO) {
1348 InitCache();
1349 std::string key("the first key");
1350 disk_cache::Entry* entry;
1351 ASSERT_TRUE(cache_->CreateEntry(key, &entry));
1352
1353 const int kSize = 4 * 1024;
1354 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
1355 CacheTestFillBuffer(buf->data(), kSize, false);
1356
1357 SimpleCallbackTest cb1, cb2, cb3, cb4;
1358 int64 offset = 0;
1359 for (int ret = 0; ret != net::ERR_IO_PENDING; offset += kSize * 4)
1360 ret = entry->WriteSparseData(offset, buf, kSize, &cb1);
1361
1362 // Cannot use the entry at this point.
1363 offset = 0;
1364 EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
1365 entry->GetAvailableRange(offset, kSize, &offset));
1366 EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2));
1367
1368 // We cancel the pending operation, and register multiple notifications.
1369 entry->CancelSparseIO();
1370 EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb2));
1371 EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb3));
1372 entry->CancelSparseIO(); // Should be a no op at this point.
1373 EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb4));
1374
1375 offset = 0;
1376 EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
1377 entry->GetAvailableRange(offset, kSize, &offset));
1378 EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
1379 entry->ReadSparseData(offset, buf, kSize, NULL));
1380 EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
1381 entry->WriteSparseData(offset, buf, kSize, NULL));
1382
1383 // Now see if we receive all notifications.
1384 EXPECT_EQ(kSize, cb1.GetResult(net::ERR_IO_PENDING));
1385 EXPECT_EQ(net::OK, cb2.GetResult(net::ERR_IO_PENDING));
1386 EXPECT_EQ(net::OK, cb3.GetResult(net::ERR_IO_PENDING));
1387 EXPECT_EQ(net::OK, cb4.GetResult(net::ERR_IO_PENDING));
1388
1389 EXPECT_EQ(kSize, entry->GetAvailableRange(offset, kSize, &offset));
1390 EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2));
1391 entry->Close();
1392 }
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/mem_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698