| 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/fetch/RawResource.h" | 31 #include "core/fetch/RawResource.h" |
| 32 | 32 |
| 33 #include "core/fetch/ImageResourceClient.h" | |
| 34 #include "core/fetch/MemoryCache.h" | 33 #include "core/fetch/MemoryCache.h" |
| 35 #include "core/fetch/MockImageResourceClient.h" | |
| 36 #include "core/fetch/ResourceFetcher.h" | 34 #include "core/fetch/ResourceFetcher.h" |
| 37 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
| 38 #include "platform/testing/UnitTestHelpers.h" | 36 #include "platform/testing/UnitTestHelpers.h" |
| 39 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebURL.h" | 38 #include "public/platform/WebURL.h" |
| 41 #include "public/platform/WebURLResponse.h" | 39 #include "public/platform/WebURLResponse.h" |
| 42 #include "public/platform/WebUnitTestSupport.h" | 40 #include "public/platform/WebUnitTestSupport.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 44 | 42 |
| 45 namespace blink { | 43 namespace blink { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 ResourceResponse revalidatingResponse; | 129 ResourceResponse revalidatingResponse; |
| 132 revalidatingResponse.setHTTPStatusCode(304); | 130 revalidatingResponse.setHTTPStatusCode(304); |
| 133 resource->responseReceived(revalidatingResponse, nullptr); | 131 resource->responseReceived(revalidatingResponse, nullptr); |
| 134 EXPECT_FALSE(resource->isCacheValidator()); | 132 EXPECT_FALSE(resource->isCacheValidator()); |
| 135 EXPECT_EQ(200, resource->response().httpStatusCode()); | 133 EXPECT_EQ(200, resource->response().httpStatusCode()); |
| 136 EXPECT_EQ(4u, resource->resourceBuffer()->size()); | 134 EXPECT_EQ(4u, resource->resourceBuffer()->size()); |
| 137 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); | 135 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); |
| 138 memoryCache()->remove(resource.get()); | 136 memoryCache()->remove(resource.get()); |
| 139 | 137 |
| 140 resource->removeClient(client.get()); | 138 resource->removeClient(client.get()); |
| 141 EXPECT_FALSE(resource->hasClients()); | 139 EXPECT_FALSE(resource->hasClientsOrObservers()); |
| 142 EXPECT_FALSE(client->called()); | 140 EXPECT_FALSE(client->called()); |
| 143 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); | 141 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); |
| 144 } | 142 } |
| 145 | 143 |
| 146 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody) | 144 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody) |
| 147 { | 145 { |
| 148 RefPtrWillBeRawPtr<Resource> resource = RawResource::create(ResourceRequest(
"data:text/html,"), Resource::Raw); | 146 RefPtrWillBeRawPtr<Resource> resource = RawResource::create(ResourceRequest(
"data:text/html,"), Resource::Raw); |
| 149 ResourceResponse response; | 147 ResourceResponse response; |
| 150 response.setHTTPStatusCode(200); | 148 response.setHTTPStatusCode(200); |
| 151 resource->responseReceived(response, nullptr); | 149 resource->responseReceived(response, nullptr); |
| 152 resource->finish(); | 150 resource->finish(); |
| 153 memoryCache()->add(resource.get()); | 151 memoryCache()->add(resource.get()); |
| 154 | 152 |
| 155 // Simulate a successful revalidation. | 153 // Simulate a successful revalidation. |
| 156 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); | 154 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); |
| 157 | 155 |
| 158 OwnPtr<DummyClient> client = adoptPtr(new DummyClient); | 156 OwnPtr<DummyClient> client = adoptPtr(new DummyClient); |
| 159 resource->addClient(client.get()); | 157 resource->addClient(client.get()); |
| 160 | 158 |
| 161 ResourceResponse revalidatingResponse; | 159 ResourceResponse revalidatingResponse; |
| 162 revalidatingResponse.setHTTPStatusCode(304); | 160 revalidatingResponse.setHTTPStatusCode(304); |
| 163 resource->responseReceived(revalidatingResponse, nullptr); | 161 resource->responseReceived(revalidatingResponse, nullptr); |
| 164 EXPECT_FALSE(resource->isCacheValidator()); | 162 EXPECT_FALSE(resource->isCacheValidator()); |
| 165 EXPECT_EQ(200, resource->response().httpStatusCode()); | 163 EXPECT_EQ(200, resource->response().httpStatusCode()); |
| 166 EXPECT_EQ(nullptr, resource->resourceBuffer()); | 164 EXPECT_EQ(nullptr, resource->resourceBuffer()); |
| 167 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); | 165 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); |
| 168 memoryCache()->remove(resource.get()); | 166 memoryCache()->remove(resource.get()); |
| 169 | 167 |
| 170 resource->removeClient(client.get()); | 168 resource->removeClient(client.get()); |
| 171 EXPECT_FALSE(resource->hasClients()); | 169 EXPECT_FALSE(resource->hasClientsOrObservers()); |
| 172 EXPECT_FALSE(client->called()); | 170 EXPECT_FALSE(client->called()); |
| 173 EXPECT_EQ(0u, client->data().size()); | 171 EXPECT_EQ(0u, client->data().size()); |
| 174 } | 172 } |
| 175 | 173 |
| 176 TEST(RawResourceTest, AddClientDuringCallback) | 174 TEST(RawResourceTest, AddClientDuringCallback) |
| 177 { | 175 { |
| 178 RefPtrWillBeRawPtr<Resource> raw = RawResource::create(ResourceRequest("data
:text/html,"), Resource::Raw); | 176 RefPtrWillBeRawPtr<Resource> raw = RawResource::create(ResourceRequest("data
:text/html,"), Resource::Raw); |
| 179 | 177 |
| 180 // Create a non-null response. | 178 // Create a non-null response. |
| 181 ResourceResponse response = raw->response(); | 179 ResourceResponse response = raw->response(); |
| 182 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 180 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
| 183 raw->setResponse(response); | 181 raw->setResponse(response); |
| 184 raw->finish(); | 182 raw->finish(); |
| 185 EXPECT_FALSE(raw->response().isNull()); | 183 EXPECT_FALSE(raw->response().isNull()); |
| 186 | 184 |
| 187 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 185 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
| 188 OwnPtr<AddingClient> addingClient = adoptPtr(new AddingClient(dummyClient.ge
t(), raw.get())); | 186 OwnPtr<AddingClient> addingClient = adoptPtr(new AddingClient(dummyClient.ge
t(), raw.get())); |
| 189 raw->addClient(addingClient.get()); | 187 raw->addClient(addingClient.get()); |
| 190 testing::runPendingTasks(); | 188 testing::runPendingTasks(); |
| 191 raw->removeClient(addingClient.get()); | 189 raw->removeClient(addingClient.get()); |
| 192 EXPECT_FALSE(dummyClient->called()); | 190 EXPECT_FALSE(dummyClient->called()); |
| 193 EXPECT_FALSE(raw->hasClients()); | 191 EXPECT_FALSE(raw->hasClientsOrObservers()); |
| 194 } | 192 } |
| 195 | 193 |
| 196 // This client removes another client when notified. | 194 // This client removes another client when notified. |
| 197 class RemovingClient : public RawResourceClient { | 195 class RemovingClient : public RawResourceClient { |
| 198 public: | 196 public: |
| 199 RemovingClient(DummyClient* client) | 197 RemovingClient(DummyClient* client) |
| 200 : m_dummyClient(client) {} | 198 : m_dummyClient(client) {} |
| 201 | 199 |
| 202 ~RemovingClient() override {} | 200 ~RemovingClient() override {} |
| 203 | 201 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 221 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 219 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
| 222 raw->setResponse(response); | 220 raw->setResponse(response); |
| 223 raw->finish(); | 221 raw->finish(); |
| 224 EXPECT_FALSE(raw->response().isNull()); | 222 EXPECT_FALSE(raw->response().isNull()); |
| 225 | 223 |
| 226 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 224 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
| 227 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); | 225 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); |
| 228 raw->addClient(dummyClient.get()); | 226 raw->addClient(dummyClient.get()); |
| 229 raw->addClient(removingClient.get()); | 227 raw->addClient(removingClient.get()); |
| 230 testing::runPendingTasks(); | 228 testing::runPendingTasks(); |
| 231 EXPECT_FALSE(raw->hasClients()); | 229 EXPECT_FALSE(raw->hasClientsOrObservers()); |
| 232 } | 230 } |
| 233 | 231 |
| 234 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |