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

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: Run browser tests with our simple cache 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/cache_creator.cc » ('j') | net/disk_cache/cache_creator.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 2881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 InitCache(); 2892 InitCache();
2893 2893
2894 const char* key = "the first key"; 2894 const char* key = "the first key";
2895 disk_cache::Entry* entry = NULL; 2895 disk_cache::Entry* entry = NULL;
2896 2896
2897 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2897 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2898 ASSERT_TRUE(entry != NULL); 2898 ASSERT_TRUE(entry != NULL);
2899 entry->Close(); 2899 entry->Close();
2900 entry = NULL; 2900 entry = NULL;
2901 2901
2902 // To make sure the file creation completed we need to call open again so that
2903 // we block until it actually created the files.
2904 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2905 ASSERT_TRUE(entry != NULL);
2906 entry->Close();
2907 entry = NULL;
2908
2902 // Delete one of the files in the entry. 2909 // Delete one of the files in the entry.
2903 base::FilePath to_delete_file = cache_path_.AppendASCII( 2910 base::FilePath to_delete_file = cache_path_.AppendASCII(
2904 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 0)); 2911 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 0));
2905 EXPECT_TRUE(file_util::PathExists(to_delete_file)); 2912 EXPECT_TRUE(file_util::PathExists(to_delete_file));
2906 EXPECT_TRUE(disk_cache::DeleteCacheFile(to_delete_file)); 2913 EXPECT_TRUE(disk_cache::DeleteCacheFile(to_delete_file));
2907 2914
2908 // Failing to open the entry should delete the rest of these files. 2915 // Failing to open the entry should delete the rest of these files.
2909 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 2916 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
2910 2917
2911 // Confirm the rest of the files are gone. 2918 // Confirm the rest of the files are gone.
(...skipping 11 matching lines...) Expand all
2923 2930
2924 const char* key = "the first key"; 2931 const char* key = "the first key";
2925 disk_cache::Entry* entry = NULL; 2932 disk_cache::Entry* entry = NULL;
2926 2933
2927 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2934 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2928 disk_cache::Entry* null = NULL; 2935 disk_cache::Entry* null = NULL;
2929 ASSERT_NE(null, entry); 2936 ASSERT_NE(null, entry);
2930 entry->Close(); 2937 entry->Close();
2931 entry = NULL; 2938 entry = NULL;
2932 2939
2940 // To make sure the file creation completed we need to call open again so that
2941 // we block until it actually created the files.
2942 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2943 ASSERT_NE(null, entry);
2944 entry->Close();
2945 entry = NULL;
2946
2933 // Write an invalid header on stream 1. 2947 // Write an invalid header on stream 1.
2934 base::FilePath entry_file1_path = cache_path_.AppendASCII( 2948 base::FilePath entry_file1_path = cache_path_.AppendASCII(
2935 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1)); 2949 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1));
2936 2950
2937 disk_cache::SimpleFileHeader header; 2951 disk_cache::SimpleFileHeader header;
2938 header.initial_magic_number = GG_UINT64_C(0xbadf00d); 2952 header.initial_magic_number = GG_UINT64_C(0xbadf00d);
2939 EXPECT_EQ( 2953 EXPECT_EQ(
2940 implicit_cast<int>(sizeof(header)), 2954 implicit_cast<int>(sizeof(header)),
2941 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 2955 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header),
2942 sizeof(header))); 2956 sizeof(header)));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 NULL); 3013 NULL);
3000 cache->SetUnitTestMode(); 3014 cache->SetUnitTestMode();
3001 net::TestCompletionCallback cb; 3015 net::TestCompletionCallback cb;
3002 int rv = cache->Init(cb.callback()); 3016 int rv = cache->Init(cb.callback());
3003 EXPECT_NE(net::OK, cb.GetResult(rv)); 3017 EXPECT_NE(net::OK, cb.GetResult(rv));
3004 delete cache; 3018 delete cache;
3005 DisableIntegrityCheck(); 3019 DisableIntegrityCheck();
3006 } 3020 }
3007 3021
3008 #endif // !defined(OS_WIN) 3022 #endif // !defined(OS_WIN)
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/cache_creator.cc » ('j') | net/disk_cache/cache_creator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698