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

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

Issue 2626173003: Calculate the size of all cache entries between two points in time. (Closed)
Patch Set: fix unit_tests compilation Created 3 years, 11 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
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void BackendTrimInvalidEntry(); 119 void BackendTrimInvalidEntry();
120 void BackendTrimInvalidEntry2(); 120 void BackendTrimInvalidEntry2();
121 void BackendEnumerations(); 121 void BackendEnumerations();
122 void BackendEnumerations2(); 122 void BackendEnumerations2();
123 void BackendDoomMidEnumeration(); 123 void BackendDoomMidEnumeration();
124 void BackendInvalidEntryEnumeration(); 124 void BackendInvalidEntryEnumeration();
125 void BackendFixEnumerators(); 125 void BackendFixEnumerators();
126 void BackendDoomRecent(); 126 void BackendDoomRecent();
127 void BackendDoomBetween(); 127 void BackendDoomBetween();
128 void BackendCalculateSizeOfAllEntries(); 128 void BackendCalculateSizeOfAllEntries();
129 void BackendCalculateSizeOfEntriesBetween();
129 void BackendTransaction(const std::string& name, int num_entries, bool load); 130 void BackendTransaction(const std::string& name, int num_entries, bool load);
130 void BackendRecoverInsert(); 131 void BackendRecoverInsert();
131 void BackendRecoverRemove(); 132 void BackendRecoverRemove();
132 void BackendRecoverWithEviction(); 133 void BackendRecoverWithEviction();
133 void BackendInvalidEntry2(); 134 void BackendInvalidEntry2();
134 void BackendInvalidEntry3(); 135 void BackendInvalidEntry3();
135 void BackendInvalidEntry7(); 136 void BackendInvalidEntry7();
136 void BackendInvalidEntry8(); 137 void BackendInvalidEntry8();
137 void BackendInvalidEntry9(bool eviction); 138 void BackendInvalidEntry9(bool eviction);
138 void BackendInvalidEntry10(bool eviction); 139 void BackendInvalidEntry10(bool eviction);
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 } 1866 }
1866 1867
1867 TEST_F(DiskCacheBackendTest, SimpleCacheCalculateSizeOfAllEntries) { 1868 TEST_F(DiskCacheBackendTest, SimpleCacheCalculateSizeOfAllEntries) {
1868 // Use net::APP_CACHE to make size estimations deterministic via 1869 // Use net::APP_CACHE to make size estimations deterministic via
1869 // non-optimistic writes. 1870 // non-optimistic writes.
1870 SetCacheType(net::APP_CACHE); 1871 SetCacheType(net::APP_CACHE);
1871 SetSimpleCacheMode(); 1872 SetSimpleCacheMode();
1872 BackendCalculateSizeOfAllEntries(); 1873 BackendCalculateSizeOfAllEntries();
1873 } 1874 }
1874 1875
1876 void DiskCacheBackendTest::BackendCalculateSizeOfEntriesBetween() {
1877 InitCache();
1878
1879 EXPECT_EQ(0, CalculateSizeOfEntriesBetween(base::Time(), base::Time::Max()));
1880
1881 Time start = Time::Now();
1882
1883 disk_cache::Entry* entry;
1884 ASSERT_THAT(CreateEntry("first", &entry), IsOk());
1885 entry->Close();
1886 FlushQueueForTest();
1887
1888 AddDelay();
1889 Time middle = Time::Now();
1890 AddDelay();
1891
1892 ASSERT_THAT(CreateEntry("second", &entry), IsOk());
1893 entry->Close();
1894 ASSERT_THAT(CreateEntry("third_entry", &entry), IsOk());
1895 entry->Close();
1896 FlushQueueForTest();
1897
1898 AddDelay();
1899 Time end = Time::Now();
1900
1901 int size_1 = GetEntryMetadataSize("first");
1902 int size_2 = GetEntryMetadataSize("second");
1903 int size_3 = GetEntryMetadataSize("third_entry");
1904
1905 ASSERT_EQ(3, cache_->GetEntryCount());
1906 ASSERT_EQ(CalculateSizeOfAllEntries(),
1907 CalculateSizeOfEntriesBetween(base::Time(), base::Time::Max()));
1908
1909 int start_end = CalculateSizeOfEntriesBetween(start, end);
1910 ASSERT_EQ(CalculateSizeOfAllEntries(), start_end);
1911 ASSERT_EQ(size_1 + size_2 + size_3, start_end);
1912
1913 ASSERT_EQ(size_1, CalculateSizeOfEntriesBetween(start, middle));
1914 ASSERT_EQ(size_2 + size_3, CalculateSizeOfEntriesBetween(middle, end));
1915
1916 // After dooming the entries, the size should be back to zero.
1917 ASSERT_THAT(DoomAllEntries(), IsOk());
1918 EXPECT_EQ(0, CalculateSizeOfEntriesBetween(base::Time(), base::Time::Max()));
1919 }
1920
1921 TEST_F(DiskCacheBackendTest, CalculateSizeOfEntriesBetween) {
1922 InitCache();
1923 ASSERT_EQ(net::ERR_NOT_IMPLEMENTED,
1924 CalculateSizeOfEntriesBetween(base::Time(), base::Time::Max()));
1925 }
1926
1927 TEST_F(DiskCacheBackendTest, MemoryOnlyCalculateSizeOfEntriesBetween) {
1928 SetMemoryOnlyMode();
1929 BackendCalculateSizeOfEntriesBetween();
1930 }
1931
1932 TEST_F(DiskCacheBackendTest, SimpleCacheCalculateSizeOfEntriesBetween) {
1933 // Use net::APP_CACHE to make size estimations deterministic via
1934 // non-optimistic writes.
1935 SetCacheType(net::APP_CACHE);
1936 SetSimpleCacheMode();
1937 BackendCalculateSizeOfEntriesBetween();
1938 }
1939
1875 void DiskCacheBackendTest::BackendTransaction(const std::string& name, 1940 void DiskCacheBackendTest::BackendTransaction(const std::string& name,
1876 int num_entries, bool load) { 1941 int num_entries, bool load) {
1877 success_ = false; 1942 success_ = false;
1878 ASSERT_TRUE(CopyTestCache(name)); 1943 ASSERT_TRUE(CopyTestCache(name));
1879 DisableFirstCleanup(); 1944 DisableFirstCleanup();
1880 1945
1881 uint32_t mask; 1946 uint32_t mask;
1882 if (load) { 1947 if (load) {
1883 mask = 0xf; 1948 mask = 0xf;
1884 SetMaxSize(0x100000); 1949 SetMaxSize(0x100000);
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after
3856 // because that would advance the cache directory mtime and invalidate the 3921 // because that would advance the cache directory mtime and invalidate the
3857 // index. 3922 // index.
3858 entry2->Doom(); 3923 entry2->Doom();
3859 entry2->Close(); 3924 entry2->Close();
3860 3925
3861 DisableFirstCleanup(); 3926 DisableFirstCleanup();
3862 InitCache(); 3927 InitCache();
3863 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, 3928 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED,
3864 simple_cache_impl_->index()->init_method()); 3929 simple_cache_impl_->index()->init_method());
3865 } 3930 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698