Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1126)

Unified Diff: third_party/WebKit/Source/core/loader/PingLoaderTest.cpp

Issue 2360753002: Cross-origin https->https pings should omit Ping-From header (Closed)
Patch Set: More tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/loader/PingLoader.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/loader/PingLoaderTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/PingLoaderTest.cpp b/third_party/WebKit/Source/core/loader/PingLoaderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9348a28f3e9e5fe7a5dcd1147019a53f86b1243d
--- /dev/null
+++ b/third_party/WebKit/Source/core/loader/PingLoaderTest.cpp
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/loader/PingLoader.h"
+
+#include "core/fetch/SubstituteData.h"
+#include "core/frame/LocalFrame.h"
+#include "core/loader/EmptyClients.h"
+#include "core/loader/FrameLoader.h"
+#include "core/testing/DummyPageHolder.h"
+#include "platform/testing/URLTestHelpers.h"
+#include "platform/testing/UnitTestHelpers.h"
+#include "platform/weborigin/KURL.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebURLLoaderMockFactory.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+class PingFrameLoaderClient : public EmptyFrameLoaderClient {
+public:
+ void dispatchWillSendRequest(ResourceRequest& request) override
+ {
+ if (request.httpContentType() == "text/ping")
+ m_pingRequest = request;
+ }
+
+ const ResourceRequest& pingRequest() const { return m_pingRequest; }
+
+private:
+ ResourceRequest m_pingRequest;
+};
+
+class PingLoaderTest : public ::testing::Test {
+public:
+ void SetUp() override
+ {
+ m_client = new PingFrameLoaderClient;
+ m_pageHolder = DummyPageHolder::create(IntSize(1, 1), nullptr, m_client);
+ }
+
+ void TearDown() override
+ {
+ Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs();
+ }
+
+ void setDocumentURL(const KURL& url)
+ {
+ FrameLoadRequest request(nullptr, url, SubstituteData(SharedBuffer::create(), "text/html", "UTF-8", KURL()));
+ m_pageHolder->frame().loader().load(request);
+ blink::testing::runPendingTasks();
+ ASSERT_EQ(url.getString(), m_pageHolder->document().url().getString());
+ }
+
+ const ResourceRequest& pingAndGetRequest(const KURL& pingURL)
+ {
+ KURL destinationURL(ParsedURLString, "http://navigation.destination");
+ URLTestHelpers::registerMockedURLLoad(pingURL, "bar.html", "text/html");
+ PingLoader::sendLinkAuditPing(&m_pageHolder->frame(), pingURL, destinationURL);
+ const ResourceRequest& pingRequest = m_client->pingRequest();
+ if (!pingRequest.isNull())
+ EXPECT_EQ(destinationURL.getString(), pingRequest.httpHeaderField("Ping-To"));
+ return pingRequest;
+ }
+
+private:
+ Persistent<PingFrameLoaderClient> m_client;
+ std::unique_ptr<DummyPageHolder> m_pageHolder;
+};
+
+TEST_F(PingLoaderTest, HTTPSToHTTPS)
+{
+ KURL pingURL(ParsedURLString, "https://localhost/bar.html");
+ setDocumentURL(KURL(ParsedURLString, "https://127.0.0.1:8000/foo.html"));
+ const ResourceRequest& pingRequest = pingAndGetRequest(pingURL);
+ ASSERT_FALSE(pingRequest.isNull());
+ EXPECT_EQ(pingURL, pingRequest.url());
+ EXPECT_EQ(String(), pingRequest.httpHeaderField("Ping-From"));
+}
+
+TEST_F(PingLoaderTest, HTTPToHTTPS)
+{
+ KURL documentURL(ParsedURLString, "http://127.0.0.1:8000/foo.html");
+ KURL pingURL(ParsedURLString, "https://localhost/bar.html");
+ setDocumentURL(documentURL);
+ const ResourceRequest& pingRequest = pingAndGetRequest(pingURL);
+ ASSERT_FALSE(pingRequest.isNull());
+ EXPECT_EQ(pingURL, pingRequest.url());
+ EXPECT_EQ(documentURL.getString(), pingRequest.httpHeaderField("Ping-From"));
+}
+
+TEST_F(PingLoaderTest, NonHTTPPingTarget)
+{
+ setDocumentURL(KURL(ParsedURLString, "http://127.0.0.1:8000/foo.html"));
+ const ResourceRequest& pingRequest = pingAndGetRequest(KURL(ParsedURLString, "ftp://localhost/bar.html"));
+ ASSERT_TRUE(pingRequest.isNull());
+}
+
+} // namespace
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/loader/PingLoader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698