diff options
author | japhet <japhet@chromium.org> | 2015-10-16 15:06:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-16 22:07:02 +0000 |
commit | 71adea27213b2268bda765abccd5a3bf9517b860 (patch) | |
tree | 98b7971cf3713ae612d49d7bb647a9e87e1aaf00 /third_party/WebKit/Source/core/fetch/RawResourceTest.cpp | |
parent | 58f5f8f27169a36b4dfc059dbc059db57be31e33 (diff) | |
download | chromium_src-71adea27213b2268bda765abccd5a3bf9517b860.zip chromium_src-71adea27213b2268bda765abccd5a3bf9517b860.tar.gz chromium_src-71adea27213b2268bda765abccd5a3bf9517b860.tar.bz2 |
Revalidate using the same Resource, attempt #3
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=
Review URL: https://codereview.chromium.org/1398523004
Cr-Commit-Position: refs/heads/master@{#354615}
Diffstat (limited to 'third_party/WebKit/Source/core/fetch/RawResourceTest.cpp')
-rw-r--r-- | third_party/WebKit/Source/core/fetch/RawResourceTest.cpp | 36 |
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 2b0a480..05fc5d4 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 { |