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

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

Issue 13517004: Test cache creation retry via public interface only. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | net/disk_cache/cache_creator.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 false, NULL, NULL, &cache, 238 false, NULL, NULL, &cache,
239 cb.callback()); 239 cb.callback());
240 ASSERT_EQ(net::OK, cb.GetResult(rv)); 240 ASSERT_EQ(net::OK, cb.GetResult(rv));
241 ASSERT_TRUE(cache); 241 ASSERT_TRUE(cache);
242 delete cache; 242 delete cache;
243 } 243 }
244 244
245 MessageLoop::current()->RunUntilIdle(); 245 MessageLoop::current()->RunUntilIdle();
246 } 246 }
247 247
248 // Testst that re-creating the cache performs the expected cleanup. 248 // Tests that |BackendImpl| fails to initialize with a missing file.
249 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { 249 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) {
250 ASSERT_TRUE(CopyTestCache("bad_entry")); 250 ASSERT_TRUE(CopyTestCache("bad_entry"));
251 base::FilePath filename = cache_path_.AppendASCII("data_1"); 251 base::FilePath filename = cache_path_.AppendASCII("data_1");
252 file_util::Delete(filename, false); 252 file_util::Delete(filename, false);
253 DisableFirstCleanup(); 253 base::Thread cache_thread("CacheThread");
254 SetForceCreation(); 254 ASSERT_TRUE(cache_thread.StartWithOptions(
255 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
256 net::TestCompletionCallback cb;
255 257
256 bool prev = base::ThreadRestrictions::SetIOAllowed(false); 258 bool prev = base::ThreadRestrictions::SetIOAllowed(false);
257 InitDefaultCacheViaCreator(); 259 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
260 cache_path_, cache_thread.message_loop_proxy(), NULL);
261 int rv = cache->Init(cb.callback());
262 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv));
258 base::ThreadRestrictions::SetIOAllowed(prev); 263 base::ThreadRestrictions::SetIOAllowed(prev);
264
265 delete cache;
266 DisableIntegrityCheck();
259 } 267 }
260 268
261 TEST_F(DiskCacheBackendTest, ExternalFiles) { 269 TEST_F(DiskCacheBackendTest, ExternalFiles) {
262 InitCache(); 270 InitCache();
263 // First, let's create a file on the folder. 271 // First, let's create a file on the folder.
264 base::FilePath filename = cache_path_.AppendASCII("f_000001"); 272 base::FilePath filename = cache_path_.AppendASCII("f_000001");
265 273
266 const int kSize = 50; 274 const int kSize = 50;
267 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 275 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
268 CacheTestFillBuffer(buffer1->data(), kSize, false); 276 CacheTestFillBuffer(buffer1->data(), kSize, false);
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 cache_path_, cache_thread.message_loop_proxy(), NULL); 1542 cache_path_, cache_thread.message_loop_proxy(), NULL);
1535 int rv = cache->Init(cb.callback()); 1543 int rv = cache->Init(cb.callback());
1536 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); 1544 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv));
1537 1545
1538 delete cache; 1546 delete cache;
1539 } 1547 }
1540 1548
1541 // Tests that the cache is properly restarted on recovery error. 1549 // Tests that the cache is properly restarted on recovery error.
1542 TEST_F(DiskCacheBackendTest, DeleteOld) { 1550 TEST_F(DiskCacheBackendTest, DeleteOld) {
1543 ASSERT_TRUE(CopyTestCache("wrong_version")); 1551 ASSERT_TRUE(CopyTestCache("wrong_version"));
1544 InitDefaultCacheViaCreator(); 1552 SetNewEviction();
1553 bool prev = base::ThreadRestrictions::SetIOAllowed(false);
1554 CreateCacheViaPublicInterface();
rvargas (doing something else) 2013/04/03 17:44:22 I think the test would be more clear if it is expl
pasko-google - do not use 2013/04/03 18:12:30 Done.
1555 base::ThreadRestrictions::SetIOAllowed(prev);
1545 } 1556 }
1546 1557
1547 // We want to be able to deal with messed up entries on disk. 1558 // We want to be able to deal with messed up entries on disk.
1548 void DiskCacheBackendTest::BackendInvalidEntry2() { 1559 void DiskCacheBackendTest::BackendInvalidEntry2() {
1549 ASSERT_TRUE(CopyTestCache("bad_entry")); 1560 ASSERT_TRUE(CopyTestCache("bad_entry"));
1550 DisableFirstCleanup(); 1561 DisableFirstCleanup();
1551 InitCache(); 1562 InitCache();
1552 1563
1553 disk_cache::Entry *entry1, *entry2; 1564 disk_cache::Entry *entry1, *entry2;
1554 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 1565 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 // Ping the oldest entry. 2645 // Ping the oldest entry.
2635 cache_->OnExternalCacheHit("key0"); 2646 cache_->OnExternalCacheHit("key0");
2636 2647
2637 TrimForTest(false); 2648 TrimForTest(false);
2638 2649
2639 // Make sure the older key remains. 2650 // Make sure the older key remains.
2640 EXPECT_EQ(1, cache_->GetEntryCount()); 2651 EXPECT_EQ(1, cache_->GetEntryCount());
2641 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2652 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2642 entry->Close(); 2653 entry->Close();
2643 } 2654 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/cache_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698