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

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

Issue 164503: Merge 22637 - Disk Cache: Don't depend on the backend being enabled to... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 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 | « no previous file | net/disk_cache/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')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/net/disk_cache/backend_unittest.cc:r22637
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 void BackendRecoverRemove(); 59 void BackendRecoverRemove();
60 void BackendInvalidEntry2(); 60 void BackendInvalidEntry2();
61 void BackendNotMarkedButDirty(const std::wstring& name); 61 void BackendNotMarkedButDirty(const std::wstring& name);
62 void BackendDoomAll(); 62 void BackendDoomAll();
63 void BackendDoomAll2(); 63 void BackendDoomAll2();
64 void BackendInvalidRankings(); 64 void BackendInvalidRankings();
65 void BackendInvalidRankings2(); 65 void BackendInvalidRankings2();
66 void BackendDisable(); 66 void BackendDisable();
67 void BackendDisable2(); 67 void BackendDisable2();
68 void BackendDisable3(); 68 void BackendDisable3();
69 void BackendDisable4();
69 }; 70 };
70 71
71 void DiskCacheBackendTest::BackendBasics() { 72 void DiskCacheBackendTest::BackendBasics() {
72 InitCache(); 73 InitCache();
73 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; 74 disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
74 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); 75 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1));
75 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); 76 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
76 ASSERT_TRUE(NULL != entry1); 77 ASSERT_TRUE(NULL != entry1);
77 entry1->Close(); 78 entry1->Close();
78 entry1 = NULL; 79 entry1 = NULL;
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 1273
1273 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { 1274 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
1274 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); 1275 ASSERT_TRUE(CopyTestCache(L"bad_rankings2"));
1275 DisableFirstCleanup(); 1276 DisableFirstCleanup();
1276 SetMaxSize(20 * 1024 * 1024); 1277 SetMaxSize(20 * 1024 * 1024);
1277 SetNewEviction(); 1278 SetNewEviction();
1278 InitCache(); 1279 InitCache();
1279 BackendDisable3(); 1280 BackendDisable3();
1280 } 1281 }
1281 1282
1283 // If we disable the cache, already open entries should work as far as possible.
1284 void DiskCacheBackendTest::BackendDisable4() {
1285 disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
1286 void* iter = NULL;
1287 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1));
1288
1289 char key2[2000];
1290 char key3[20000];
1291 CacheTestFillBuffer(key2, sizeof(key2), true);
1292 CacheTestFillBuffer(key3, sizeof(key3), true);
1293 key2[sizeof(key2) - 1] = '\0';
1294 key3[sizeof(key3) - 1] = '\0';
1295 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
1296 ASSERT_TRUE(cache_->CreateEntry(key3, &entry3));
1297
1298 const int kBufSize = 20000;
1299 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kBufSize);
1300 memset(buf->data(), 0, kBufSize);
1301 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false));
1302 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false));
1303
1304 // This line should disable the cache but not delete it.
1305 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry4));
1306 EXPECT_EQ(4, cache_->GetEntryCount());
1307
1308 EXPECT_FALSE(cache_->CreateEntry("cache is disabled", &entry4));
1309
1310 EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL));
1311 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false));
1312 EXPECT_EQ(100, entry2->WriteData(1, 0, buf, 100, NULL, false));
1313
1314 EXPECT_EQ(kBufSize, entry3->ReadData(0, 0, buf, kBufSize, NULL));
1315 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false));
1316 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false));
1317
1318 std::string key = entry2->GetKey();
1319 EXPECT_EQ(sizeof(key2) - 1, key.size());
1320 key = entry3->GetKey();
1321 EXPECT_EQ(sizeof(key3) - 1, key.size());
1322
1323 entry1->Close();
1324 entry2->Close();
1325 entry3->Close();
1326 MessageLoop::current()->RunAllPending();
1327
1328 EXPECT_EQ(0, cache_->GetEntryCount());
1329 }
1330
1331 TEST_F(DiskCacheBackendTest, DisableSuccess4) {
1332 ASSERT_TRUE(CopyTestCache(L"bad_rankings"));
1333 DisableFirstCleanup();
1334 SetDirectMode();
1335 InitCache();
1336 BackendDisable4();
1337 }
1338
1339 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
1340 ASSERT_TRUE(CopyTestCache(L"bad_rankings"));
1341 DisableFirstCleanup();
1342 SetDirectMode();
1343 SetNewEviction();
1344 InitCache();
1345 BackendDisable4();
1346 }
1347
1282 TEST_F(DiskCacheTest, Backend_UsageStats) { 1348 TEST_F(DiskCacheTest, Backend_UsageStats) {
1283 MessageLoopHelper helper; 1349 MessageLoopHelper helper;
1284 1350
1285 std::wstring path = GetCachePath(); 1351 std::wstring path = GetCachePath();
1286 ASSERT_TRUE(DeleteCache(path.c_str())); 1352 ASSERT_TRUE(DeleteCache(path.c_str()));
1287 scoped_ptr<disk_cache::BackendImpl> cache; 1353 scoped_ptr<disk_cache::BackendImpl> cache;
1288 cache.reset(new disk_cache::BackendImpl(path)); 1354 cache.reset(new disk_cache::BackendImpl(path));
1289 ASSERT_TRUE(NULL != cache.get()); 1355 ASSERT_TRUE(NULL != cache.get());
1290 cache->SetUnitTestMode(); 1356 cache->SetUnitTestMode();
1291 ASSERT_TRUE(cache->Init()); 1357 ASSERT_TRUE(cache->Init());
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 EXPECT_EQ(kDefaultSize * 5 / 2, 1492 EXPECT_EQ(kDefaultSize * 5 / 2,
1427 disk_cache::PreferedCacheSize(large_size * 100 / 2)); 1493 disk_cache::PreferedCacheSize(large_size * 100 / 2));
1428 EXPECT_EQ(kDefaultSize * 5 / 2, 1494 EXPECT_EQ(kDefaultSize * 5 / 2,
1429 disk_cache::PreferedCacheSize(large_size * 500 / 2)); 1495 disk_cache::PreferedCacheSize(large_size * 500 / 2));
1430 1496
1431 EXPECT_EQ(kDefaultSize * 6 / 2, 1497 EXPECT_EQ(kDefaultSize * 6 / 2,
1432 disk_cache::PreferedCacheSize(large_size * 600 / 2)); 1498 disk_cache::PreferedCacheSize(large_size * 600 / 2));
1433 EXPECT_EQ(kDefaultSize * 7 / 2, 1499 EXPECT_EQ(kDefaultSize * 7 / 2,
1434 disk_cache::PreferedCacheSize(large_size * 700 / 2)); 1500 disk_cache::PreferedCacheSize(large_size * 700 / 2));
1435 } 1501 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698