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

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

Issue 19747: URLRequestContext and disk cache for media files (Closed)
Patch Set: signed and unsigned... Created 11 years, 9 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
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/mem_entry_impl.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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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, entry->WriteData(0, 0, buffer, kDataSize, NULL, false));
876
877 // Close the entry.
878 entry->Close();
879
880 // Open the entry again and get it's file handle.
881 ASSERT_TRUE(cache_->OpenEntry("key", &entry));
882 base::PlatformFile cache_file = entry->GetPlatformFile(0);
883
884 // Make sure it's a valid file handle and verify the size of the file.
885 scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
886 ASSERT_EQ(kDataSize, file->GetLength());
887
888 entry->Close();
889 }
890
891 // Test the behavior of EntryImpl that small entries are kept in block files
892 // or buffer, and only entries above certain size would be stored in an
893 // external file, make sure GetPlatformFile() works with both cases without
894 // using UseExternalFile().
895 TEST_F(DiskCacheEntryTest, GetPlatformFileVariableEntrySize) {
896 InitCache();
897
898 disk_cache::Entry* entry;
899
900 // Make the buffer just larger than disk_cache::kMaxBlockSize.
901 const size_t kLargeDataSize = disk_cache::kMaxBlockSize + 1;
902 const size_t kSmallDataSize = kLargeDataSize / 2;
903 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kLargeDataSize);
904
905 // 1. First test with small entry.
906 ASSERT_TRUE(cache_->CreateEntry("small_entry", &entry));
907
908 CacheTestFillBuffer(buffer->data(), kSmallDataSize, false);
909 ASSERT_EQ(kSmallDataSize,
910 entry->WriteData(0, 0, buffer, kSmallDataSize, NULL, false));
911
912 // Make sure we don't get an external file.
913 ASSERT_EQ(base::kInvalidPlatformFileValue, entry->GetPlatformFile(0));
914
915 entry->Close();
916
917 // 2. Test with large entry.
918 ASSERT_TRUE(cache_->CreateEntry("large_entry", &entry));
919
920 CacheTestFillBuffer(buffer->data(), kLargeDataSize, false);
921 ASSERT_EQ(kLargeDataSize,
922 entry->WriteData(0, 0, buffer, kLargeDataSize, NULL, false));
923
924 base::PlatformFile cache_file = entry->GetPlatformFile(0);
925 EXPECT_NE(base::kInvalidPlatformFileValue, cache_file);
926
927 // Make sure it's a valid file handle and verify the size of the file.
928 scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
929 ASSERT_EQ(kLargeDataSize, file->GetLength());
930
931 entry->Close();
932 }
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/mem_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698