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

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

Issue 23983005: SimpleCache: merge the first and second stream in one file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes in the crc32 handling Created 7 years, 3 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/entry_unittest.cc » ('j') | net/disk_cache/entry_unittest.cc » ('J')
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/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/port.h" 8 #include "base/port.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 3232 matching lines...) Expand 10 before | Expand all | Expand 10 after
3243 3243
3244 // To make sure the file creation completed we need to call open again so that 3244 // To make sure the file creation completed we need to call open again so that
3245 // we block until it actually created the files. 3245 // we block until it actually created the files.
3246 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 3246 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
3247 ASSERT_TRUE(entry != NULL); 3247 ASSERT_TRUE(entry != NULL);
3248 entry->Close(); 3248 entry->Close();
3249 entry = NULL; 3249 entry = NULL;
3250 3250
3251 // Delete one of the files in the entry. 3251 // Delete one of the files in the entry.
3252 base::FilePath to_delete_file = cache_path_.AppendASCII( 3252 base::FilePath to_delete_file = cache_path_.AppendASCII(
3253 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 0)); 3253 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
3254 EXPECT_TRUE(base::PathExists(to_delete_file)); 3254 EXPECT_TRUE(base::PathExists(to_delete_file));
3255 EXPECT_TRUE(disk_cache::DeleteCacheFile(to_delete_file)); 3255 EXPECT_TRUE(disk_cache::DeleteCacheFile(to_delete_file));
3256 3256
3257 // Failing to open the entry should delete the rest of these files. 3257 // Failing to open the entry should delete the rest of these files.
3258 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 3258 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
3259 3259
3260 // Confirm the rest of the files are gone. 3260 // Confirm the rest of the files are gone.
3261 for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) { 3261 for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) {
3262 base::FilePath 3262 base::FilePath should_be_gone_file(cache_path_.AppendASCII(
3263 should_be_gone_file(cache_path_.AppendASCII( 3263 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, i)));
3264 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i)));
3265 EXPECT_FALSE(base::PathExists(should_be_gone_file)); 3264 EXPECT_FALSE(base::PathExists(should_be_gone_file));
3266 } 3265 }
3267 } 3266 }
3268 3267
3269 TEST_F(DiskCacheBackendTest, SimpleCacheOpenBadFile) { 3268 TEST_F(DiskCacheBackendTest, SimpleCacheOpenBadFile) {
3270 SetSimpleCacheMode(); 3269 SetSimpleCacheMode();
3271 InitCache(); 3270 InitCache();
3272 3271
3273 const char* key = "the first key"; 3272 const char* key = "the first key";
3274 disk_cache::Entry* entry = NULL; 3273 disk_cache::Entry* entry = NULL;
3275 3274
3276 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 3275 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
3277 disk_cache::Entry* null = NULL; 3276 disk_cache::Entry* null = NULL;
3278 ASSERT_NE(null, entry); 3277 ASSERT_NE(null, entry);
3279 entry->Close(); 3278 entry->Close();
3280 entry = NULL; 3279 entry = NULL;
3281 3280
3282 // To make sure the file creation completed we need to call open again so that 3281 // To make sure the file creation completed we need to call open again so that
3283 // we block until it actually created the files. 3282 // we block until it actually created the files.
3284 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 3283 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
3285 ASSERT_NE(null, entry); 3284 ASSERT_NE(null, entry);
3286 entry->Close(); 3285 entry->Close();
3287 entry = NULL; 3286 entry = NULL;
3288 3287
3289 // Write an invalid header on stream 1. 3288 // Write an invalid header for stream 0 and stream 1.
3290 base::FilePath entry_file1_path = cache_path_.AppendASCII( 3289 base::FilePath entry_file1_path = cache_path_.AppendASCII(
3291 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1)); 3290 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
3292 3291
3293 disk_cache::SimpleFileHeader header; 3292 disk_cache::SimpleFileHeader header;
3294 header.initial_magic_number = GG_UINT64_C(0xbadf00d); 3293 header.initial_magic_number = GG_UINT64_C(0xbadf00d);
3295 EXPECT_EQ( 3294 EXPECT_EQ(
3296 implicit_cast<int>(sizeof(header)), 3295 implicit_cast<int>(sizeof(header)),
3297 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 3296 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header),
3298 sizeof(header))); 3297 sizeof(header)));
3299 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 3298 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
3300 } 3299 }
3301 3300
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3465 void* iter = NULL; 3464 void* iter = NULL;
3466 size_t count = 0; 3465 size_t count = 0;
3467 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3466 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3468 cache_->EndEnumeration(&iter); 3467 cache_->EndEnumeration(&iter);
3469 3468
3470 EXPECT_EQ(key_pool.size(), count); 3469 EXPECT_EQ(key_pool.size(), count);
3471 EXPECT_TRUE(keys_to_match.empty()); 3470 EXPECT_TRUE(keys_to_match.empty());
3472 } 3471 }
3473 3472
3474 #endif // defined(OS_POSIX) 3473 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/entry_unittest.cc » ('j') | net/disk_cache/entry_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698