Index: net/url_request/url_request_quic_unittest.cc |
diff --git a/net/url_request/url_request_quic_unittest.cc b/net/url_request/url_request_quic_unittest.cc |
index 7532196988f52ad3238b3bdcf438f345d128083f..8a877d1fe4fb5048f08c907d078c7cf49c274189 100644 |
--- a/net/url_request/url_request_quic_unittest.cc |
+++ b/net/url_request/url_request_quic_unittest.cc |
@@ -15,6 +15,9 @@ |
#include "net/cert/mock_cert_verifier.h" |
#include "net/dns/mapped_host_resolver.h" |
#include "net/dns/mock_host_resolver.h" |
+#include "net/log/net_log_event_type.h" |
+#include "net/log/test_net_log.h" |
+#include "net/log/test_net_log_entry.h" |
#include "net/quic/chromium/crypto/proof_source_chromium.h" |
#include "net/quic/test_tools/crypto_test_utils.h" |
#include "net/test/cert_test_util.h" |
@@ -64,9 +67,11 @@ class URLRequestQuicTest : public ::testing::Test { |
params->origins_to_force_quic_on.insert(HostPortPair(kTestServerHost, 443)); |
params->cert_verifier = &cert_verifier_; |
params->enable_quic = true; |
+ params->enable_server_push_cancellation = true; |
context_->set_host_resolver(host_resolver_.get()); |
context_->set_http_network_session_params(std::move(params)); |
context_->set_cert_verifier(&cert_verifier_); |
+ context_->set_net_log(&net_log_); |
} |
void TearDown() override { |
@@ -88,11 +93,23 @@ class URLRequestQuicTest : public ::testing::Test { |
return context_->CreateRequest(url, priority, delegate); |
} |
+ void ExtractNetLog(NetLogEventType type, |
+ TestNetLogEntry::List* entry_list) const { |
+ net::TestNetLogEntry::List entries; |
+ net_log_.GetEntries(&entries); |
+ |
+ for (const auto& entry : entries) { |
+ if (entry.type == type) |
+ entry_list->push_back(entry); |
+ } |
+ } |
+ |
private: |
void StartQuicServer() { |
// Set up in-memory cache. |
response_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, kHelloStatus, |
kHelloBodyValue); |
+ response_cache_.InitializeFromDirectory(ServerPushCacheDirectory()); |
net::QuicConfig config; |
// Set up server certs. |
std::unique_ptr<net::ProofSourceChromium> proof_source( |
@@ -120,9 +137,19 @@ class URLRequestQuicTest : public ::testing::Test { |
EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); |
} |
+ std::string ServerPushCacheDirectory() { |
+ base::FilePath path; |
+ PathService::Get(base::DIR_SOURCE_ROOT, &path); |
+ path = path.AppendASCII("net").AppendASCII("data").AppendASCII( |
+ "quic_http_response_cache_data_with_push"); |
+ // The file path is known to be an ascii string. |
+ return path.MaybeAsASCII(); |
+ } |
+ |
std::unique_ptr<MappedHostResolver> host_resolver_; |
std::unique_ptr<QuicSimpleServer> server_; |
std::unique_ptr<TestURLRequestContext> context_; |
+ TestNetLog net_log_; |
QuicHttpResponseCache response_cache_; |
MockCertVerifier cert_verifier_; |
}; |
@@ -211,6 +238,192 @@ TEST_F(URLRequestQuicTest, TestGetRequest) { |
EXPECT_EQ(kHelloBodyValue, delegate.data_received()); |
} |
+TEST_F(URLRequestQuicTest, CancelPushIfCached) { |
Zhongyi Shi
2017/02/16 07:39:50
Currently the server push cancellation status is v
Ryan Hamilton
2017/02/16 15:18:08
One idea might be for the QUIC server to expose th
|
+ base::RunLoop run_loop; |
+ WaitForCompletionNetworkDelegate network_delegate( |
+ run_loop.QuitClosure(), /*num_expected_requests=*/2); |
+ SetNetworkDelegate(&network_delegate); |
+ |
+ Init(); |
+ { |
+ // Send a request to the pushed url: /kitten-1.jpg to pull the resource into |
+ // cache. |
+ CheckLoadTimingDelegate delegate(false); |
+ std::string url = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg"); |
+ std::unique_ptr<URLRequest> request = |
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); |
+ |
+ request->Start(); |
+ ASSERT_TRUE(request->is_pending()); |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_TRUE(request->status().is_success()); |
+ } |
+ |
+ // Send a request to /index2.html which pushes /kitten-1.jpg and /favicon.ico. |
+ // Should cancel push for /kitten-1.jpg. |
+ CheckLoadTimingDelegate delegate(true); |
+ std::string url = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html"); |
+ std::unique_ptr<URLRequest> request = |
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); |
+ |
+ request->Start(); |
+ ASSERT_TRUE(request->is_pending()); |
+ base::RunLoop().Run(); |
+ |
+ // Extract net logs to verify push lookup transactions. |
+ net::TestNetLogEntry::List entries; |
+ ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries); |
+ |
+ EXPECT_EQ(4u, entries.size()); |
+ |
+ std::string value; |
+ int net_error; |
+ std::string push_url_1 = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg"); |
+ std::string push_url_2 = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico"); |
+ |
+ EXPECT_TRUE(entries[0].GetStringValue("push_url", &value)); |
+ EXPECT_EQ(value, push_url_1); |
+ // No net error code for this lookup transaction, the push is found. |
+ EXPECT_FALSE(entries[1].GetIntegerValue("net_error", &net_error)); |
+ |
+ EXPECT_TRUE(entries[2].GetStringValue("push_url", &value)); |
+ EXPECT_EQ(value, push_url_2); |
+ // Net error code -400 is found for this lookup transaction, the push is not |
+ // found in the cache. |
+ EXPECT_TRUE(entries[3].GetIntegerValue("net_error", &net_error)); |
+ EXPECT_EQ(net_error, -400); |
+ |
+ EXPECT_TRUE(request->status().is_success()); |
+} |
+ |
+TEST_F(URLRequestQuicTest, CancelPushIfCached2) { |
+ base::RunLoop run_loop; |
+ WaitForCompletionNetworkDelegate network_delegate( |
+ run_loop.QuitClosure(), /*num_expected_requests=*/3); |
+ SetNetworkDelegate(&network_delegate); |
+ |
+ Init(); |
+ { |
+ // Send a request to the pushed url: /kitten-1.jpg to pull the resource into |
+ // cache. |
+ CheckLoadTimingDelegate delegate(false); |
+ std::string url = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg"); |
+ std::unique_ptr<URLRequest> request = |
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); |
+ |
+ request->Start(); |
+ ASSERT_TRUE(request->is_pending()); |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_TRUE(request->status().is_success()); |
+ EXPECT_NE(network_delegate.total_network_bytes_sent(), 0u); |
+ } |
+ |
+ { |
+ // Send a request to the pushed url: /favicon.ico to pull the resource into |
+ // cache. |
+ CheckLoadTimingDelegate delegate(true); |
+ std::string url = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico"); |
+ std::unique_ptr<URLRequest> request = |
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); |
+ |
+ request->Start(); |
+ ASSERT_TRUE(request->is_pending()); |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_TRUE(request->status().is_success()); |
+ } |
+ |
+ // Send a request to /index2.html which pushes /kitten-1.jpg and /favicon.ico. |
+ // Should cancel push for /kitten-1.jpg. |
+ CheckLoadTimingDelegate delegate(true); |
+ std::string url = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html"); |
+ std::unique_ptr<URLRequest> request = |
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); |
+ |
+ request->Start(); |
+ ASSERT_TRUE(request->is_pending()); |
+ base::RunLoop().Run(); |
+ |
+ // Extract net logs to verify push lookup transactions. |
+ net::TestNetLogEntry::List entries; |
+ ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries); |
+ |
+ EXPECT_EQ(4u, entries.size()); |
+ |
+ std::string value; |
+ int net_error; |
+ std::string push_url_1 = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg"); |
+ std::string push_url_2 = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico"); |
+ |
+ EXPECT_TRUE(entries[0].GetStringValue("push_url", &value)); |
+ EXPECT_EQ(value, push_url_1); |
+ // No net error code for this lookup transaction, the push is found. |
+ EXPECT_FALSE(entries[1].GetIntegerValue("net_error", &net_error)); |
+ |
+ EXPECT_TRUE(entries[2].GetStringValue("push_url", &value)); |
+ EXPECT_EQ(value, push_url_2); |
+ // No net error code for this lookup transaction, the push is found. |
+ EXPECT_FALSE(entries[3].GetIntegerValue("net_error", &net_error)); |
+ |
+ EXPECT_TRUE(request->status().is_success()); |
+} |
+ |
+TEST_F(URLRequestQuicTest, DoNotCancelPushIfNotFoundInCache) { |
+ base::RunLoop run_loop; |
+ WaitForCompletionNetworkDelegate network_delegate( |
+ run_loop.QuitClosure(), /*num_expected_requests=*/1); |
+ SetNetworkDelegate(&network_delegate); |
+ |
+ Init(); |
+ // Send a request to /index2.hmtl which pushes /kitten-1.jpg and /favicon.ico |
+ // and shouldn't cancel any since neither is in cache. |
+ CheckLoadTimingDelegate delegate(false); |
+ std::string url = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html"); |
+ std::unique_ptr<URLRequest> request = |
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); |
+ |
+ request->Start(); |
+ ASSERT_TRUE(request->is_pending()); |
+ base::RunLoop().Run(); |
+ |
+ // Extract net logs to verify push lookup transactions. |
+ net::TestNetLogEntry::List entries; |
+ ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries); |
+ |
+ EXPECT_EQ(4u, entries.size()); |
+ |
+ std::string value; |
+ int net_error; |
+ std::string push_url_1 = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg"); |
+ std::string push_url_2 = |
+ base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico"); |
+ |
+ EXPECT_TRUE(entries[0].GetStringValue("push_url", &value)); |
+ EXPECT_EQ(value, push_url_1); |
+ EXPECT_TRUE(entries[1].GetIntegerValue("net_error", &net_error)); |
+ EXPECT_EQ(net_error, -400); |
+ |
+ EXPECT_TRUE(entries[2].GetStringValue("push_url", &value)); |
+ EXPECT_EQ(value, push_url_2); |
+ EXPECT_TRUE(entries[3].GetIntegerValue("net_error", &net_error)); |
+ EXPECT_EQ(net_error, -400); |
+ |
+ EXPECT_TRUE(request->status().is_success()); |
+} |
+ |
// Tests that if two requests use the same QUIC session, the second request |
// should not have |LoadTimingInfo::connect_timing|. |
TEST_F(URLRequestQuicTest, TestTwoRequests) { |