| 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/PingLoader.h" | 5 #include "core/loader/PingLoader.h" |
| 6 | 6 |
| 7 #include "core/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
| 8 #include "core/loader/EmptyClients.h" | 8 #include "core/loader/EmptyClients.h" |
| 9 #include "core/loader/FrameLoader.h" | 9 #include "core/loader/FrameLoader.h" |
| 10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| 11 #include "platform/loader/fetch/SubstituteData.h" | 11 #include "platform/loader/fetch/SubstituteData.h" |
| 12 #include "platform/testing/URLTestHelpers.h" | 12 #include "platform/testing/URLTestHelpers.h" |
| 13 #include "platform/testing/UnitTestHelpers.h" | 13 #include "platform/testing/UnitTestHelpers.h" |
| 14 #include "platform/weborigin/KURL.h" | 14 #include "platform/weborigin/KURL.h" |
| 15 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 16 #include "public/platform/WebURLLoaderMockFactory.h" | 16 #include "public/platform/WebURLLoaderMockFactory.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class PingFrameLoaderClient : public EmptyLocalFrameClient { | 23 class PingLocalFrameClient : public EmptyLocalFrameClient { |
| 24 public: | 24 public: |
| 25 void dispatchWillSendRequest(ResourceRequest& request) override { | 25 void dispatchWillSendRequest(ResourceRequest& request) override { |
| 26 if (request.httpContentType() == "text/ping") | 26 if (request.httpContentType() == "text/ping") |
| 27 m_pingRequest = request; | 27 m_pingRequest = request; |
| 28 } | 28 } |
| 29 | 29 |
| 30 const ResourceRequest& pingRequest() const { return m_pingRequest; } | 30 const ResourceRequest& pingRequest() const { return m_pingRequest; } |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 ResourceRequest m_pingRequest; | 33 ResourceRequest m_pingRequest; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class PingLoaderTest : public ::testing::Test { | 36 class PingLoaderTest : public ::testing::Test { |
| 37 public: | 37 public: |
| 38 void SetUp() override { | 38 void SetUp() override { |
| 39 m_client = new PingFrameLoaderClient; | 39 m_client = new PingLocalFrameClient; |
| 40 m_pageHolder = DummyPageHolder::create(IntSize(1, 1), nullptr, m_client); | 40 m_pageHolder = DummyPageHolder::create(IntSize(1, 1), nullptr, m_client); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void TearDown() override { | 43 void TearDown() override { |
| 44 Platform::current() | 44 Platform::current() |
| 45 ->getURLLoaderMockFactory() | 45 ->getURLLoaderMockFactory() |
| 46 ->unregisterAllURLsAndClearMemoryCache(); | 46 ->unregisterAllURLsAndClearMemoryCache(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void setDocumentURL(const KURL& url) { | 49 void setDocumentURL(const KURL& url) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 EXPECT_EQ(destinationURL.getString(), | 66 EXPECT_EQ(destinationURL.getString(), |
| 67 pingRequest.httpHeaderField("Ping-To")); | 67 pingRequest.httpHeaderField("Ping-To")); |
| 68 } | 68 } |
| 69 // Serve the ping request, since it will otherwise bleed in to the next | 69 // Serve the ping request, since it will otherwise bleed in to the next |
| 70 // test, and once begun there is no way to cancel it directly. | 70 // test, and once begun there is no way to cancel it directly. |
| 71 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); | 71 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 72 return pingRequest; | 72 return pingRequest; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 Persistent<PingFrameLoaderClient> m_client; | 76 Persistent<PingLocalFrameClient> m_client; |
| 77 std::unique_ptr<DummyPageHolder> m_pageHolder; | 77 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 TEST_F(PingLoaderTest, HTTPSToHTTPS) { | 80 TEST_F(PingLoaderTest, HTTPSToHTTPS) { |
| 81 KURL pingURL(ParsedURLString, "https://localhost/bar.html"); | 81 KURL pingURL(ParsedURLString, "https://localhost/bar.html"); |
| 82 setDocumentURL(KURL(ParsedURLString, "https://127.0.0.1:8000/foo.html")); | 82 setDocumentURL(KURL(ParsedURLString, "https://127.0.0.1:8000/foo.html")); |
| 83 const ResourceRequest& pingRequest = pingAndGetRequest(pingURL); | 83 const ResourceRequest& pingRequest = pingAndGetRequest(pingURL); |
| 84 ASSERT_FALSE(pingRequest.isNull()); | 84 ASSERT_FALSE(pingRequest.isNull()); |
| 85 EXPECT_EQ(pingURL, pingRequest.url()); | 85 EXPECT_EQ(pingURL, pingRequest.url()); |
| 86 EXPECT_EQ(String(), pingRequest.httpHeaderField("Ping-From")); | 86 EXPECT_EQ(String(), pingRequest.httpHeaderField("Ping-From")); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 99 TEST_F(PingLoaderTest, NonHTTPPingTarget) { | 99 TEST_F(PingLoaderTest, NonHTTPPingTarget) { |
| 100 setDocumentURL(KURL(ParsedURLString, "http://127.0.0.1:8000/foo.html")); | 100 setDocumentURL(KURL(ParsedURLString, "http://127.0.0.1:8000/foo.html")); |
| 101 const ResourceRequest& pingRequest = | 101 const ResourceRequest& pingRequest = |
| 102 pingAndGetRequest(KURL(ParsedURLString, "ftp://localhost/bar.html")); | 102 pingAndGetRequest(KURL(ParsedURLString, "ftp://localhost/bar.html")); |
| 103 ASSERT_TRUE(pingRequest.isNull()); | 103 ASSERT_TRUE(pingRequest.isNull()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace | 106 } // namespace |
| 107 | 107 |
| 108 } // namespace blink | 108 } // namespace blink |
| OLD | NEW |