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

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

Powered by Google App Engine
This is Rietveld 408576698