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 file_util::Delete(filename, false); | 273 base::Delete(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 2491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2775 base::win::ScopedHandle file2(CreateFile( | 2775 base::win::ScopedHandle file2(CreateFile( |
2776 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); | 2776 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); |
2777 EXPECT_FALSE(file2.IsValid()); | 2777 EXPECT_FALSE(file2.IsValid()); |
2778 | 2778 |
2779 sharing |= FILE_SHARE_DELETE; | 2779 sharing |= FILE_SHARE_DELETE; |
2780 file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, | 2780 file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, |
2781 OPEN_EXISTING, 0, NULL)); | 2781 OPEN_EXISTING, 0, NULL)); |
2782 EXPECT_TRUE(file2.IsValid()); | 2782 EXPECT_TRUE(file2.IsValid()); |
2783 #endif | 2783 #endif |
2784 | 2784 |
2785 EXPECT_TRUE(file_util::Delete(name, false)); | 2785 EXPECT_TRUE(base::Delete(name, false)); |
2786 | 2786 |
2787 // We should be able to use the file. | 2787 // We should be able to use the file. |
2788 const int kSize = 200; | 2788 const int kSize = 200; |
2789 char buffer1[kSize]; | 2789 char buffer1[kSize]; |
2790 char buffer2[kSize]; | 2790 char buffer2[kSize]; |
2791 memset(buffer1, 't', kSize); | 2791 memset(buffer1, 't', kSize); |
2792 memset(buffer2, 0, kSize); | 2792 memset(buffer2, 0, kSize); |
2793 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); | 2793 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); |
2794 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); | 2794 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); |
2795 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); | 2795 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3058 cache_path_, base::MessageLoopProxy::current().get(), NULL); | 3058 cache_path_, base::MessageLoopProxy::current().get(), NULL); |
3059 cache->SetUnitTestMode(); | 3059 cache->SetUnitTestMode(); |
3060 net::TestCompletionCallback cb; | 3060 net::TestCompletionCallback cb; |
3061 int rv = cache->Init(cb.callback()); | 3061 int rv = cache->Init(cb.callback()); |
3062 EXPECT_NE(net::OK, cb.GetResult(rv)); | 3062 EXPECT_NE(net::OK, cb.GetResult(rv)); |
3063 delete cache; | 3063 delete cache; |
3064 DisableIntegrityCheck(); | 3064 DisableIntegrityCheck(); |
3065 } | 3065 } |
3066 | 3066 |
3067 #endif // !defined(OS_WIN) | 3067 #endif // !defined(OS_WIN) |
OLD | NEW |