Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 113931: Remove code path that passes a file handle to the renderer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/histogram_macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/platform_thread.h" 6 #include "base/platform_thread.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 TEST_F(DiskCacheEntryTest, DoomedEntry) { 825 TEST_F(DiskCacheEntryTest, DoomedEntry) {
826 InitCache(); 826 InitCache();
827 DoomEntry(); 827 DoomEntry();
828 } 828 }
829 829
830 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { 830 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) {
831 SetMemoryOnlyMode(); 831 SetMemoryOnlyMode();
832 InitCache(); 832 InitCache();
833 DoomEntry(); 833 DoomEntry();
834 } 834 }
835
836 // Check that we can hint an entry to use external file and the return value
837 // is a valid file handle.
838 TEST_F(DiskCacheEntryTest, UseExternalFile) {
839 InitCache();
840
841 disk_cache::Entry* entry;
842 ASSERT_TRUE(cache_->CreateEntry("key", &entry));
843 base::PlatformFile cache_file = entry->UseExternalFile(0);
844
845 // We should have a valid file handle.
846 EXPECT_NE(base::kInvalidPlatformFileValue, cache_file);
847 scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
848
849 // 4KB.
850 size_t kDataSize = 0x1000;
851 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kDataSize);
852
853 CacheTestFillBuffer(buffer->data(), kDataSize, false);
854 ASSERT_EQ(0U, file->GetLength());
855 ASSERT_EQ(kDataSize, static_cast<size_t>(
856 entry->WriteData(0, 0, buffer, kDataSize, NULL, false)));
857 ASSERT_EQ(kDataSize, file->GetLength());
858 entry->Close();
859 }
860
861 // Make sure we can use Entry::GetPlatformFile on an entry stored in an external
862 // file and get a valid file handle.
863 TEST_F(DiskCacheEntryTest, GetPlatformFile) {
864 InitCache();
865
866 disk_cache::Entry* entry;
867 ASSERT_TRUE(cache_->CreateEntry("key", &entry));
868 EXPECT_NE(base::kInvalidPlatformFileValue, entry->UseExternalFile(0));
869
870 size_t kDataSize = 50;
871 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kDataSize);
872
873 // Fill the data buffer and write it to cache.
874 CacheTestFillBuffer(buffer->data(), kDataSize, false);
875 ASSERT_EQ(kDataSize,static_cast<size_t>(
876 entry->WriteData(0, 0, buffer, kDataSize, NULL, false)));
877
878 // Close the entry.
879 entry->Close();
880
881 // Open the entry again and get it's file handle.
882 ASSERT_TRUE(cache_->OpenEntry("key", &entry));
883 base::PlatformFile cache_file = entry->GetPlatformFile(0);
884
885 // Make sure it's a valid file handle and verify the size of the file.
886 scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
887 ASSERT_EQ(kDataSize, file->GetLength());
888
889 entry->Close();
890 }
891
892 // Test the behavior of EntryImpl that small entries are kept in block files
893 // or buffer, and only entries above certain size would be stored in an
894 // external file, make sure GetPlatformFile() works with both cases without
895 // using UseExternalFile().
896 TEST_F(DiskCacheEntryTest, GetPlatformFileVariableEntrySize) {
897 InitCache();
898
899 disk_cache::Entry* entry;
900
901 // Make the buffer just larger than disk_cache::kMaxBlockSize.
902 const size_t kLargeDataSize = disk_cache::kMaxBlockSize + 1;
903 const size_t kSmallDataSize = kLargeDataSize / 2;
904 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kLargeDataSize);
905
906 // 1. First test with small entry.
907 ASSERT_TRUE(cache_->CreateEntry("small_entry", &entry));
908
909 CacheTestFillBuffer(buffer->data(), kSmallDataSize, false);
910 ASSERT_EQ(kSmallDataSize, static_cast<size_t>(
911 entry->WriteData(0, 0, buffer, kSmallDataSize, NULL, false)));
912
913 // Make sure we don't get an external file.
914 ASSERT_EQ(base::kInvalidPlatformFileValue, entry->GetPlatformFile(0));
915
916 entry->Close();
917
918 // 2. Test with large entry.
919 ASSERT_TRUE(cache_->CreateEntry("large_entry", &entry));
920
921 CacheTestFillBuffer(buffer->data(), kLargeDataSize, false);
922 ASSERT_EQ(kLargeDataSize, static_cast<size_t>(
923 entry->WriteData(0, 0, buffer, kLargeDataSize, NULL, false)));
924
925 base::PlatformFile cache_file = entry->GetPlatformFile(0);
926 EXPECT_NE(base::kInvalidPlatformFileValue, cache_file);
927
928 // Make sure it's a valid file handle and verify the size of the file.
929 scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
930 ASSERT_EQ(kLargeDataSize, file->GetLength());
931
932 entry->Close();
933 }
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/histogram_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698