| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/loader/ThreadableLoader.h" | 5 #include "core/loader/ThreadableLoader.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContextTask.h" | 7 #include "core/dom/ExecutionContextTask.h" |
| 8 #include "core/loader/DocumentThreadableLoader.h" | 8 #include "core/loader/DocumentThreadableLoader.h" |
| 9 #include "core/loader/ThreadableLoaderClient.h" | 9 #include "core/loader/ThreadableLoaderClient.h" |
| 10 #include "core/loader/WorkerThreadableLoader.h" | 10 #include "core/loader/WorkerThreadableLoader.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 using ::testing::_; | 42 using ::testing::_; |
| 43 using ::testing::InSequence; | 43 using ::testing::InSequence; |
| 44 using ::testing::InvokeWithoutArgs; | 44 using ::testing::InvokeWithoutArgs; |
| 45 using ::testing::StrEq; | 45 using ::testing::StrEq; |
| 46 using ::testing::Truly; | 46 using ::testing::Truly; |
| 47 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; | 47 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; |
| 48 | 48 |
| 49 constexpr char kFileName[] = "fox-null-terminated.html"; |
| 50 |
| 49 class MockThreadableLoaderClient : public ThreadableLoaderClient { | 51 class MockThreadableLoaderClient : public ThreadableLoaderClient { |
| 50 public: | 52 public: |
| 51 static std::unique_ptr<MockThreadableLoaderClient> create() { | 53 static std::unique_ptr<MockThreadableLoaderClient> create() { |
| 52 return WTF::wrapUnique( | 54 return WTF::wrapUnique( |
| 53 new ::testing::StrictMock<MockThreadableLoaderClient>); | 55 new ::testing::StrictMock<MockThreadableLoaderClient>); |
| 54 } | 56 } |
| 55 MOCK_METHOD2(didSendData, void(unsigned long long, unsigned long long)); | 57 MOCK_METHOD2(didSendData, void(unsigned long long, unsigned long long)); |
| 56 MOCK_METHOD3(didReceiveResponseMock, | 58 MOCK_METHOD3(didReceiveResponseMock, |
| 57 void(unsigned long, | 59 void(unsigned long, |
| 58 const ResourceResponse&, | 60 const ResourceResponse&, |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 406 |
| 405 void TearDown() override { | 407 void TearDown() override { |
| 406 m_helper->onTearDown(); | 408 m_helper->onTearDown(); |
| 407 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 409 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
| 408 memoryCache()->evictResources(); | 410 memoryCache()->evictResources(); |
| 409 m_client.reset(); | 411 m_client.reset(); |
| 410 } | 412 } |
| 411 | 413 |
| 412 void setUpSuccessURL() { | 414 void setUpSuccessURL() { |
| 413 URLTestHelpers::registerMockedURLLoad( | 415 URLTestHelpers::registerMockedURLLoad( |
| 414 successURL(), "fox-null-terminated.html", "text/html"); | 416 successURL(), testing::webTestDataPath(kFileName), "text/html"); |
| 415 } | 417 } |
| 416 | 418 |
| 417 void setUpErrorURL() { | 419 void setUpErrorURL() { |
| 418 URLTestHelpers::registerMockedErrorURLLoad(errorURL()); | 420 URLTestHelpers::registerMockedErrorURLLoad(errorURL()); |
| 419 } | 421 } |
| 420 | 422 |
| 421 void setUpRedirectURL() { | 423 void setUpRedirectURL() { |
| 422 KURL url = redirectURL(); | 424 KURL url = redirectURL(); |
| 423 | 425 |
| 424 WebURLLoadTiming timing; | 426 WebURLLoadTiming timing; |
| 425 timing.initialize(); | 427 timing.initialize(); |
| 426 | 428 |
| 427 WebURLResponse response; | 429 WebURLResponse response; |
| 428 response.setURL(url); | 430 response.setURL(url); |
| 429 response.setHTTPStatusCode(301); | 431 response.setHTTPStatusCode(301); |
| 430 response.setLoadTiming(timing); | 432 response.setLoadTiming(timing); |
| 431 response.addHTTPHeaderField("Location", successURL().getString()); | 433 response.addHTTPHeaderField("Location", successURL().getString()); |
| 432 response.addHTTPHeaderField("Access-Control-Allow-Origin", "null"); | 434 response.addHTTPHeaderField("Access-Control-Allow-Origin", "null"); |
| 433 | 435 |
| 434 URLTestHelpers::registerMockedURLLoadWithCustomResponse( | 436 URLTestHelpers::registerMockedURLLoadWithCustomResponse( |
| 435 url, "fox-null-terminated.html", "", response); | 437 url, testing::webTestDataPath(kFileName), response); |
| 436 } | 438 } |
| 437 | 439 |
| 438 void setUpRedirectLoopURL() { | 440 void setUpRedirectLoopURL() { |
| 439 KURL url = redirectLoopURL(); | 441 KURL url = redirectLoopURL(); |
| 440 | 442 |
| 441 WebURLLoadTiming timing; | 443 WebURLLoadTiming timing; |
| 442 timing.initialize(); | 444 timing.initialize(); |
| 443 | 445 |
| 444 WebURLResponse response; | 446 WebURLResponse response; |
| 445 response.setURL(url); | 447 response.setURL(url); |
| 446 response.setHTTPStatusCode(301); | 448 response.setHTTPStatusCode(301); |
| 447 response.setLoadTiming(timing); | 449 response.setLoadTiming(timing); |
| 448 response.addHTTPHeaderField("Location", redirectLoopURL().getString()); | 450 response.addHTTPHeaderField("Location", redirectLoopURL().getString()); |
| 449 response.addHTTPHeaderField("Access-Control-Allow-Origin", "null"); | 451 response.addHTTPHeaderField("Access-Control-Allow-Origin", "null"); |
| 450 | 452 |
| 451 URLTestHelpers::registerMockedURLLoadWithCustomResponse( | 453 URLTestHelpers::registerMockedURLLoadWithCustomResponse( |
| 452 url, "fox-null-terminated.html", "", response); | 454 url, testing::webTestDataPath(kFileName), response); |
| 453 } | 455 } |
| 454 | 456 |
| 455 std::unique_ptr<MockThreadableLoaderClient> m_client; | 457 std::unique_ptr<MockThreadableLoaderClient> m_client; |
| 456 std::unique_ptr<ThreadableLoaderTestHelper> m_helper; | 458 std::unique_ptr<ThreadableLoaderTestHelper> m_helper; |
| 457 }; | 459 }; |
| 458 | 460 |
| 459 INSTANTIATE_TEST_CASE_P(Document, | 461 INSTANTIATE_TEST_CASE_P(Document, |
| 460 ThreadableLoaderTest, | 462 ThreadableLoaderTest, |
| 461 ::testing::Values(DocumentThreadableLoaderTest)); | 463 ::testing::Values(DocumentThreadableLoaderTest)); |
| 462 | 464 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 // test is not saying that didFailAccessControlCheck should be dispatched | 882 // test is not saying that didFailAccessControlCheck should be dispatched |
| 881 // synchronously, but is saying that even when a response is served | 883 // synchronously, but is saying that even when a response is served |
| 882 // synchronously it should not lead to a crash. | 884 // synchronously it should not lead to a crash. |
| 883 startLoader(KURL(KURL(), "about:blank")); | 885 startLoader(KURL(KURL(), "about:blank")); |
| 884 callCheckpoint(2); | 886 callCheckpoint(2); |
| 885 } | 887 } |
| 886 | 888 |
| 887 } // namespace | 889 } // namespace |
| 888 | 890 |
| 889 } // namespace blink | 891 } // namespace blink |
| OLD | NEW |