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

Side by Side Diff: third_party/WebKit/Source/core/loader/PingLoaderTest.cpp

Issue 2982523002: Set "ping" requests priority as lowest (Closed)
Patch Set: fix Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 PingLocalFrameClient : 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.GetKeepalive())
27 ping_request_ = request; 27 ping_request_ = request;
28 } 28 }
29 29
30 const ResourceRequest& PingRequest() const { return ping_request_; } 30 const ResourceRequest& PingRequest() const { return ping_request_; }
31 31
32 private: 32 private:
33 ResourceRequest ping_request_; 33 ResourceRequest ping_request_;
34 }; 34 };
35 35
36 class PingLoaderTest : public ::testing::Test { 36 class PingLoaderTest : public ::testing::Test {
(...skipping 27 matching lines...) Expand all
64 if (!ping_request.IsNull()) { 64 if (!ping_request.IsNull()) {
65 EXPECT_EQ(destination_url.GetString(), 65 EXPECT_EQ(destination_url.GetString(),
66 ping_request.HttpHeaderField("Ping-To")); 66 ping_request.HttpHeaderField("Ping-To"));
67 } 67 }
68 // Serve the ping request, since it will otherwise bleed in to the next 68 // Serve the ping request, since it will otherwise bleed in to the next
69 // test, and once begun there is no way to cancel it directly. 69 // test, and once begun there is no way to cancel it directly.
70 Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests(); 70 Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
71 return ping_request; 71 return ping_request;
72 } 72 }
73 73
74 private: 74 protected:
75 Persistent<PingLocalFrameClient> client_; 75 Persistent<PingLocalFrameClient> client_;
76 std::unique_ptr<DummyPageHolder> page_holder_; 76 std::unique_ptr<DummyPageHolder> page_holder_;
77 }; 77 };
78 78
79 TEST_F(PingLoaderTest, HTTPSToHTTPS) { 79 TEST_F(PingLoaderTest, HTTPSToHTTPS) {
80 KURL ping_url(kParsedURLString, "https://localhost/bar.html"); 80 KURL ping_url(kParsedURLString, "https://localhost/bar.html");
81 SetDocumentURL(KURL(kParsedURLString, "https://127.0.0.1:8000/foo.html")); 81 SetDocumentURL(KURL(kParsedURLString, "https://127.0.0.1:8000/foo.html"));
82 const ResourceRequest& ping_request = PingAndGetRequest(ping_url); 82 const ResourceRequest& ping_request = PingAndGetRequest(ping_url);
83 ASSERT_FALSE(ping_request.IsNull()); 83 ASSERT_FALSE(ping_request.IsNull());
84 EXPECT_EQ(ping_url, ping_request.Url()); 84 EXPECT_EQ(ping_url, ping_request.Url());
(...skipping 11 matching lines...) Expand all
96 ping_request.HttpHeaderField("Ping-From")); 96 ping_request.HttpHeaderField("Ping-From"));
97 } 97 }
98 98
99 TEST_F(PingLoaderTest, NonHTTPPingTarget) { 99 TEST_F(PingLoaderTest, NonHTTPPingTarget) {
100 SetDocumentURL(KURL(kParsedURLString, "http://127.0.0.1:8000/foo.html")); 100 SetDocumentURL(KURL(kParsedURLString, "http://127.0.0.1:8000/foo.html"));
101 const ResourceRequest& ping_request = 101 const ResourceRequest& ping_request =
102 PingAndGetRequest(KURL(kParsedURLString, "ftp://localhost/bar.html")); 102 PingAndGetRequest(KURL(kParsedURLString, "ftp://localhost/bar.html"));
103 ASSERT_TRUE(ping_request.IsNull()); 103 ASSERT_TRUE(ping_request.IsNull());
104 } 104 }
105 105
106 TEST_F(PingLoaderTest, LoadImagePriority) {
107 SetDocumentURL(KURL(kParsedURLString, "http://localhost/foo.html"));
108
109 KURL ping_url(kParsedURLString, "https://localhost/bar.html");
110 URLTestHelpers::RegisterMockedURLLoad(
111 ping_url, testing::CoreTestDataPath("bar.html"), "text/html");
112 PingLoader::LoadImage(&page_holder_->GetFrame(), ping_url);
113 Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
114 const ResourceRequest& request = client_->PingRequest();
115 ASSERT_FALSE(request.IsNull());
116 ASSERT_EQ(request.Url(), ping_url);
117 EXPECT_EQ(kResourceLoadPriorityVeryLow, request.Priority());
118 }
119
120 TEST_F(PingLoaderTest, LinkAuditPingPriority) {
121 KURL destination_url(kParsedURLString, "http://navigation.destination");
122 SetDocumentURL(KURL(kParsedURLString, "http://localhost/foo.html"));
123
124 KURL ping_url(kParsedURLString, "https://localhost/bar.html");
125 URLTestHelpers::RegisterMockedURLLoad(
126 ping_url, testing::CoreTestDataPath("bar.html"), "text/html");
127 PingLoader::SendLinkAuditPing(&page_holder_->GetFrame(), ping_url,
128 destination_url);
129 Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
130 const ResourceRequest& request = client_->PingRequest();
131 ASSERT_FALSE(request.IsNull());
132 ASSERT_EQ(request.Url(), ping_url);
133 EXPECT_EQ(kResourceLoadPriorityVeryLow, request.Priority());
134 }
135
136 TEST_F(PingLoaderTest, BeaconPriority) {
137 SetDocumentURL(KURL(kParsedURLString, "https://localhost/foo.html"));
138
139 KURL ping_url(kParsedURLString, "https://localhost/bar.html");
140 URLTestHelpers::RegisterMockedURLLoad(
141 ping_url, testing::CoreTestDataPath("bar.html"), "text/html");
142 size_t size = 0;
143 PingLoader::SendBeacon(&page_holder_->GetFrame(), 123, ping_url, "hello",
144 size);
145 Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
146 const ResourceRequest& request = client_->PingRequest();
147 ASSERT_FALSE(request.IsNull());
148 ASSERT_EQ(request.Url(), ping_url);
149 EXPECT_EQ(kResourceLoadPriorityVeryLow, request.Priority());
150 }
151
106 } // namespace 152 } // namespace
107 153
108 } // namespace blink 154 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698