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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceTest.cpp

Issue 1802313003: Don't leave a discarded SharedBuffer on Resource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/fetch/Resource.h" 5 #include "core/fetch/Resource.h"
6 6
7 #include "core/fetch/MemoryCache.h"
8 #include "platform/SharedBuffer.h"
7 #include "platform/network/ResourceRequest.h" 9 #include "platform/network/ResourceRequest.h"
8 #include "platform/network/ResourceResponse.h" 10 #include "platform/network/ResourceResponse.h"
9 #include "platform/testing/TestingPlatformSupport.h" 11 #include "platform/testing/TestingPlatformSupport.h"
10 #include "platform/testing/URLTestHelpers.h" 12 #include "platform/testing/URLTestHelpers.h"
11 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 #include "wtf/Vector.h" 15 #include "wtf/Vector.h"
14 16
15 namespace blink { 17 namespace blink {
16 18
17 namespace { 19 namespace {
18 20
21 class UnlockableResource : public Resource {
22 public:
23 static RefPtrWillBeRawPtr<UnlockableResource> create(const KURL& url)
24 {
25 return adoptRefWillBeNoop(new UnlockableResource(ResourceRequest(url), R esource::Raw));
26 }
27
28 private:
29 UnlockableResource(const ResourceRequest& request, Type type)
30 : Resource(request, type)
31 {
32 }
33
34 bool isSafeToUnlock() const override { return true; }
35 };
36
19 class MockPlatform final : public TestingPlatformSupport { 37 class MockPlatform final : public TestingPlatformSupport {
20 public: 38 public:
21 MockPlatform() { } 39 MockPlatform() { }
22 ~MockPlatform() override { } 40 ~MockPlatform() override { }
23 41
24 // From blink::Platform: 42 // From blink::Platform:
25 void cacheMetadata(const WebURL& url, int64_t, const char*, size_t) override 43 void cacheMetadata(const WebURL& url, int64_t, const char*, size_t) override
26 { 44 {
27 m_cachedURLs.append(url); 45 m_cachedURLs.append(url);
28 } 46 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 83
66 TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedVia ServiceWorker) 84 TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedVia ServiceWorker)
67 { 85 {
68 MockPlatform mock; 86 MockPlatform mock;
69 ResourceResponse response(createTestResourceResponse()); 87 ResourceResponse response(createTestResourceResponse());
70 response.setWasFetchedViaServiceWorker(true); 88 response.setWasFetchedViaServiceWorker(true);
71 createTestResourceAndSetCachedMetadata(response); 89 createTestResourceAndSetCachedMetadata(response);
72 EXPECT_EQ(0u, mock.cachedURLs().size()); 90 EXPECT_EQ(0u, mock.cachedURLs().size());
73 } 91 }
74 92
93 TEST(ResourceTest, LockFailureNoCrash)
94 {
95 ResourceResponse response(createTestResourceResponse());
96 RefPtrWillBeRawPtr<UnlockableResource> resource = UnlockableResource::create (response.url());
97 memoryCache()->add(resource.get());
98 resource->setResponse(response);
99
100 // A Resource won't be put in DiscardableMemory unless it is at least 16KiB.
101 Vector<char> dataVector(4*4096);
102 for (int i = 0; i < 4096; i++)
103 dataVector.append("test", 4);
104 resource->setResourceBuffer(SharedBuffer::adoptVector(dataVector));
105
106 resource->setLoadFinishTime(currentTime());
107 resource->finish();
108 resource->prune();
109 ASSERT_TRUE(resource->isPurgeable());
110 bool didLock = resource->lock();
111 ASSERT_FALSE(didLock);
112 EXPECT_EQ(nullptr, resource->resourceBuffer());
113 EXPECT_EQ(size_t(0), resource->encodedSize());
114 }
115
75 } // namespace blink 116 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698