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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/MemoryCacheTest.cpp

Issue 2845513002: [WIP] Add Resource::IsShareable
Patch Set: fix Created 3 years, 7 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 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/loader/fetch/MemoryCache.h" 31 #include "platform/loader/fetch/MemoryCache.h"
32 32
33 #include "platform/loader/fetch/RawResource.h"
34 #include "platform/loader/fetch/ResourceRequest.h" 33 #include "platform/loader/fetch/ResourceRequest.h"
34 #include "platform/loader/testing/MockResource.h"
35 #include "platform/loader/testing/MockResourceClient.h" 35 #include "platform/loader/testing/MockResourceClient.h"
36 #include "platform/testing/TestingPlatformSupport.h" 36 #include "platform/testing/TestingPlatformSupport.h"
37 #include "platform/testing/UnitTestHelpers.h" 37 #include "platform/testing/UnitTestHelpers.h"
38 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
39 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 class MemoryCacheTest : public ::testing::Test { 43 class MemoryCacheTest : public ::testing::Test {
44 public: 44 public:
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // Next task: now, the resources was pruned. 152 // Next task: now, the resources was pruned.
153 EXPECT_EQ(size_without_decode, GetMemoryCache()->size()); 153 EXPECT_EQ(size_without_decode, GetMemoryCache()->size());
154 } 154 }
155 155
156 static void TestResourcePruningAtEndOfTask(Resource* resource1, 156 static void TestResourcePruningAtEndOfTask(Resource* resource1,
157 Resource* resource2) { 157 Resource* resource2) {
158 GetMemoryCache()->SetDelayBeforeLiveDecodedPrune(0); 158 GetMemoryCache()->SetDelayBeforeLiveDecodedPrune(0);
159 159
160 // Enforce pruning by adding |dummyResource| and then call prune(). 160 // Enforce pruning by adding |dummyResource| and then call prune().
161 Resource* dummy_resource = 161 Resource* dummy_resource =
162 RawResource::Create(ResourceRequest("http://dummy"), Resource::kRaw); 162 MockResource::Create(ResourceRequest("http://dummy"));
163 GetMemoryCache()->Add(dummy_resource); 163 GetMemoryCache()->Add(dummy_resource);
164 EXPECT_GT(GetMemoryCache()->size(), 1u); 164 EXPECT_GT(GetMemoryCache()->size(), 1u);
165 const unsigned kTotalCapacity = 1; 165 const unsigned kTotalCapacity = 1;
166 GetMemoryCache()->SetCapacity(kTotalCapacity); 166 GetMemoryCache()->SetCapacity(kTotalCapacity);
167 GetMemoryCache()->Prune(); 167 GetMemoryCache()->Prune();
168 GetMemoryCache()->Remove(dummy_resource); 168 GetMemoryCache()->Remove(dummy_resource);
169 EXPECT_EQ(0u, GetMemoryCache()->size()); 169 EXPECT_EQ(0u, GetMemoryCache()->size());
170 170
171 const char kData[6] = "abcde"; 171 const char kData[6] = "abcde";
172 resource1->AppendData(kData, 3u); 172 resource1->AppendData(kData, 3u);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 FakeResource* resource2 = 395 FakeResource* resource2 =
396 FakeResource::Create(ResourceRequest(url2), Resource::kRaw); 396 FakeResource::Create(ResourceRequest(url2), Resource::kRaw);
397 GetMemoryCache()->Add(resource2); 397 GetMemoryCache()->Add(resource2);
398 EXPECT_TRUE(GetMemoryCache()->Contains(resource2)); 398 EXPECT_TRUE(GetMemoryCache()->Contains(resource2));
399 399
400 GetMemoryCache()->RemoveURLFromCache(url2); 400 GetMemoryCache()->RemoveURLFromCache(url2);
401 EXPECT_FALSE(GetMemoryCache()->Contains(resource2)); 401 EXPECT_FALSE(GetMemoryCache()->Contains(resource2));
402 } 402 }
403 403
404 } // namespace blink 404 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698