summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
diff options
context:
space:
mode:
authorjaphet <japhet@chromium.org>2015-10-23 12:04:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-23 19:04:58 +0000
commitaadbd2624c5003698624cf2e21fd6ae876e28629 (patch)
tree9d1bb4a8259c59491ecb55602f6d77813eec30f2 /third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
parent75f8614691dcbe73f10d690c11af9d33c7e92530 (diff)
downloadchromium_src-aadbd2624c5003698624cf2e21fd6ae876e28629.zip
chromium_src-aadbd2624c5003698624cf2e21fd6ae876e28629.tar.gz
chromium_src-aadbd2624c5003698624cf2e21fd6ae876e28629.tar.bz2
Revalidate using the same Resource, attempt #4
Currently, when we perform a revalidation, we create a new resource and put it in the MemoryCache in place of the resource being revalidated. If the revalidation results in a 304, we silently swap all of the clients of the revalidation to the now-revalidated resource and swap which Resource is in the MemoryCache. This changes the behavior to use the existing resource to revalidate itself, which simplifies the logic quite a bit. It also gives us the option of removing ResourcePtr (which is used to implement the silent client swap in the 304 case) and make Resources simply RefCounted in a future change. BUG=545215 Review URL: https://codereview.chromium.org/1412413003 Cr-Commit-Position: refs/heads/master@{#355850}
Diffstat (limited to 'third_party/WebKit/Source/core/fetch/RawResourceTest.cpp')
-rw-r--r--third_party/WebKit/Source/core/fetch/RawResourceTest.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp b/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
index 164c2c9..617b116 100644
--- a/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
@@ -62,27 +62,25 @@ TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse)
TEST(RawResourceTest, RevalidationSucceeded)
{
- // Create two RawResources and set one to revalidate the other.
- RawResource* oldResourcePointer = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw);
- RawResource* newResourcePointer = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw);
- newResourcePointer->setResourceToRevalidate(oldResourcePointer);
- ResourcePtr<Resource> oldResource = oldResourcePointer;
- ResourcePtr<Resource> newResource = newResourcePointer;
- memoryCache()->add(oldResource.get());
- memoryCache()->remove(oldResource.get());
- memoryCache()->add(newResource.get());
+ ResourcePtr<Resource> resource = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw);
+ ResourceResponse response;
+ response.setHTTPStatusCode(200);
+ resource->responseReceived(response, nullptr);
+ const char data[5] = "abcd";
+ resource->appendData(data, 4);
+ resource->finish();
+ memoryCache()->add(resource.get());
// Simulate a successful revalidation.
- // The revalidated resource (oldResource) should now be in the cache, newResource
- // should have been sliently switched to point to the revalidated resource, and
- // we shouldn't hit any ASSERTs.
- ResourceResponse response;
- response.setHTTPStatusCode(304);
- newResource->responseReceived(response, nullptr);
- EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/html,")), oldResource.get());
- EXPECT_EQ(oldResource.get(), newResource.get());
- EXPECT_NE(newResource.get(), newResourcePointer);
- memoryCache()->remove(newResource.get());
+ resource->setRevalidatingRequest(ResourceRequest("data:text/html,"));
+ ResourceResponse revalidatingResponse;
+ revalidatingResponse.setHTTPStatusCode(304);
+ resource->responseReceived(revalidatingResponse, nullptr);
+ EXPECT_FALSE(resource->isCacheValidator());
+ EXPECT_EQ(200, resource->response().httpStatusCode());
+ EXPECT_EQ(4u, resource->resourceBuffer()->size());
+ EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/html,")), resource.get());
+ memoryCache()->remove(resource.get());
}
class DummyClient : public RawResourceClient {