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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fetch/ResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
index 42dd25d715e5b200fdde4f703ca3d4942d46a512..a91cc38da54961baa506136a95622951354e2c79 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
@@ -4,6 +4,8 @@
#include "core/fetch/Resource.h"
+#include "core/fetch/MemoryCache.h"
+#include "platform/SharedBuffer.h"
#include "platform/network/ResourceRequest.h"
#include "platform/network/ResourceResponse.h"
#include "platform/testing/TestingPlatformSupport.h"
@@ -16,6 +18,22 @@ namespace blink {
namespace {
+class UnlockableResource : public Resource {
+public:
+ static RefPtrWillBeRawPtr<UnlockableResource> create(const KURL& url)
+ {
+ return adoptRefWillBeNoop(new UnlockableResource(ResourceRequest(url), Resource::Raw));
+ }
+
+private:
+ UnlockableResource(const ResourceRequest& request, Type type)
+ : Resource(request, type)
+ {
+ }
+
+ bool isSafeToUnlock() const override { return true; }
+};
+
class MockPlatform final : public TestingPlatformSupport {
public:
MockPlatform() { }
@@ -72,4 +90,27 @@ TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedVia
EXPECT_EQ(0u, mock.cachedURLs().size());
}
+TEST(ResourceTest, LockFailureNoCrash)
+{
+ ResourceResponse response(createTestResourceResponse());
+ RefPtrWillBeRawPtr<UnlockableResource> resource = UnlockableResource::create(response.url());
+ memoryCache()->add(resource.get());
+ resource->setResponse(response);
+
+ // A Resource won't be put in DiscardableMemory unless it is at least 16KiB.
+ Vector<char> dataVector(4*4096);
+ for (int i = 0; i < 4096; i++)
+ dataVector.append("test", 4);
+ resource->setResourceBuffer(SharedBuffer::adoptVector(dataVector));
+
+ resource->setLoadFinishTime(currentTime());
+ resource->finish();
+ resource->prune();
+ ASSERT_TRUE(resource->isPurgeable());
+ bool didLock = resource->lock();
+ ASSERT_FALSE(didLock);
+ EXPECT_EQ(nullptr, resource->resourceBuffer());
+ EXPECT_EQ(size_t(0), resource->encodedSize());
+}
+
} // namespace blink
« 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