| OLD | NEW |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 ResourcePtr<RawResource> jpegResource(new RawResource(jpegRequest, Resource:
:Raw)); | 53 ResourcePtr<RawResource> jpegResource(new RawResource(jpegRequest, Resource:
:Raw)); |
| 54 | 54 |
| 55 ResourceRequest pngRequest; | 55 ResourceRequest pngRequest; |
| 56 pngRequest.setHTTPAccept("image/png"); | 56 pngRequest.setHTTPAccept("image/png"); |
| 57 | 57 |
| 58 ASSERT_FALSE(jpegResource->canReuse(pngRequest)); | 58 ASSERT_FALSE(jpegResource->canReuse(pngRequest)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 TEST(RawResourceTest, RevalidationSucceeded) | 61 TEST(RawResourceTest, RevalidationSucceeded) |
| 62 { | 62 { |
| 63 ResourcePtr<Resource> resource(new RawResource(ResourceRequest("data:text/ht
ml,"), Resource::Raw)); | 63 // Create two RawResources and set one to revalidate the other. |
| 64 ResourceResponse response; | 64 RawResource* oldResourcePointer = new RawResource(ResourceRequest("data:text
/html,"), Resource::Raw); |
| 65 response.setHTTPStatusCode(200); | 65 RawResource* newResourcePointer = new RawResource(ResourceRequest("data:text
/html,"), Resource::Raw); |
| 66 resource->responseReceived(response, nullptr); | 66 newResourcePointer->setResourceToRevalidate(oldResourcePointer); |
| 67 const char data[5] = "abcd"; | 67 ResourcePtr<Resource> oldResource = oldResourcePointer; |
| 68 resource->appendData(data, 4); | 68 ResourcePtr<Resource> newResource = newResourcePointer; |
| 69 resource->finish(); | 69 memoryCache()->add(oldResource.get()); |
| 70 memoryCache()->add(resource.get()); | 70 memoryCache()->remove(oldResource.get()); |
| 71 memoryCache()->add(newResource.get()); |
| 71 | 72 |
| 72 // Simulate a successful revalidation. | 73 // Simulate a successful revalidation. |
| 73 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); | 74 // The revalidated resource (oldResource) should now be in the cache, newRes
ource |
| 74 ResourceResponse revalidatingResponse; | 75 // should have been sliently switched to point to the revalidated resource,
and |
| 75 revalidatingResponse.setHTTPStatusCode(304); | 76 // we shouldn't hit any ASSERTs. |
| 76 resource->responseReceived(revalidatingResponse, nullptr); | 77 ResourceResponse response; |
| 77 EXPECT_FALSE(resource->isCacheValidator()); | 78 response.setHTTPStatusCode(304); |
| 78 EXPECT_EQ(200, resource->response().httpStatusCode()); | 79 newResource->responseReceived(response, nullptr); |
| 79 EXPECT_EQ(4u, resource->resourceBuffer()->size()); | 80 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), oldResource.get()); |
| 80 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); | 81 EXPECT_EQ(oldResource.get(), newResource.get()); |
| 82 EXPECT_NE(newResource.get(), newResourcePointer); |
| 81 } | 83 } |
| 82 | 84 |
| 83 class DummyClient : public RawResourceClient { | 85 class DummyClient : public RawResourceClient { |
| 84 public: | 86 public: |
| 85 DummyClient() : m_called(false) {} | 87 DummyClient() : m_called(false) {} |
| 86 ~DummyClient() override {} | 88 ~DummyClient() override {} |
| 87 | 89 |
| 88 // ResourceClient implementation. | 90 // ResourceClient implementation. |
| 89 virtual void notifyFinished(Resource* resource) | 91 virtual void notifyFinished(Resource* resource) |
| 90 { | 92 { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 177 |
| 176 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 178 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
| 177 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); | 179 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); |
| 178 raw->addClient(dummyClient.get()); | 180 raw->addClient(dummyClient.get()); |
| 179 raw->addClient(removingClient.get()); | 181 raw->addClient(removingClient.get()); |
| 180 testing::runPendingTasks(); | 182 testing::runPendingTasks(); |
| 181 EXPECT_FALSE(raw->hasClients()); | 183 EXPECT_FALSE(raw->hasClients()); |
| 182 } | 184 } |
| 183 | 185 |
| 184 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |