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

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

Issue 13907009: Support optimistic Create and Write operations on the SimpleCache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make linker happy Created 7 years, 7 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_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/port.h" 7 #include "base/port.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
(...skipping 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after
2849 InitCache(); 2849 InitCache();
2850 2850
2851 const char* key = "the first key"; 2851 const char* key = "the first key";
2852 disk_cache::Entry* entry = NULL; 2852 disk_cache::Entry* entry = NULL;
2853 2853
2854 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2854 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2855 ASSERT_TRUE(entry != NULL); 2855 ASSERT_TRUE(entry != NULL);
2856 entry->Close(); 2856 entry->Close();
2857 entry = NULL; 2857 entry = NULL;
2858 2858
2859 // To make sure the file creation completed we need to call open again so that
gavinp 2013/05/01 13:11:22 Good catch on this. I think it should be moved ou
felipeg 2013/05/02 09:49:27 Done.
gavinp 2013/05/02 12:47:39 Not done, right?
felipeg 2013/05/02 13:55:58 I thought we agreed to leave it as a comment.
gavinp 2013/05/02 14:05:45 Yeah. I am sorry for being unclear; I just want to
2860 // we block until it actually created the files.
2861 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2862 ASSERT_TRUE(entry != NULL);
2863 entry->Close();
2864 entry = NULL;
2865
2859 // Delete one of the files in the entry. 2866 // Delete one of the files in the entry.
2860 base::FilePath to_delete_file = cache_path_.AppendASCII( 2867 base::FilePath to_delete_file = cache_path_.AppendASCII(
2861 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 0)); 2868 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 0));
2862 EXPECT_TRUE(file_util::PathExists(to_delete_file)); 2869 EXPECT_TRUE(file_util::PathExists(to_delete_file));
2863 EXPECT_TRUE(disk_cache::DeleteCacheFile(to_delete_file)); 2870 EXPECT_TRUE(disk_cache::DeleteCacheFile(to_delete_file));
2864 2871
2865 // Failing to open the entry should delete the rest of these files. 2872 // Failing to open the entry should delete the rest of these files.
2866 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 2873 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
2867
2868 // Confirm the rest of the files are gone. 2874 // Confirm the rest of the files are gone.
2869 for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) { 2875 for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) {
2870 base::FilePath 2876 base::FilePath
2871 should_be_gone_file(cache_path_.AppendASCII( 2877 should_be_gone_file(cache_path_.AppendASCII(
2872 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i))); 2878 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i)));
2873 EXPECT_FALSE(file_util::PathExists(should_be_gone_file)); 2879 EXPECT_FALSE(file_util::PathExists(should_be_gone_file));
2874 } 2880 }
2875 } 2881 }
2876 2882
2877 TEST_F(DiskCacheBackendTest, SimpleCacheOpenBadFile) { 2883 TEST_F(DiskCacheBackendTest, SimpleCacheOpenBadFile) {
2878 SetSimpleCacheMode(); 2884 SetSimpleCacheMode();
2879 InitCache(); 2885 InitCache();
2880 2886
2881 const char* key = "the first key"; 2887 const char* key = "the first key";
2882 disk_cache::Entry* entry = NULL; 2888 disk_cache::Entry* entry = NULL;
2883 2889
2884 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2890 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2885 disk_cache::Entry* null = NULL; 2891 disk_cache::Entry* null = NULL;
2886 ASSERT_NE(null, entry); 2892 ASSERT_NE(null, entry);
2887 entry->Close(); 2893 entry->Close();
2888 entry = NULL; 2894 entry = NULL;
2889 2895
2896 // To make sure the file creation completed we need to call open again so that
2897 // we block until it actually created the files.
2898 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2899 ASSERT_NE(null, entry);
2900 entry->Close();
2901 entry = NULL;
2902
2890 // Write an invalid header on stream 1. 2903 // Write an invalid header on stream 1.
2891 base::FilePath entry_file1_path = cache_path_.AppendASCII( 2904 base::FilePath entry_file1_path = cache_path_.AppendASCII(
2892 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1)); 2905 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1));
2893 2906
2894 disk_cache::SimpleFileHeader header; 2907 disk_cache::SimpleFileHeader header;
2895 header.initial_magic_number = GG_UINT64_C(0xbadf00d); 2908 header.initial_magic_number = GG_UINT64_C(0xbadf00d);
2896 EXPECT_EQ( 2909 EXPECT_EQ(
2897 implicit_cast<int>(sizeof(header)), 2910 implicit_cast<int>(sizeof(header)),
2898 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 2911 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header),
2899 sizeof(header))); 2912 sizeof(header)));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 NULL); 2990 NULL);
2978 cache->SetUnitTestMode(); 2991 cache->SetUnitTestMode();
2979 net::TestCompletionCallback cb; 2992 net::TestCompletionCallback cb;
2980 int rv = cache->Init(cb.callback()); 2993 int rv = cache->Init(cb.callback());
2981 EXPECT_NE(net::OK, cb.GetResult(rv)); 2994 EXPECT_NE(net::OK, cb.GetResult(rv));
2982 delete cache; 2995 delete cache;
2983 DisableIntegrityCheck(); 2996 DisableIntegrityCheck();
2984 } 2997 }
2985 2998
2986 #endif // !defined(OS_WIN) 2999 #endif // !defined(OS_WIN)
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