| OLD | NEW | 
|     1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |     1 // Copyright (c) 2011 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/string_util.h" |     7 #include "base/string_util.h" | 
|     8 #include "base/stringprintf.h" |     8 #include "base/stringprintf.h" | 
|     9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |     9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 
|    10 #include "base/threading/platform_thread.h" |    10 #include "base/threading/platform_thread.h" | 
|    11 #include "net/base/io_buffer.h" |    11 #include "net/base/io_buffer.h" | 
|    12 #include "net/base/net_errors.h" |    12 #include "net/base/net_errors.h" | 
|    13 #include "net/base/test_completion_callback.h" |    13 #include "net/base/test_completion_callback.h" | 
|    14 #include "net/disk_cache/backend_impl.h" |    14 #include "net/disk_cache/backend_impl.h" | 
|    15 #include "net/disk_cache/cache_util.h" |    15 #include "net/disk_cache/cache_util.h" | 
|    16 #include "net/disk_cache/disk_cache_test_base.h" |    16 #include "net/disk_cache/disk_cache_test_base.h" | 
|    17 #include "net/disk_cache/disk_cache_test_util.h" |    17 #include "net/disk_cache/disk_cache_test_util.h" | 
|    18 #include "net/disk_cache/histogram_macros.h" |    18 #include "net/disk_cache/histogram_macros.h" | 
|    19 #include "net/disk_cache/mapped_file.h" |    19 #include "net/disk_cache/mapped_file.h" | 
|    20 #include "net/disk_cache/mem_backend_impl.h" |    20 #include "net/disk_cache/mem_backend_impl.h" | 
|    21 #include "testing/gtest/include/gtest/gtest.h" |    21 #include "testing/gtest/include/gtest/gtest.h" | 
|    22  |    22  | 
 |    23 #if defined(OS_WIN) | 
 |    24 #include "base/win/scoped_handle.h" | 
 |    25 #endif | 
 |    26  | 
|    23 using base::Time; |    27 using base::Time; | 
|    24  |    28  | 
|    25 // Tests that can run with different types of caches. |    29 // Tests that can run with different types of caches. | 
|    26 class DiskCacheBackendTest : public DiskCacheTestWithCache { |    30 class DiskCacheBackendTest : public DiskCacheTestWithCache { | 
|    27  protected: |    31  protected: | 
|    28   void BackendBasics(); |    32   void BackendBasics(); | 
|    29   void BackendKeying(); |    33   void BackendKeying(); | 
|    30   void BackendSetSize(); |    34   void BackendSetSize(); | 
|    31   void BackendLoad(); |    35   void BackendLoad(); | 
|    32   void BackendValidEntry(); |    36   void BackendValidEntry(); | 
| (...skipping 1889 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1922   disk_cache::Addr address(0x80000001); |  1926   disk_cache::Addr address(0x80000001); | 
|  1923   ASSERT_TRUE(cache_impl_->CreateExternalFile(&address)); |  1927   ASSERT_TRUE(cache_impl_->CreateExternalFile(&address)); | 
|  1924   FilePath name = cache_impl_->GetFileName(address); |  1928   FilePath name = cache_impl_->GetFileName(address); | 
|  1925  |  1929  | 
|  1926   scoped_refptr<disk_cache::File> file(new disk_cache::File(false)); |  1930   scoped_refptr<disk_cache::File> file(new disk_cache::File(false)); | 
|  1927   file->Init(name); |  1931   file->Init(name); | 
|  1928  |  1932  | 
|  1929 #if defined(OS_WIN) |  1933 #if defined(OS_WIN) | 
|  1930   DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; |  1934   DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; | 
|  1931   DWORD access = GENERIC_READ | GENERIC_WRITE; |  1935   DWORD access = GENERIC_READ | GENERIC_WRITE; | 
|  1932   ScopedHandle file2(CreateFile(name.value().c_str(), access, sharing, NULL, |  1936   base::win::ScopedHandle file2(CreateFile( | 
|  1933                                 OPEN_EXISTING, 0, NULL)); |  1937       name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); | 
|  1934   EXPECT_FALSE(file2.IsValid()); |  1938   EXPECT_FALSE(file2.IsValid()); | 
|  1935  |  1939  | 
|  1936   sharing |= FILE_SHARE_DELETE; |  1940   sharing |= FILE_SHARE_DELETE; | 
|  1937   file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, |  1941   file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, | 
|  1938                        OPEN_EXISTING, 0, NULL)); |  1942                        OPEN_EXISTING, 0, NULL)); | 
|  1939   EXPECT_TRUE(file2.IsValid()); |  1943   EXPECT_TRUE(file2.IsValid()); | 
|  1940 #endif |  1944 #endif | 
|  1941  |  1945  | 
|  1942   EXPECT_TRUE(file_util::Delete(name, false)); |  1946   EXPECT_TRUE(file_util::Delete(name, false)); | 
|  1943  |  1947  | 
|  1944   // We should be able to use the file. |  1948   // We should be able to use the file. | 
|  1945   const int kSize = 200; |  1949   const int kSize = 200; | 
|  1946   char buffer1[kSize]; |  1950   char buffer1[kSize]; | 
|  1947   char buffer2[kSize]; |  1951   char buffer2[kSize]; | 
|  1948   memset(buffer1, 't', kSize); |  1952   memset(buffer1, 't', kSize); | 
|  1949   memset(buffer2, 0, kSize); |  1953   memset(buffer2, 0, kSize); | 
|  1950   EXPECT_TRUE(file->Write(buffer1, kSize, 0)); |  1954   EXPECT_TRUE(file->Write(buffer1, kSize, 0)); | 
|  1951   EXPECT_TRUE(file->Read(buffer2, kSize, 0)); |  1955   EXPECT_TRUE(file->Read(buffer2, kSize, 0)); | 
|  1952   EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); |  1956   EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); | 
|  1953  |  1957  | 
|  1954   EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); |  1958   EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); | 
|  1955 } |  1959 } | 
| OLD | NEW |