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