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