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