| 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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 delete cache; | 263 delete cache; |
| 264 } | 264 } |
| 265 | 265 |
| 266 base::MessageLoop::current()->RunUntilIdle(); | 266 base::MessageLoop::current()->RunUntilIdle(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Tests that |BackendImpl| fails to initialize with a missing file. | 269 // Tests that |BackendImpl| fails to initialize with a missing file. |
| 270 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { | 270 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { |
| 271 ASSERT_TRUE(CopyTestCache("bad_entry")); | 271 ASSERT_TRUE(CopyTestCache("bad_entry")); |
| 272 base::FilePath filename = cache_path_.AppendASCII("data_1"); | 272 base::FilePath filename = cache_path_.AppendASCII("data_1"); |
| 273 base::Delete(filename, false); | 273 base::DeleteFile(filename, false); |
| 274 base::Thread cache_thread("CacheThread"); | 274 base::Thread cache_thread("CacheThread"); |
| 275 ASSERT_TRUE(cache_thread.StartWithOptions( | 275 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 276 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 276 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 277 net::TestCompletionCallback cb; | 277 net::TestCompletionCallback cb; |
| 278 | 278 |
| 279 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 279 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
| 280 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 280 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( |
| 281 cache_path_, cache_thread.message_loop_proxy().get(), NULL); | 281 cache_path_, cache_thread.message_loop_proxy().get(), NULL); |
| 282 int rv = cache->Init(cb.callback()); | 282 int rv = cache->Init(cb.callback()); |
| 283 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 283 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
| (...skipping 2487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2771 base::win::ScopedHandle file2(CreateFile( | 2771 base::win::ScopedHandle file2(CreateFile( |
| 2772 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); | 2772 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); |
| 2773 EXPECT_FALSE(file2.IsValid()); | 2773 EXPECT_FALSE(file2.IsValid()); |
| 2774 | 2774 |
| 2775 sharing |= FILE_SHARE_DELETE; | 2775 sharing |= FILE_SHARE_DELETE; |
| 2776 file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, | 2776 file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, |
| 2777 OPEN_EXISTING, 0, NULL)); | 2777 OPEN_EXISTING, 0, NULL)); |
| 2778 EXPECT_TRUE(file2.IsValid()); | 2778 EXPECT_TRUE(file2.IsValid()); |
| 2779 #endif | 2779 #endif |
| 2780 | 2780 |
| 2781 EXPECT_TRUE(base::Delete(name, false)); | 2781 EXPECT_TRUE(base::DeleteFile(name, false)); |
| 2782 | 2782 |
| 2783 // We should be able to use the file. | 2783 // We should be able to use the file. |
| 2784 const int kSize = 200; | 2784 const int kSize = 200; |
| 2785 char buffer1[kSize]; | 2785 char buffer1[kSize]; |
| 2786 char buffer2[kSize]; | 2786 char buffer2[kSize]; |
| 2787 memset(buffer1, 't', kSize); | 2787 memset(buffer1, 't', kSize); |
| 2788 memset(buffer2, 0, kSize); | 2788 memset(buffer2, 0, kSize); |
| 2789 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); | 2789 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); |
| 2790 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); | 2790 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); |
| 2791 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); | 2791 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3059 delete cache; | 3059 delete cache; |
| 3060 DisableIntegrityCheck(); | 3060 DisableIntegrityCheck(); |
| 3061 } | 3061 } |
| 3062 | 3062 |
| 3063 TEST_F(DiskCacheBackendTest, SimpleCacheFixEnumerators) { | 3063 TEST_F(DiskCacheBackendTest, SimpleCacheFixEnumerators) { |
| 3064 SetSimpleCacheMode(); | 3064 SetSimpleCacheMode(); |
| 3065 BackendFixEnumerators(); | 3065 BackendFixEnumerators(); |
| 3066 } | 3066 } |
| 3067 | 3067 |
| 3068 #endif // !defined(OS_WIN) | 3068 #endif // !defined(OS_WIN) |
| OLD | NEW |