Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
pasko-google - do not use
2013/05/02 14:01:43
BUG=173400
felipeg
2013/05/02 14:10:05
Done.
| |
| 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" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| (...skipping 2880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | |
|
pasko-google - do not use
2013/05/02 14:01:43
an empty line preceding the comment looked better
felipeg
2013/05/02 14:10:05
Done.
| |
| 2911 // Confirm the rest of the files are gone. | 2917 // Confirm the rest of the files are gone. |
| 2912 for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) { | 2918 for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) { |
| 2913 base::FilePath | 2919 base::FilePath |
| 2914 should_be_gone_file(cache_path_.AppendASCII( | 2920 should_be_gone_file(cache_path_.AppendASCII( |
| 2915 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i))); | 2921 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i))); |
| 2916 EXPECT_FALSE(file_util::PathExists(should_be_gone_file)); | 2922 EXPECT_FALSE(file_util::PathExists(should_be_gone_file)); |
| 2917 } | 2923 } |
| 2918 } | 2924 } |
| 2919 | 2925 |
| 2920 TEST_F(DiskCacheBackendTest, SimpleCacheOpenBadFile) { | 2926 TEST_F(DiskCacheBackendTest, SimpleCacheOpenBadFile) { |
| 2921 SetSimpleCacheMode(); | 2927 SetSimpleCacheMode(); |
| 2922 InitCache(); | 2928 InitCache(); |
| 2923 | 2929 |
| 2924 const char* key = "the first key"; | 2930 const char* key = "the first key"; |
| 2925 disk_cache::Entry* entry = NULL; | 2931 disk_cache::Entry* entry = NULL; |
| 2926 | 2932 |
| 2927 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 2933 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 2928 disk_cache::Entry* null = NULL; | 2934 disk_cache::Entry* null = NULL; |
| 2929 ASSERT_NE(null, entry); | 2935 ASSERT_NE(null, entry); |
| 2930 entry->Close(); | 2936 entry->Close(); |
| 2931 entry = NULL; | 2937 entry = NULL; |
| 2932 | 2938 |
| 2939 // To make sure the file creation completed we need to call open again so that | |
| 2940 // we block until it actually created the files. | |
| 2941 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | |
| 2942 ASSERT_NE(null, entry); | |
| 2943 entry->Close(); | |
| 2944 entry = NULL; | |
| 2945 | |
| 2933 // Write an invalid header on stream 1. | 2946 // Write an invalid header on stream 1. |
| 2934 base::FilePath entry_file1_path = cache_path_.AppendASCII( | 2947 base::FilePath entry_file1_path = cache_path_.AppendASCII( |
| 2935 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1)); | 2948 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, 1)); |
| 2936 | 2949 |
| 2937 disk_cache::SimpleFileHeader header; | 2950 disk_cache::SimpleFileHeader header; |
| 2938 header.initial_magic_number = GG_UINT64_C(0xbadf00d); | 2951 header.initial_magic_number = GG_UINT64_C(0xbadf00d); |
| 2939 EXPECT_EQ( | 2952 EXPECT_EQ( |
| 2940 implicit_cast<int>(sizeof(header)), | 2953 implicit_cast<int>(sizeof(header)), |
| 2941 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), | 2954 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), |
| 2942 sizeof(header))); | 2955 sizeof(header))); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2999 NULL); | 3012 NULL); |
| 3000 cache->SetUnitTestMode(); | 3013 cache->SetUnitTestMode(); |
| 3001 net::TestCompletionCallback cb; | 3014 net::TestCompletionCallback cb; |
| 3002 int rv = cache->Init(cb.callback()); | 3015 int rv = cache->Init(cb.callback()); |
| 3003 EXPECT_NE(net::OK, cb.GetResult(rv)); | 3016 EXPECT_NE(net::OK, cb.GetResult(rv)); |
| 3004 delete cache; | 3017 delete cache; |
| 3005 DisableIntegrityCheck(); | 3018 DisableIntegrityCheck(); |
| 3006 } | 3019 } |
| 3007 | 3020 |
| 3008 #endif // !defined(OS_WIN) | 3021 #endif // !defined(OS_WIN) |
| OLD | NEW |