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

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

Issue 120004: Introduce parent and child entries for MemEntryImpl... (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 | « no previous file | net/disk_cache/mem_backend_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-2009 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"
11 #include "net/disk_cache/disk_cache_test_base.h" 11 #include "net/disk_cache/disk_cache_test_base.h"
12 #include "net/disk_cache/disk_cache_test_util.h" 12 #include "net/disk_cache/disk_cache_test_util.h"
13 #include "net/disk_cache/entry_impl.h" 13 #include "net/disk_cache/entry_impl.h"
14 #include "net/disk_cache/mem_entry_impl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 using base::Time; 17 using base::Time;
17 18
18 extern volatile int g_cache_tests_received; 19 extern volatile int g_cache_tests_received;
19 extern volatile bool g_cache_tests_error; 20 extern volatile bool g_cache_tests_error;
20 21
21 // Tests that can run with different types of caches. 22 // Tests that can run with different types of caches.
22 class DiskCacheEntryTest : public DiskCacheTestWithCache { 23 class DiskCacheEntryTest : public DiskCacheTestWithCache {
23 protected: 24 protected:
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 TEST_F(DiskCacheEntryTest, DoomedEntry) { 813 TEST_F(DiskCacheEntryTest, DoomedEntry) {
813 InitCache(); 814 InitCache();
814 DoomEntry(); 815 DoomEntry();
815 } 816 }
816 817
817 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { 818 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) {
818 SetMemoryOnlyMode(); 819 SetMemoryOnlyMode();
819 InitCache(); 820 InitCache();
820 DoomEntry(); 821 DoomEntry();
821 } 822 }
823
824 // Test that child entries in a memory cache backend are not visible from
825 // enumerations.
826 TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSlaveEntries) {
827 SetMemoryOnlyMode();
828 SetDirectMode();
829 SetMaxSize(1024);
830 InitCache();
831
832 disk_cache::Entry* entry;
833 disk_cache::MemEntryImpl* parent_entry;
834
835 ASSERT_TRUE(cache_->CreateEntry("parent", &entry));
836 parent_entry = reinterpret_cast<disk_cache::MemEntryImpl*>(entry);
837 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, parent_entry->type());
838 parent_entry->Close();
839
840 disk_cache::MemEntryImpl* child_entry =
841 new disk_cache::MemEntryImpl(mem_cache_);
842 // TODO(hclam): we shouldn't create a child entry explicit. Once a parent
843 // entry can be triggered to create a child entry, we should change this
844 // to use another public method to do the creation.
845 EXPECT_TRUE(child_entry->CreateChildEntry(parent_entry));
846 EXPECT_EQ(disk_cache::MemEntryImpl::kChildEntry, child_entry->type());
847
848 // Perform the enumerations.
849 void* iter = NULL;
850 int count = 0;
851 while (cache_->OpenNextEntry(&iter, &entry)) {
852 ASSERT_TRUE(entry != NULL);
853 disk_cache::MemEntryImpl* mem_entry =
854 reinterpret_cast<disk_cache::MemEntryImpl*>(entry);
855 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type());
856 EXPECT_TRUE(mem_entry == parent_entry);
857 mem_entry->Close();
858 ++count;
859 }
860 EXPECT_EQ(1, count);
861
862 // TODO(hclam): remove this when parent entry can doom child entries
863 // internally. Now we have to doom this child entry manually.
864 child_entry->Doom();
865 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/mem_backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698