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

Unified Diff: net/url_request/url_request_quic_unittest.cc

Issue 2718633002: debug on ios simulator
Patch Set: add to BUILD.gn test_support_bundle_data Created 3 years, 10 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 | « net/tools/quic/test_tools/mock_quic_session_visitor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f435d61cdf19d8a52a3461fe1de2828859dc3901..6546823d0bff072dfdeb41d29006f8e93f4ff7b4 100644
--- a/net/url_request/url_request_quic_unittest.cc
+++ b/net/url_request/url_request_quic_unittest.cc
@@ -5,6 +5,7 @@
#include <memory>
#include "base/files/file_path.h"
+#include "base/files/file_enumerator.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
@@ -19,6 +20,8 @@
#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/platform/api/quic_str_cat.h"
+#include "net/quic/platform/api/quic_text_utils.h"
#include "net/quic/test_tools/crypto_test_utils.h"
#include "net/test/cert_test_util.h"
#include "net/test/gtest_util.h"
@@ -45,6 +48,14 @@ const char kTestServerHost[] = "test.example.com";
const char kHelloPath[] = "/hello.txt";
const char kHelloBodyValue[] = "Hello from QUIC Server";
const int kHelloStatus = 200;
+// First push resource.
+// const char kPush1Path[] = "/push1.txt";
+// const char kPush1BodyValue[] = "First Pushed Resource from QUIC Server";
+// const int kPush1Status = 200;
+// Second push resource.
+// const char kPush2Path[] = "/push2.txt";
+// const char kPush2BodyValue[] = "Second Pushed Resource from QUIC Server";
+// const int kPush2Status = 200;
class URLRequestQuicTest : public ::testing::Test {
protected:
@@ -100,10 +111,15 @@ class URLRequestQuicTest : public ::testing::Test {
net::TestNetLogEntry::List entries;
net_log_.GetEntries(&entries);
+ EXPECT_EQ(0u, entries.size());
+
for (const auto& entry : entries) {
- if (entry.type == type)
+ if (entry.type == type) {
+ LOG(ERROR) << entry.GetParamsJson();
entry_list->push_back(entry);
+ }
}
+ LOG(ERROR) << "size: " << entry_list->size();
}
unsigned int GetRstErrorCountReceivedByServer(
@@ -112,12 +128,57 @@ class URLRequestQuicTest : public ::testing::Test {
->GetRstErrorCount(error_code);
}
+ int GetPushPromiseSent() const {
+ return (static_cast<QuicSimpleDispatcher*>(server_->dispatcher()))
+ ->push_promise_sent_;
+ }
+
private:
void StartQuicServer() {
// Set up in-memory cache.
+ std::string response_body("hello response");
+ int NumResources = 5;
+ std::list<QuicHttpResponseCache::ServerPushInfo> push_resources;
+ for (int i = 0; i < NumResources; ++i) {
+ std::string path = "/server_push_src" + QuicTextUtils::Uint64ToString(i);
+ std::string url = "https://test.example.com" + path;
+ QuicUrl resource_url(url);
+ LOG(ERROR) << "url: " << url;
+ std::string body = QuicStrCat("This is server push response body for ", path);
+ SpdyHeaderBlock response_headers;
+ response_headers[":version"] = "HTTP/1.1";
+ response_headers[":status"] = "200";
+ response_headers["content-length"] =
+ QuicTextUtils::Uint64ToString(body.size());
+ push_resources.push_back(
+ QuicHttpResponseCache::ServerPushInfo(resource_url, response_headers.Clone(), i, body));
+ }
+
response_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, kHelloStatus,
kHelloBodyValue);
- response_cache_.InitializeFromDirectory(ServerPushCacheDirectory());
+
+ LOG(ERROR) << "==== zhongyi: adding " << push_resources.size() << " pushes";
+ response_cache_.AddSimpleResponseWithServerPushResources(
+ kTestServerHost, "/index3.html", 200, response_body, push_resources);
+ EXPECT_EQ(100u, response_cache_.GetServerPushResources("test.example.com/index3.html").size());
+
+ // response_cache_.InitializeFromDirectory(GetServerPushResourceDirectory());
+ LOG(ERROR) << "=========== compare the directory path ===================";
+ LOG(ERROR) << "test server " << GetServerPushResourceDirectory().AsUTF8Unsafe();
+ LOG(ERROR) << "ServerPushCacheDirectory: " << ServerPushCacheDirectory();
+ LOG(ERROR) << "cert file dir: " << GetTestCertsDirectory().AsUTF8Unsafe();
+
+ base::FileEnumerator iter(GetServerPushResourceDirectory(), true, base::FileEnumerator::FILES);
+ int count = 0;
+ for (base::FilePath file = iter.Next(); !file.value().empty(); file = iter.Next()) {
+ count ++;
+ }
+ LOG(ERROR) << "@@@@ In TEST: of the file size: " << count;
+
+ // response_cache_.InitializeFromDirectory(ServerPushCacheDirectory());
+ response_cache_.InitializeFromDirectory(ServerPushCacheDirectory(), GetServerPushResourceDirectory());
+
+ EXPECT_EQ(100u, response_cache_.GetServerPushResources("test.example.com/index2.html").size());
net::QuicConfig config;
// Set up server certs.
std::unique_ptr<net::ProofSourceChromium> proof_source(
@@ -150,6 +211,7 @@ class URLRequestQuicTest : public ::testing::Test {
PathService::Get(base::DIR_SOURCE_ROOT, &path);
path = path.AppendASCII("net").AppendASCII("data").AppendASCII(
"quic_http_response_cache_data_with_push");
+ LOG(ERROR) << "path.MaybeAsASCII: " << path.MaybeAsASCII();
// The file path is known to be an ascii string.
return path.MaybeAsASCII();
}
@@ -280,6 +342,33 @@ TEST_F(URLRequestQuicTest, CancelPushIfCached) {
request->Start();
ASSERT_TRUE(request->is_pending());
base::RunLoop().Run();
+ run_loop.Run();
+
+ EXPECT_TRUE(request->status().is_success());
+
+ // Verify the reset error count received on the server side.
+ EXPECT_EQ(1u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
+}
+
+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());
+
+ run_loop.Run();
// Extract net logs on client side to verify push lookup transactions.
net::TestNetLogEntry::List entries;
@@ -287,29 +376,10 @@ TEST_F(URLRequestQuicTest, CancelPushIfCached) {
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());
// Verify the reset error count received on the server side.
- EXPECT_EQ(1u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
+ EXPECT_EQ(0u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
}
TEST_F(URLRequestQuicTest, CancelPushIfCached2) {
@@ -364,112 +434,192 @@ TEST_F(URLRequestQuicTest, CancelPushIfCached2) {
ASSERT_TRUE(request->is_pending());
base::RunLoop().Run();
+ run_loop.Run();
// Extract net logs on client side 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());
// Verify the reset error count received on the server side.
EXPECT_EQ(2u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
}
-TEST_F(URLRequestQuicTest, DoNotCancelPushIfNotFoundInCache) {
+// Tests that if two requests use the same QUIC session, the second request
+// should not have |LoadTimingInfo::connect_timing|.
+TEST_F(URLRequestQuicTest, TestTwoRequests) {
base::RunLoop run_loop;
WaitForCompletionNetworkDelegate network_delegate(
- run_loop.QuitClosure(), /*num_expected_requests=*/1);
+ run_loop.QuitClosure(), /*num_expected_requests=*/2);
SetNetworkDelegate(&network_delegate);
+ Init();
+ CheckLoadTimingDelegate delegate(false);
+ delegate.set_quit_on_complete(false);
+ std::string url =
+ base::StringPrintf("https://%s%s", kTestServerHost, kHelloPath);
+ std::unique_ptr<URLRequest> request =
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
+ CheckLoadTimingDelegate delegate2(true);
+ delegate2.set_quit_on_complete(false);
+ std::unique_ptr<URLRequest> request2 =
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate2);
+ request->Start();
+ request2->Start();
+ ASSERT_TRUE(request->is_pending());
+ ASSERT_TRUE(request2->is_pending());
+ run_loop.Run();
+
+ EXPECT_TRUE(request->status().is_success());
+ EXPECT_TRUE(request2->status().is_success());
+ EXPECT_EQ(kHelloBodyValue, delegate.data_received());
+ EXPECT_EQ(kHelloBodyValue, delegate2.data_received());
+}
+
+// Tests that if two requests use the same QUIC session, the second request
+// should not have |LoadTimingInfo::connect_timing|.
+TEST_F(URLRequestQuicTest, TestTwoRequestsSecondPush) {
+ base::RunLoop run_loop;
+ WaitForCompletionNetworkDelegate network_delegate(
+ run_loop.QuitClosure(), /*num_expected_requests=*/2);
+ 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);
+ delegate.set_quit_on_complete(false);
std::string url =
base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
+ std::string url2 =
+ base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico");
+
std::unique_ptr<URLRequest> request =
CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
+ CheckLoadTimingDelegate delegate2(true);
+ delegate2.set_quit_on_complete(false);
+ std::unique_ptr<URLRequest> request2 =
+ CreateRequest(GURL(url2), DEFAULT_PRIORITY, &delegate2);
request->Start();
ASSERT_TRUE(request->is_pending());
- base::RunLoop().Run();
+ request2->Start();
+ run_loop.Run();
+ EXPECT_TRUE(request->status().is_success());
+ EXPECT_TRUE(request2->status().is_success());
+ EXPECT_EQ(kHelloBodyValue, delegate.data_received());
+ EXPECT_EQ(kHelloBodyValue, delegate2.data_received());
- // Extract net logs on client side to verify push lookup transactions.
net::TestNetLogEntry::List entries;
- ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
-
+ // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
+ // EXPECT_EQ(4u, entries.size());
+ ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
EXPECT_EQ(4u, entries.size());
+ EXPECT_EQ(100, GetPushPromiseSent());
+}
- 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");
+TEST_F(URLRequestQuicTest, TestRequestsSentPush) {
+ base::RunLoop run_loop;
+ WaitForCompletionNetworkDelegate network_delegate(
+ run_loop.QuitClosure(), /*num_expected_requests=*/1);
+ SetNetworkDelegate(&network_delegate);
+ Init();
+ CheckLoadTimingDelegate delegate(false);
+ delegate.set_quit_on_complete(false);
+ std::string url =
+ base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
- 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);
+ std::unique_ptr<URLRequest> request =
+ CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
- 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);
+ request->Start();
+ ASSERT_TRUE(request->is_pending());
+ run_loop.Run();
EXPECT_TRUE(request->status().is_success());
+ EXPECT_EQ(kHelloBodyValue, delegate.data_received());
- // Verify the reset error count received on the server side.
- EXPECT_EQ(0u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
+ net::TestNetLogEntry::List entries;
+ // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
+ // EXPECT_EQ(4u, entries.size());
+ ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
+ EXPECT_EQ(4u, entries.size());
+ EXPECT_EQ(100, GetPushPromiseSent());
}
-// Tests that if two requests use the same QUIC session, the second request
-// should not have |LoadTimingInfo::connect_timing|.
-TEST_F(URLRequestQuicTest, TestTwoRequests) {
+TEST_F(URLRequestQuicTest, TestGetRequest2) {
+ Init();
+ 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();
+
+ EXPECT_TRUE(request->status().is_success());
+ EXPECT_EQ(kHelloBodyValue, delegate.data_received());
+
+ net::TestNetLogEntry::List entries;
+ // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
+ // EXPECT_EQ(4u, entries.size());
+ ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
+ EXPECT_EQ(4u, entries.size());
+ EXPECT_EQ(100, GetPushPromiseSent());
+}
+
+TEST_F(URLRequestQuicTest, TestRequestsSentPush3ManualAdd) {
base::RunLoop run_loop;
WaitForCompletionNetworkDelegate network_delegate(
- run_loop.QuitClosure(), /*num_expected_requests=*/2);
+ run_loop.QuitClosure(), /*num_expected_requests=*/1);
SetNetworkDelegate(&network_delegate);
Init();
CheckLoadTimingDelegate delegate(false);
delegate.set_quit_on_complete(false);
std::string url =
- base::StringPrintf("https://%s%s", kTestServerHost, kHelloPath);
+ base::StringPrintf("https://%s%s", kTestServerHost, "/index3.html");
+
std::unique_ptr<URLRequest> request =
CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
- CheckLoadTimingDelegate delegate2(true);
- delegate2.set_quit_on_complete(false);
- std::unique_ptr<URLRequest> request2 =
- CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate2);
request->Start();
- request2->Start();
ASSERT_TRUE(request->is_pending());
- ASSERT_TRUE(request2->is_pending());
run_loop.Run();
EXPECT_TRUE(request->status().is_success());
- EXPECT_TRUE(request2->status().is_success());
EXPECT_EQ(kHelloBodyValue, delegate.data_received());
- EXPECT_EQ(kHelloBodyValue, delegate2.data_received());
+
+ net::TestNetLogEntry::List entries;
+ // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
+ // EXPECT_EQ(4u, entries.size());
+ ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
+ EXPECT_EQ(100u, entries.size());
+ EXPECT_EQ(100, GetPushPromiseSent());
}
+TEST_F(URLRequestQuicTest, TestGetRequest3ManualAddPush) {
+ Init();
+ CheckLoadTimingDelegate delegate(false);
+ std::string url =
+ base::StringPrintf("https://%s%s", kTestServerHost, "/index3.html");
+ 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_EQ(kHelloBodyValue, delegate.data_received());
+
+ net::TestNetLogEntry::List entries;
+ // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
+ // EXPECT_EQ(4u, entries.size());
+ ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
+ EXPECT_EQ(100u, entries.size());
+ EXPECT_EQ(100, GetPushPromiseSent());
+}
+
+
} // namespace net
« no previous file with comments | « net/tools/quic/test_tools/mock_quic_session_visitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698