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

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

Issue 2584423002: Loading: move core/fetch to platform/loader/fetch (Closed)
Patch Set: another try Created 3 years, 10 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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
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 "core/fetch/MemoryCache.h" 31 #include "platform/loader/fetch/MemoryCache.h"
32 32
33 #include "core/fetch/MockResourceClient.h" 33 #include "platform/loader/fetch/MockResourceClient.h"
34 #include "core/fetch/RawResource.h" 34 #include "platform/loader/fetch/RawResource.h"
35 #include "platform/network/ResourceRequest.h" 35 #include "platform/network/ResourceRequest.h"
36 #include "platform/testing/TestingPlatformSupport.h"
36 #include "platform/testing/UnitTestHelpers.h" 37 #include "platform/testing/UnitTestHelpers.h"
37 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
38 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 class MemoryCacheTest : public ::testing::Test { 43 class MemoryCacheTest : public ::testing::Test {
43 public: 44 public:
44 class FakeDecodedResource final : public Resource { 45 class FakeDecodedResource final : public Resource {
45 public: 46 public:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 virtual void SetUp() { 82 virtual void SetUp() {
82 // Save the global memory cache to restore it upon teardown. 83 // Save the global memory cache to restore it upon teardown.
83 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()); 84 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create());
84 } 85 }
85 86
86 virtual void TearDown() { 87 virtual void TearDown() {
87 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); 88 replaceMemoryCacheForTesting(m_globalMemoryCache.release());
88 } 89 }
89 90
90 Persistent<MemoryCache> m_globalMemoryCache; 91 Persistent<MemoryCache> m_globalMemoryCache;
92 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
93 m_platform;
91 }; 94 };
92 95
93 // Verifies that setters and getters for cache capacities work correcty. 96 // Verifies that setters and getters for cache capacities work correcty.
94 TEST_F(MemoryCacheTest, CapacityAccounting) { 97 TEST_F(MemoryCacheTest, CapacityAccounting) {
95 const size_t sizeMax = ~static_cast<size_t>(0); 98 const size_t sizeMax = ~static_cast<size_t>(0);
96 const size_t totalCapacity = sizeMax / 4; 99 const size_t totalCapacity = sizeMax / 4;
97 memoryCache()->setCapacity(totalCapacity); 100 memoryCache()->setCapacity(totalCapacity);
98 EXPECT_EQ(totalCapacity, memoryCache()->capacity()); 101 EXPECT_EQ(totalCapacity, memoryCache()->capacity());
99 } 102 }
100 103
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 resource2->finish(); 176 resource2->finish();
174 177
175 Platform::current()->currentThread()->getWebTaskRunner()->postTask( 178 Platform::current()->currentThread()->getWebTaskRunner()->postTask(
176 BLINK_FROM_HERE, WTF::bind(&runTask1, wrapPersistent(resource1), 179 BLINK_FROM_HERE, WTF::bind(&runTask1, wrapPersistent(resource1),
177 wrapPersistent(resource2))); 180 wrapPersistent(resource2)));
178 Platform::current()->currentThread()->getWebTaskRunner()->postTask( 181 Platform::current()->currentThread()->getWebTaskRunner()->postTask(
179 BLINK_FROM_HERE, 182 BLINK_FROM_HERE,
180 WTF::bind(&runTask2, 183 WTF::bind(&runTask2,
181 resource1->encodedSize() + resource1->overheadSize() + 184 resource1->encodedSize() + resource1->overheadSize() +
182 resource2->encodedSize() + resource2->overheadSize())); 185 resource2->encodedSize() + resource2->overheadSize()));
183 testing::runPendingTasks(); 186 static_cast<TestingPlatformSupportWithMockScheduler*>(Platform::current())
187 ->runUntilIdle();
184 } 188 }
185 189
186 // Verified that when ordering a prune in a runLoop task, the prune 190 // Verified that when ordering a prune in a runLoop task, the prune
187 // is deferred to the end of the task. 191 // is deferred to the end of the task.
188 TEST_F(MemoryCacheTest, ResourcePruningAtEndOfTask_Basic) { 192 TEST_F(MemoryCacheTest, ResourcePruningAtEndOfTask_Basic) {
189 Resource* resource1 = FakeDecodedResource::create( 193 Resource* resource1 = FakeDecodedResource::create(
190 ResourceRequest("http://test/resource1"), Resource::Raw); 194 ResourceRequest("http://test/resource1"), Resource::Raw);
191 Resource* resource2 = FakeDecodedResource::create( 195 Resource* resource2 = FakeDecodedResource::create(
192 ResourceRequest("http://test/resource2"), Resource::Raw); 196 ResourceRequest("http://test/resource2"), Resource::Raw);
193 testResourcePruningAtEndOfTask(resource1, resource2); 197 testResourcePruningAtEndOfTask(resource1, resource2);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 FakeResource* resource2 = 393 FakeResource* resource2 =
390 FakeResource::create(ResourceRequest(url2), Resource::Raw); 394 FakeResource::create(ResourceRequest(url2), Resource::Raw);
391 memoryCache()->add(resource2); 395 memoryCache()->add(resource2);
392 EXPECT_TRUE(memoryCache()->contains(resource2)); 396 EXPECT_TRUE(memoryCache()->contains(resource2));
393 397
394 memoryCache()->removeURLFromCache(url2); 398 memoryCache()->removeURLFromCache(url2);
395 EXPECT_FALSE(memoryCache()->contains(resource2)); 399 EXPECT_FALSE(memoryCache()->contains(resource2));
396 } 400 }
397 401
398 } // namespace blink 402 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698