| 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 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 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 "platform/loader/fetch/RawResource.h" |
| 32 | 32 |
| 33 #include "core/fetch/MemoryCache.h" | |
| 34 #include "core/fetch/ResourceFetcher.h" | |
| 35 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
| 36 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
| 35 #include "platform/loader/fetch/MemoryCache.h" |
| 36 #include "platform/loader/fetch/ResourceFetcher.h" |
| 37 #include "platform/network/ResourceTimingInfo.h" | 37 #include "platform/network/ResourceTimingInfo.h" |
| 38 #include "platform/testing/TestingPlatformSupport.h" |
| 38 #include "platform/testing/UnitTestHelpers.h" | 39 #include "platform/testing/UnitTestHelpers.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebScheduler.h" | 41 #include "public/platform/WebScheduler.h" |
| 41 #include "public/platform/WebThread.h" | 42 #include "public/platform/WebThread.h" |
| 42 #include "public/platform/WebURL.h" | 43 #include "public/platform/WebURL.h" |
| 43 #include "public/platform/WebURLResponse.h" | 44 #include "public/platform/WebURLResponse.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| 49 using ::testing::InSequence; | 50 using ::testing::InSequence; |
| 50 using ::testing::_; | 51 using ::testing::_; |
| 51 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; | 52 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; |
| 52 | 53 |
| 54 class RawResourceTest : public ::testing::Test { |
| 55 public: |
| 56 RawResourceTest() {} |
| 57 ~RawResourceTest() override {} |
| 58 |
| 59 protected: |
| 60 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 61 m_platform; |
| 62 |
| 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(RawResourceTest); |
| 65 }; |
| 66 |
| 53 class MockRawResourceClient | 67 class MockRawResourceClient |
| 54 : public GarbageCollectedFinalized<MockRawResourceClient>, | 68 : public GarbageCollectedFinalized<MockRawResourceClient>, |
| 55 public RawResourceClient { | 69 public RawResourceClient { |
| 56 USING_GARBAGE_COLLECTED_MIXIN(MockRawResourceClient); | 70 USING_GARBAGE_COLLECTED_MIXIN(MockRawResourceClient); |
| 57 | 71 |
| 58 public: | 72 public: |
| 59 static MockRawResourceClient* create() { | 73 static MockRawResourceClient* create() { |
| 60 return new ::testing::StrictMock<MockRawResourceClient>; | 74 return new ::testing::StrictMock<MockRawResourceClient>; |
| 61 } | 75 } |
| 62 | 76 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 86 } | 100 } |
| 87 | 101 |
| 88 String debugName() const override { return "MockRawResourceClient"; } | 102 String debugName() const override { return "MockRawResourceClient"; } |
| 89 | 103 |
| 90 DEFINE_INLINE_VIRTUAL_TRACE() { RawResourceClient::trace(visitor); } | 104 DEFINE_INLINE_VIRTUAL_TRACE() { RawResourceClient::trace(visitor); } |
| 91 | 105 |
| 92 protected: | 106 protected: |
| 93 MockRawResourceClient() = default; | 107 MockRawResourceClient() = default; |
| 94 }; | 108 }; |
| 95 | 109 |
| 96 TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse) { | 110 TEST_F(RawResourceTest, DontIgnoreAcceptForCacheReuse) { |
| 97 ResourceRequest jpegRequest; | 111 ResourceRequest jpegRequest; |
| 98 jpegRequest.setHTTPAccept("image/jpeg"); | 112 jpegRequest.setHTTPAccept("image/jpeg"); |
| 99 | 113 |
| 100 RawResource* jpegResource(RawResource::create(jpegRequest, Resource::Raw)); | 114 RawResource* jpegResource(RawResource::create(jpegRequest, Resource::Raw)); |
| 101 | 115 |
| 102 ResourceRequest pngRequest; | 116 ResourceRequest pngRequest; |
| 103 pngRequest.setHTTPAccept("image/png"); | 117 pngRequest.setHTTPAccept("image/png"); |
| 104 | 118 |
| 105 EXPECT_FALSE(jpegResource->canReuse(pngRequest)); | 119 EXPECT_FALSE(jpegResource->canReuse(pngRequest)); |
| 106 } | 120 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 visitor->trace(m_dummyClient); | 185 visitor->trace(m_dummyClient); |
| 172 visitor->trace(m_resource); | 186 visitor->trace(m_resource); |
| 173 RawResourceClient::trace(visitor); | 187 RawResourceClient::trace(visitor); |
| 174 } | 188 } |
| 175 | 189 |
| 176 private: | 190 private: |
| 177 Member<DummyClient> m_dummyClient; | 191 Member<DummyClient> m_dummyClient; |
| 178 Member<Resource> m_resource; | 192 Member<Resource> m_resource; |
| 179 }; | 193 }; |
| 180 | 194 |
| 181 TEST(RawResourceTest, RevalidationSucceeded) { | 195 TEST_F(RawResourceTest, RevalidationSucceeded) { |
| 182 Resource* resource = | 196 Resource* resource = |
| 183 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); | 197 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); |
| 184 ResourceResponse response; | 198 ResourceResponse response; |
| 185 response.setHTTPStatusCode(200); | 199 response.setHTTPStatusCode(200); |
| 186 resource->responseReceived(response, nullptr); | 200 resource->responseReceived(response, nullptr); |
| 187 const char data[5] = "abcd"; | 201 const char data[5] = "abcd"; |
| 188 resource->appendData(data, 4); | 202 resource->appendData(data, 4); |
| 189 resource->finish(); | 203 resource->finish(); |
| 190 memoryCache()->add(resource); | 204 memoryCache()->add(resource); |
| 191 | 205 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 204 EXPECT_EQ(resource, memoryCache()->resourceForURL( | 218 EXPECT_EQ(resource, memoryCache()->resourceForURL( |
| 205 KURL(ParsedURLString, "data:text/html,"))); | 219 KURL(ParsedURLString, "data:text/html,"))); |
| 206 memoryCache()->remove(resource); | 220 memoryCache()->remove(resource); |
| 207 | 221 |
| 208 resource->removeClient(client); | 222 resource->removeClient(client); |
| 209 EXPECT_FALSE(resource->isAlive()); | 223 EXPECT_FALSE(resource->isAlive()); |
| 210 EXPECT_FALSE(client->called()); | 224 EXPECT_FALSE(client->called()); |
| 211 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); | 225 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); |
| 212 } | 226 } |
| 213 | 227 |
| 214 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody) { | 228 TEST_F(RawResourceTest, RevalidationSucceededForResourceWithoutBody) { |
| 215 Resource* resource = | 229 Resource* resource = |
| 216 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); | 230 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); |
| 217 ResourceResponse response; | 231 ResourceResponse response; |
| 218 response.setHTTPStatusCode(200); | 232 response.setHTTPStatusCode(200); |
| 219 resource->responseReceived(response, nullptr); | 233 resource->responseReceived(response, nullptr); |
| 220 resource->finish(); | 234 resource->finish(); |
| 221 memoryCache()->add(resource); | 235 memoryCache()->add(resource); |
| 222 | 236 |
| 223 // Simulate a successful revalidation. | 237 // Simulate a successful revalidation. |
| 224 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); | 238 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 235 EXPECT_EQ(resource, memoryCache()->resourceForURL( | 249 EXPECT_EQ(resource, memoryCache()->resourceForURL( |
| 236 KURL(ParsedURLString, "data:text/html,"))); | 250 KURL(ParsedURLString, "data:text/html,"))); |
| 237 memoryCache()->remove(resource); | 251 memoryCache()->remove(resource); |
| 238 | 252 |
| 239 resource->removeClient(client); | 253 resource->removeClient(client); |
| 240 EXPECT_FALSE(resource->isAlive()); | 254 EXPECT_FALSE(resource->isAlive()); |
| 241 EXPECT_FALSE(client->called()); | 255 EXPECT_FALSE(client->called()); |
| 242 EXPECT_EQ(0u, client->data().size()); | 256 EXPECT_EQ(0u, client->data().size()); |
| 243 } | 257 } |
| 244 | 258 |
| 245 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders) { | 259 TEST_F(RawResourceTest, RevalidationSucceededUpdateHeaders) { |
| 246 Resource* resource = | 260 Resource* resource = |
| 247 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); | 261 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); |
| 248 ResourceResponse response; | 262 ResourceResponse response; |
| 249 response.setHTTPStatusCode(200); | 263 response.setHTTPStatusCode(200); |
| 250 response.addHTTPHeaderField("keep-alive", "keep-alive value"); | 264 response.addHTTPHeaderField("keep-alive", "keep-alive value"); |
| 251 response.addHTTPHeaderField("expires", "expires value"); | 265 response.addHTTPHeaderField("expires", "expires value"); |
| 252 response.addHTTPHeaderField("last-modified", "last-modified value"); | 266 response.addHTTPHeaderField("last-modified", "last-modified value"); |
| 253 response.addHTTPHeaderField("proxy-authenticate", "proxy-authenticate value"); | 267 response.addHTTPHeaderField("proxy-authenticate", "proxy-authenticate value"); |
| 254 response.addHTTPHeaderField("proxy-connection", "proxy-connection value"); | 268 response.addHTTPHeaderField("proxy-connection", "proxy-connection value"); |
| 255 response.addHTTPHeaderField("x-custom", "custom value"); | 269 response.addHTTPHeaderField("x-custom", "custom value"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 EXPECT_EQ("updated", resource->response().httpHeaderField("x-custom")); | 322 EXPECT_EQ("updated", resource->response().httpHeaderField("x-custom")); |
| 309 | 323 |
| 310 memoryCache()->remove(resource); | 324 memoryCache()->remove(resource); |
| 311 | 325 |
| 312 resource->removeClient(client); | 326 resource->removeClient(client); |
| 313 EXPECT_FALSE(resource->isAlive()); | 327 EXPECT_FALSE(resource->isAlive()); |
| 314 EXPECT_FALSE(client->called()); | 328 EXPECT_FALSE(client->called()); |
| 315 EXPECT_EQ(0u, client->data().size()); | 329 EXPECT_EQ(0u, client->data().size()); |
| 316 } | 330 } |
| 317 | 331 |
| 318 TEST(RawResourceTest, RedirectDuringRevalidation) { | 332 TEST_F(RawResourceTest, RedirectDuringRevalidation) { |
| 319 Resource* resource = RawResource::create( | 333 Resource* resource = RawResource::create( |
| 320 ResourceRequest("https://example.com/1"), Resource::Raw); | 334 ResourceRequest("https://example.com/1"), Resource::Raw); |
| 321 ResourceResponse response; | 335 ResourceResponse response; |
| 322 response.setURL(KURL(ParsedURLString, "https://example.com/1")); | 336 response.setURL(KURL(ParsedURLString, "https://example.com/1")); |
| 323 response.setHTTPStatusCode(200); | 337 response.setHTTPStatusCode(200); |
| 324 resource->responseReceived(response, nullptr); | 338 resource->responseReceived(response, nullptr); |
| 325 const char data[5] = "abcd"; | 339 const char data[5] = "abcd"; |
| 326 resource->appendData(data, 4); | 340 resource->appendData(data, 4); |
| 327 resource->finish(); | 341 resource->finish(); |
| 328 memoryCache()->add(resource); | 342 memoryCache()->add(resource); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 392 |
| 379 EXPECT_TRUE(client->called()); | 393 EXPECT_TRUE(client->called()); |
| 380 EXPECT_EQ(1, client->numberOfRedirectsReceived()); | 394 EXPECT_EQ(1, client->numberOfRedirectsReceived()); |
| 381 EXPECT_EQ("xyz", String(client->data().data(), client->data().size())); | 395 EXPECT_EQ("xyz", String(client->data().data(), client->data().size())); |
| 382 | 396 |
| 383 // Test the case where a client is added after revalidation is completed. | 397 // Test the case where a client is added after revalidation is completed. |
| 384 Persistent<DummyClient> client2 = new DummyClient; | 398 Persistent<DummyClient> client2 = new DummyClient; |
| 385 resource->addClient(client2); | 399 resource->addClient(client2); |
| 386 | 400 |
| 387 // Because RawResourceClient is added asynchronously, | 401 // Because RawResourceClient is added asynchronously, |
| 388 // |runPendingTasks()| is called to make |client2| to be notified. | 402 // |runUntilIdle()| is called to make |client2| to be notified. |
| 389 testing::runPendingTasks(); | 403 m_platform->runUntilIdle(); |
| 390 | 404 |
| 391 EXPECT_TRUE(client2->called()); | 405 EXPECT_TRUE(client2->called()); |
| 392 EXPECT_EQ(1, client2->numberOfRedirectsReceived()); | 406 EXPECT_EQ(1, client2->numberOfRedirectsReceived()); |
| 393 EXPECT_EQ("xyz", String(client2->data().data(), client2->data().size())); | 407 EXPECT_EQ("xyz", String(client2->data().data(), client2->data().size())); |
| 394 | 408 |
| 395 memoryCache()->remove(resource); | 409 memoryCache()->remove(resource); |
| 396 | 410 |
| 397 resource->removeClient(client); | 411 resource->removeClient(client); |
| 398 resource->removeClient(client2); | 412 resource->removeClient(client2); |
| 399 EXPECT_FALSE(resource->isAlive()); | 413 EXPECT_FALSE(resource->isAlive()); |
| 400 } | 414 } |
| 401 | 415 |
| 402 TEST(RawResourceTest, AddClientDuringCallback) { | 416 TEST_F(RawResourceTest, AddClientDuringCallback) { |
| 403 Resource* raw = | 417 Resource* raw = |
| 404 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); | 418 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); |
| 405 | 419 |
| 406 // Create a non-null response. | 420 // Create a non-null response. |
| 407 ResourceResponse response = raw->response(); | 421 ResourceResponse response = raw->response(); |
| 408 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 422 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
| 409 raw->setResponse(response); | 423 raw->setResponse(response); |
| 410 raw->finish(); | 424 raw->finish(); |
| 411 EXPECT_FALSE(raw->response().isNull()); | 425 EXPECT_FALSE(raw->response().isNull()); |
| 412 | 426 |
| 413 Persistent<DummyClient> dummyClient = new DummyClient(); | 427 Persistent<DummyClient> dummyClient = new DummyClient(); |
| 414 Persistent<AddingClient> addingClient = | 428 Persistent<AddingClient> addingClient = |
| 415 new AddingClient(dummyClient.get(), raw); | 429 new AddingClient(dummyClient.get(), raw); |
| 416 raw->addClient(addingClient); | 430 raw->addClient(addingClient); |
| 417 testing::runPendingTasks(); | 431 m_platform->runUntilIdle(); |
| 418 raw->removeClient(addingClient); | 432 raw->removeClient(addingClient); |
| 419 EXPECT_FALSE(dummyClient->called()); | 433 EXPECT_FALSE(dummyClient->called()); |
| 420 EXPECT_FALSE(raw->isAlive()); | 434 EXPECT_FALSE(raw->isAlive()); |
| 421 } | 435 } |
| 422 | 436 |
| 423 // This client removes another client when notified. | 437 // This client removes another client when notified. |
| 424 class RemovingClient : public GarbageCollectedFinalized<RemovingClient>, | 438 class RemovingClient : public GarbageCollectedFinalized<RemovingClient>, |
| 425 public RawResourceClient { | 439 public RawResourceClient { |
| 426 USING_GARBAGE_COLLECTED_MIXIN(RemovingClient); | 440 USING_GARBAGE_COLLECTED_MIXIN(RemovingClient); |
| 427 | 441 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 438 String debugName() const override { return "RemovingClient"; } | 452 String debugName() const override { return "RemovingClient"; } |
| 439 DEFINE_INLINE_TRACE() { | 453 DEFINE_INLINE_TRACE() { |
| 440 visitor->trace(m_dummyClient); | 454 visitor->trace(m_dummyClient); |
| 441 RawResourceClient::trace(visitor); | 455 RawResourceClient::trace(visitor); |
| 442 } | 456 } |
| 443 | 457 |
| 444 private: | 458 private: |
| 445 Member<DummyClient> m_dummyClient; | 459 Member<DummyClient> m_dummyClient; |
| 446 }; | 460 }; |
| 447 | 461 |
| 448 TEST(RawResourceTest, RemoveClientDuringCallback) { | 462 TEST_F(RawResourceTest, RemoveClientDuringCallback) { |
| 449 Resource* raw = | 463 Resource* raw = |
| 450 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); | 464 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); |
| 451 | 465 |
| 452 // Create a non-null response. | 466 // Create a non-null response. |
| 453 ResourceResponse response = raw->response(); | 467 ResourceResponse response = raw->response(); |
| 454 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 468 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
| 455 raw->setResponse(response); | 469 raw->setResponse(response); |
| 456 raw->finish(); | 470 raw->finish(); |
| 457 EXPECT_FALSE(raw->response().isNull()); | 471 EXPECT_FALSE(raw->response().isNull()); |
| 458 | 472 |
| 459 Persistent<DummyClient> dummyClient = new DummyClient(); | 473 Persistent<DummyClient> dummyClient = new DummyClient(); |
| 460 Persistent<RemovingClient> removingClient = | 474 Persistent<RemovingClient> removingClient = |
| 461 new RemovingClient(dummyClient.get()); | 475 new RemovingClient(dummyClient.get()); |
| 462 raw->addClient(dummyClient); | 476 raw->addClient(dummyClient); |
| 463 raw->addClient(removingClient); | 477 raw->addClient(removingClient); |
| 464 testing::runPendingTasks(); | 478 m_platform->runUntilIdle(); |
| 465 EXPECT_FALSE(raw->isAlive()); | 479 EXPECT_FALSE(raw->isAlive()); |
| 466 } | 480 } |
| 467 | 481 |
| 468 // ResourceClient can be added to |m_clients| asynchronously via | 482 // ResourceClient can be added to |m_clients| asynchronously via |
| 469 // ResourceCallback. When revalidation is started after ResourceCallback is | 483 // ResourceCallback. When revalidation is started after ResourceCallback is |
| 470 // scheduled and before it is dispatched, ResourceClient's callbacks should be | 484 // scheduled and before it is dispatched, ResourceClient's callbacks should be |
| 471 // called appropriately. | 485 // called appropriately. |
| 472 TEST(RawResourceTest, StartFailedRevalidationWhileResourceCallback) { | 486 TEST_F(RawResourceTest, StartFailedRevalidationWhileResourceCallback) { |
| 473 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 487 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 474 | 488 |
| 475 ResourceResponse response; | 489 ResourceResponse response; |
| 476 response.setURL(url); | 490 response.setURL(url); |
| 477 response.setHTTPStatusCode(200); | 491 response.setHTTPStatusCode(200); |
| 478 | 492 |
| 479 ResourceResponse newResponse; | 493 ResourceResponse newResponse; |
| 480 newResponse.setURL(url); | 494 newResponse.setURL(url); |
| 481 newResponse.setHTTPStatusCode(201); | 495 newResponse.setHTTPStatusCode(201); |
| 482 | 496 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 498 // Add a client. No callbacks are made here because ResourceCallback is | 512 // Add a client. No callbacks are made here because ResourceCallback is |
| 499 // scheduled asynchronously. | 513 // scheduled asynchronously. |
| 500 resource->addClient(client); | 514 resource->addClient(client); |
| 501 EXPECT_FALSE(resource->isCacheValidator()); | 515 EXPECT_FALSE(resource->isCacheValidator()); |
| 502 | 516 |
| 503 // Start revalidation. | 517 // Start revalidation. |
| 504 resource->setRevalidatingRequest(ResourceRequest(url)); | 518 resource->setRevalidatingRequest(ResourceRequest(url)); |
| 505 EXPECT_TRUE(resource->isCacheValidator()); | 519 EXPECT_TRUE(resource->isCacheValidator()); |
| 506 | 520 |
| 507 // Make the ResourceCallback to be dispatched. | 521 // Make the ResourceCallback to be dispatched. |
| 508 testing::runPendingTasks(); | 522 m_platform->runUntilIdle(); |
| 509 | 523 |
| 510 checkpoint.Call(1); | 524 checkpoint.Call(1); |
| 511 | 525 |
| 512 resource->responseReceived(newResponse, nullptr); | 526 resource->responseReceived(newResponse, nullptr); |
| 513 resource->appendData("newData", 8); | 527 resource->appendData("newData", 8); |
| 514 } | 528 } |
| 515 | 529 |
| 516 TEST(RawResourceTest, StartSuccessfulRevalidationWhileResourceCallback) { | 530 TEST_F(RawResourceTest, StartSuccessfulRevalidationWhileResourceCallback) { |
| 517 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 531 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 518 | 532 |
| 519 ResourceResponse response; | 533 ResourceResponse response; |
| 520 response.setURL(url); | 534 response.setURL(url); |
| 521 response.setHTTPStatusCode(200); | 535 response.setHTTPStatusCode(200); |
| 522 | 536 |
| 523 ResourceResponse newResponse; | 537 ResourceResponse newResponse; |
| 524 newResponse.setURL(url); | 538 newResponse.setURL(url); |
| 525 newResponse.setHTTPStatusCode(304); | 539 newResponse.setHTTPStatusCode(304); |
| 526 | 540 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 542 // Add a client. No callbacks are made here because ResourceCallback is | 556 // Add a client. No callbacks are made here because ResourceCallback is |
| 543 // scheduled asynchronously. | 557 // scheduled asynchronously. |
| 544 resource->addClient(client); | 558 resource->addClient(client); |
| 545 EXPECT_FALSE(resource->isCacheValidator()); | 559 EXPECT_FALSE(resource->isCacheValidator()); |
| 546 | 560 |
| 547 // Start revalidation. | 561 // Start revalidation. |
| 548 resource->setRevalidatingRequest(ResourceRequest(url)); | 562 resource->setRevalidatingRequest(ResourceRequest(url)); |
| 549 EXPECT_TRUE(resource->isCacheValidator()); | 563 EXPECT_TRUE(resource->isCacheValidator()); |
| 550 | 564 |
| 551 // Make the ResourceCallback to be dispatched. | 565 // Make the ResourceCallback to be dispatched. |
| 552 testing::runPendingTasks(); | 566 m_platform->runUntilIdle(); |
| 553 | 567 |
| 554 checkpoint.Call(1); | 568 checkpoint.Call(1); |
| 555 | 569 |
| 556 resource->responseReceived(newResponse, nullptr); | 570 resource->responseReceived(newResponse, nullptr); |
| 557 } | 571 } |
| 558 | 572 |
| 559 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) { | 573 TEST_F(RawResourceTest, |
| 574 CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) { |
| 560 ResourceRequest request("data:text/html,"); | 575 ResourceRequest request("data:text/html,"); |
| 561 request.setHTTPHeaderField( | 576 request.setHTTPHeaderField( |
| 562 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, "Foo"); | 577 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, "Foo"); |
| 563 Resource* raw = RawResource::create(request, Resource::Raw); | 578 Resource* raw = RawResource::create(request, Resource::Raw); |
| 564 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); | 579 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); |
| 565 } | 580 } |
| 566 | 581 |
| 567 } // namespace blink | 582 } // namespace blink |
| OLD | NEW |