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

Side by Side 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, 9 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 | « net/tools/quic/test_tools/mock_quic_session_visitor.h ('k') | no next file » | 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 <memory> 5 #include <memory>
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_enumerator.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "net/base/load_timing_info.h" 14 #include "net/base/load_timing_info.h"
14 #include "net/base/network_delegate.h" 15 #include "net/base/network_delegate.h"
15 #include "net/cert/mock_cert_verifier.h" 16 #include "net/cert/mock_cert_verifier.h"
16 #include "net/dns/mapped_host_resolver.h" 17 #include "net/dns/mapped_host_resolver.h"
17 #include "net/dns/mock_host_resolver.h" 18 #include "net/dns/mock_host_resolver.h"
18 #include "net/log/net_log_event_type.h" 19 #include "net/log/net_log_event_type.h"
19 #include "net/log/test_net_log.h" 20 #include "net/log/test_net_log.h"
20 #include "net/log/test_net_log_entry.h" 21 #include "net/log/test_net_log_entry.h"
21 #include "net/quic/chromium/crypto/proof_source_chromium.h" 22 #include "net/quic/chromium/crypto/proof_source_chromium.h"
23 #include "net/quic/platform/api/quic_str_cat.h"
24 #include "net/quic/platform/api/quic_text_utils.h"
22 #include "net/quic/test_tools/crypto_test_utils.h" 25 #include "net/quic/test_tools/crypto_test_utils.h"
23 #include "net/test/cert_test_util.h" 26 #include "net/test/cert_test_util.h"
24 #include "net/test/gtest_util.h" 27 #include "net/test/gtest_util.h"
25 #include "net/test/test_data_directory.h" 28 #include "net/test/test_data_directory.h"
26 #include "net/tools/quic/quic_dispatcher.h" 29 #include "net/tools/quic/quic_dispatcher.h"
27 #include "net/tools/quic/quic_http_response_cache.h" 30 #include "net/tools/quic/quic_http_response_cache.h"
28 #include "net/tools/quic/quic_simple_dispatcher.h" 31 #include "net/tools/quic/quic_simple_dispatcher.h"
29 #include "net/tools/quic/quic_simple_server.h" 32 #include "net/tools/quic/quic_simple_server.h"
30 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_test_util.h" 34 #include "net/url_request/url_request_test_util.h"
32 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/gurl.h" 37 #include "url/gurl.h"
35 38
36 namespace net { 39 namespace net {
37 40
38 namespace { 41 namespace {
39 42
40 // This must match the certificate used (quic_test.example.com.crt and 43 // This must match the certificate used (quic_test.example.com.crt and
41 // quic_test.example.com.key.pkcs8). 44 // quic_test.example.com.key.pkcs8).
42 const int kTestServerPort = 6121; 45 const int kTestServerPort = 6121;
43 const char kTestServerHost[] = "test.example.com"; 46 const char kTestServerHost[] = "test.example.com";
44 // Used as a simple response from the server. 47 // Used as a simple response from the server.
45 const char kHelloPath[] = "/hello.txt"; 48 const char kHelloPath[] = "/hello.txt";
46 const char kHelloBodyValue[] = "Hello from QUIC Server"; 49 const char kHelloBodyValue[] = "Hello from QUIC Server";
47 const int kHelloStatus = 200; 50 const int kHelloStatus = 200;
51 // First push resource.
52 // const char kPush1Path[] = "/push1.txt";
53 // const char kPush1BodyValue[] = "First Pushed Resource from QUIC Server";
54 // const int kPush1Status = 200;
55 // Second push resource.
56 // const char kPush2Path[] = "/push2.txt";
57 // const char kPush2BodyValue[] = "Second Pushed Resource from QUIC Server";
58 // const int kPush2Status = 200;
48 59
49 class URLRequestQuicTest : public ::testing::Test { 60 class URLRequestQuicTest : public ::testing::Test {
50 protected: 61 protected:
51 URLRequestQuicTest() : context_(new TestURLRequestContext(true)) { 62 URLRequestQuicTest() : context_(new TestURLRequestContext(true)) {
52 StartQuicServer(); 63 StartQuicServer();
53 64
54 std::unique_ptr<HttpNetworkSession::Params> params( 65 std::unique_ptr<HttpNetworkSession::Params> params(
55 new HttpNetworkSession::Params); 66 new HttpNetworkSession::Params);
56 CertVerifyResult verify_result; 67 CertVerifyResult verify_result;
57 verify_result.verified_cert = ImportCertFromFile( 68 verify_result.verified_cert = ImportCertFromFile(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 RequestPriority priority, 104 RequestPriority priority,
94 URLRequest::Delegate* delegate) { 105 URLRequest::Delegate* delegate) {
95 return context_->CreateRequest(url, priority, delegate); 106 return context_->CreateRequest(url, priority, delegate);
96 } 107 }
97 108
98 void ExtractNetLog(NetLogEventType type, 109 void ExtractNetLog(NetLogEventType type,
99 TestNetLogEntry::List* entry_list) const { 110 TestNetLogEntry::List* entry_list) const {
100 net::TestNetLogEntry::List entries; 111 net::TestNetLogEntry::List entries;
101 net_log_.GetEntries(&entries); 112 net_log_.GetEntries(&entries);
102 113
114 EXPECT_EQ(0u, entries.size());
115
103 for (const auto& entry : entries) { 116 for (const auto& entry : entries) {
104 if (entry.type == type) 117 if (entry.type == type) {
118 LOG(ERROR) << entry.GetParamsJson();
105 entry_list->push_back(entry); 119 entry_list->push_back(entry);
120 }
106 } 121 }
122 LOG(ERROR) << "size: " << entry_list->size();
107 } 123 }
108 124
109 unsigned int GetRstErrorCountReceivedByServer( 125 unsigned int GetRstErrorCountReceivedByServer(
110 QuicRstStreamErrorCode error_code) const { 126 QuicRstStreamErrorCode error_code) const {
111 return (static_cast<QuicSimpleDispatcher*>(server_->dispatcher())) 127 return (static_cast<QuicSimpleDispatcher*>(server_->dispatcher()))
112 ->GetRstErrorCount(error_code); 128 ->GetRstErrorCount(error_code);
113 } 129 }
114 130
131 int GetPushPromiseSent() const {
132 return (static_cast<QuicSimpleDispatcher*>(server_->dispatcher()))
133 ->push_promise_sent_;
134 }
135
115 private: 136 private:
116 void StartQuicServer() { 137 void StartQuicServer() {
117 // Set up in-memory cache. 138 // Set up in-memory cache.
139 std::string response_body("hello response");
140 int NumResources = 5;
141 std::list<QuicHttpResponseCache::ServerPushInfo> push_resources;
142 for (int i = 0; i < NumResources; ++i) {
143 std::string path = "/server_push_src" + QuicTextUtils::Uint64ToString(i);
144 std::string url = "https://test.example.com" + path;
145 QuicUrl resource_url(url);
146 LOG(ERROR) << "url: " << url;
147 std::string body = QuicStrCat("This is server push response body for ", pa th);
148 SpdyHeaderBlock response_headers;
149 response_headers[":version"] = "HTTP/1.1";
150 response_headers[":status"] = "200";
151 response_headers["content-length"] =
152 QuicTextUtils::Uint64ToString(body.size());
153 push_resources.push_back(
154 QuicHttpResponseCache::ServerPushInfo(resource_url, response_headers.C lone(), i, body));
155 }
156
118 response_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, kHelloStatus, 157 response_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, kHelloStatus,
119 kHelloBodyValue); 158 kHelloBodyValue);
120 response_cache_.InitializeFromDirectory(ServerPushCacheDirectory()); 159
160 LOG(ERROR) << "==== zhongyi: adding " << push_resources.size() << " pushes";
161 response_cache_.AddSimpleResponseWithServerPushResources(
162 kTestServerHost, "/index3.html", 200, response_body, push_resources);
163 EXPECT_EQ(100u, response_cache_.GetServerPushResources("test.example.com/ind ex3.html").size());
164
165 // response_cache_.InitializeFromDirectory(GetServerPushResourceDirectory()) ;
166 LOG(ERROR) << "=========== compare the directory path ===================";
167 LOG(ERROR) << "test server " << GetServerPushResourceDirectory().AsUTF8Unsaf e();
168 LOG(ERROR) << "ServerPushCacheDirectory: " << ServerPushCacheDirectory();
169 LOG(ERROR) << "cert file dir: " << GetTestCertsDirectory().AsUTF8Unsafe();
170
171 base::FileEnumerator iter(GetServerPushResourceDirectory(), true, base::File Enumerator::FILES);
172 int count = 0;
173 for (base::FilePath file = iter.Next(); !file.value().empty(); file = iter.N ext()) {
174 count ++;
175 }
176 LOG(ERROR) << "@@@@ In TEST: of the file size: " << count;
177
178 // response_cache_.InitializeFromDirectory(ServerPushCacheDirectory());
179 response_cache_.InitializeFromDirectory(ServerPushCacheDirectory(), GetServe rPushResourceDirectory());
180
181 EXPECT_EQ(100u, response_cache_.GetServerPushResources("test.example.com/ind ex2.html").size());
121 net::QuicConfig config; 182 net::QuicConfig config;
122 // Set up server certs. 183 // Set up server certs.
123 std::unique_ptr<net::ProofSourceChromium> proof_source( 184 std::unique_ptr<net::ProofSourceChromium> proof_source(
124 new net::ProofSourceChromium()); 185 new net::ProofSourceChromium());
125 base::FilePath directory = GetTestCertsDirectory(); 186 base::FilePath directory = GetTestCertsDirectory();
126 CHECK(proof_source->Initialize( 187 CHECK(proof_source->Initialize(
127 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.crt")), 188 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.crt")),
128 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.pkcs8")), 189 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.pkcs8")),
129 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.sct")))); 190 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.sct"))));
130 server_.reset(new QuicSimpleServer( 191 server_.reset(new QuicSimpleServer(
(...skipping 12 matching lines...) Expand all
143 std::string map_rule = "MAP test.example.com test.example.com:" + 204 std::string map_rule = "MAP test.example.com test.example.com:" +
144 base::IntToString(server_->server_address().port()); 205 base::IntToString(server_->server_address().port());
145 EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); 206 EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule));
146 } 207 }
147 208
148 std::string ServerPushCacheDirectory() { 209 std::string ServerPushCacheDirectory() {
149 base::FilePath path; 210 base::FilePath path;
150 PathService::Get(base::DIR_SOURCE_ROOT, &path); 211 PathService::Get(base::DIR_SOURCE_ROOT, &path);
151 path = path.AppendASCII("net").AppendASCII("data").AppendASCII( 212 path = path.AppendASCII("net").AppendASCII("data").AppendASCII(
152 "quic_http_response_cache_data_with_push"); 213 "quic_http_response_cache_data_with_push");
214 LOG(ERROR) << "path.MaybeAsASCII: " << path.MaybeAsASCII();
153 // The file path is known to be an ascii string. 215 // The file path is known to be an ascii string.
154 return path.MaybeAsASCII(); 216 return path.MaybeAsASCII();
155 } 217 }
156 218
157 std::unique_ptr<MappedHostResolver> host_resolver_; 219 std::unique_ptr<MappedHostResolver> host_resolver_;
158 std::unique_ptr<QuicSimpleServer> server_; 220 std::unique_ptr<QuicSimpleServer> server_;
159 std::unique_ptr<TestURLRequestContext> context_; 221 std::unique_ptr<TestURLRequestContext> context_;
160 TestNetLog net_log_; 222 TestNetLog net_log_;
161 QuicHttpResponseCache response_cache_; 223 QuicHttpResponseCache response_cache_;
162 MockCertVerifier cert_verifier_; 224 MockCertVerifier cert_verifier_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // Should cancel push for /kitten-1.jpg. 335 // Should cancel push for /kitten-1.jpg.
274 CheckLoadTimingDelegate delegate(true); 336 CheckLoadTimingDelegate delegate(true);
275 std::string url = 337 std::string url =
276 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html"); 338 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
277 std::unique_ptr<URLRequest> request = 339 std::unique_ptr<URLRequest> request =
278 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); 340 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
279 341
280 request->Start(); 342 request->Start();
281 ASSERT_TRUE(request->is_pending()); 343 ASSERT_TRUE(request->is_pending());
282 base::RunLoop().Run(); 344 base::RunLoop().Run();
345 run_loop.Run();
346
347 EXPECT_TRUE(request->status().is_success());
348
349 // Verify the reset error count received on the server side.
350 EXPECT_EQ(1u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
351 }
352
353 TEST_F(URLRequestQuicTest, DoNotCancelPushIfNotFoundInCache) {
354 base::RunLoop run_loop;
355 WaitForCompletionNetworkDelegate network_delegate(
356 run_loop.QuitClosure(), /*num_expected_requests=*/1);
357 SetNetworkDelegate(&network_delegate);
358
359 Init();
360 // Send a request to /index2.hmtl which pushes /kitten-1.jpg and /favicon.ico
361 // and shouldn't cancel any since neither is in cache.
362 CheckLoadTimingDelegate delegate(false);
363 std::string url =
364 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
365 std::unique_ptr<URLRequest> request =
366 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
367
368 request->Start();
369 ASSERT_TRUE(request->is_pending());
370
371 run_loop.Run();
283 372
284 // Extract net logs on client side to verify push lookup transactions. 373 // Extract net logs on client side to verify push lookup transactions.
285 net::TestNetLogEntry::List entries; 374 net::TestNetLogEntry::List entries;
286 ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries); 375 ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
287 376
288 EXPECT_EQ(4u, entries.size()); 377 EXPECT_EQ(4u, entries.size());
289 378
290 std::string value;
291 int net_error;
292 std::string push_url_1 =
293 base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg");
294 std::string push_url_2 =
295 base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico");
296
297 EXPECT_TRUE(entries[0].GetStringValue("push_url", &value));
298 EXPECT_EQ(value, push_url_1);
299 // No net error code for this lookup transaction, the push is found.
300 EXPECT_FALSE(entries[1].GetIntegerValue("net_error", &net_error));
301
302 EXPECT_TRUE(entries[2].GetStringValue("push_url", &value));
303 EXPECT_EQ(value, push_url_2);
304 // Net error code -400 is found for this lookup transaction, the push is not
305 // found in the cache.
306 EXPECT_TRUE(entries[3].GetIntegerValue("net_error", &net_error));
307 EXPECT_EQ(net_error, -400);
308
309 EXPECT_TRUE(request->status().is_success()); 379 EXPECT_TRUE(request->status().is_success());
310 380
311 // Verify the reset error count received on the server side. 381 // Verify the reset error count received on the server side.
312 EXPECT_EQ(1u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED)); 382 EXPECT_EQ(0u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
313 } 383 }
314 384
315 TEST_F(URLRequestQuicTest, CancelPushIfCached2) { 385 TEST_F(URLRequestQuicTest, CancelPushIfCached2) {
316 base::RunLoop run_loop; 386 base::RunLoop run_loop;
317 WaitForCompletionNetworkDelegate network_delegate( 387 WaitForCompletionNetworkDelegate network_delegate(
318 run_loop.QuitClosure(), /*num_expected_requests=*/3); 388 run_loop.QuitClosure(), /*num_expected_requests=*/3);
319 SetNetworkDelegate(&network_delegate); 389 SetNetworkDelegate(&network_delegate);
320 390
321 Init(); 391 Init();
322 { 392 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 CheckLoadTimingDelegate delegate(true); 427 CheckLoadTimingDelegate delegate(true);
358 std::string url = 428 std::string url =
359 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html"); 429 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
360 std::unique_ptr<URLRequest> request = 430 std::unique_ptr<URLRequest> request =
361 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate); 431 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
362 432
363 request->Start(); 433 request->Start();
364 ASSERT_TRUE(request->is_pending()); 434 ASSERT_TRUE(request->is_pending());
365 base::RunLoop().Run(); 435 base::RunLoop().Run();
366 436
437 run_loop.Run();
367 // Extract net logs on client side to verify push lookup transactions. 438 // Extract net logs on client side to verify push lookup transactions.
368 net::TestNetLogEntry::List entries; 439 net::TestNetLogEntry::List entries;
369 ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries); 440 ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
370 441
371 EXPECT_EQ(4u, entries.size()); 442 EXPECT_EQ(4u, entries.size());
372 443
373 std::string value;
374 int net_error;
375 std::string push_url_1 =
376 base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg");
377 std::string push_url_2 =
378 base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico");
379
380 EXPECT_TRUE(entries[0].GetStringValue("push_url", &value));
381 EXPECT_EQ(value, push_url_1);
382 // No net error code for this lookup transaction, the push is found.
383 EXPECT_FALSE(entries[1].GetIntegerValue("net_error", &net_error));
384
385 EXPECT_TRUE(entries[2].GetStringValue("push_url", &value));
386 EXPECT_EQ(value, push_url_2);
387 // No net error code for this lookup transaction, the push is found.
388 EXPECT_FALSE(entries[3].GetIntegerValue("net_error", &net_error));
389
390 EXPECT_TRUE(request->status().is_success()); 444 EXPECT_TRUE(request->status().is_success());
391 445
392 // Verify the reset error count received on the server side. 446 // Verify the reset error count received on the server side.
393 EXPECT_EQ(2u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED)); 447 EXPECT_EQ(2u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
394 } 448 }
395 449
396 TEST_F(URLRequestQuicTest, DoNotCancelPushIfNotFoundInCache) {
397 base::RunLoop run_loop;
398 WaitForCompletionNetworkDelegate network_delegate(
399 run_loop.QuitClosure(), /*num_expected_requests=*/1);
400 SetNetworkDelegate(&network_delegate);
401
402 Init();
403 // Send a request to /index2.hmtl which pushes /kitten-1.jpg and /favicon.ico
404 // and shouldn't cancel any since neither is in cache.
405 CheckLoadTimingDelegate delegate(false);
406 std::string url =
407 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
408 std::unique_ptr<URLRequest> request =
409 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
410
411 request->Start();
412 ASSERT_TRUE(request->is_pending());
413 base::RunLoop().Run();
414
415 // Extract net logs on client side to verify push lookup transactions.
416 net::TestNetLogEntry::List entries;
417 ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
418
419 EXPECT_EQ(4u, entries.size());
420
421 std::string value;
422 int net_error;
423 std::string push_url_1 =
424 base::StringPrintf("https://%s%s", kTestServerHost, "/kitten-1.jpg");
425 std::string push_url_2 =
426 base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico");
427
428 EXPECT_TRUE(entries[0].GetStringValue("push_url", &value));
429 EXPECT_EQ(value, push_url_1);
430 EXPECT_TRUE(entries[1].GetIntegerValue("net_error", &net_error));
431 EXPECT_EQ(net_error, -400);
432
433 EXPECT_TRUE(entries[2].GetStringValue("push_url", &value));
434 EXPECT_EQ(value, push_url_2);
435 EXPECT_TRUE(entries[3].GetIntegerValue("net_error", &net_error));
436 EXPECT_EQ(net_error, -400);
437
438 EXPECT_TRUE(request->status().is_success());
439
440 // Verify the reset error count received on the server side.
441 EXPECT_EQ(0u, GetRstErrorCountReceivedByServer(QUIC_STREAM_CANCELLED));
442 }
443
444 // Tests that if two requests use the same QUIC session, the second request 450 // Tests that if two requests use the same QUIC session, the second request
445 // should not have |LoadTimingInfo::connect_timing|. 451 // should not have |LoadTimingInfo::connect_timing|.
446 TEST_F(URLRequestQuicTest, TestTwoRequests) { 452 TEST_F(URLRequestQuicTest, TestTwoRequests) {
447 base::RunLoop run_loop; 453 base::RunLoop run_loop;
448 WaitForCompletionNetworkDelegate network_delegate( 454 WaitForCompletionNetworkDelegate network_delegate(
449 run_loop.QuitClosure(), /*num_expected_requests=*/2); 455 run_loop.QuitClosure(), /*num_expected_requests=*/2);
450 SetNetworkDelegate(&network_delegate); 456 SetNetworkDelegate(&network_delegate);
451 Init(); 457 Init();
452 CheckLoadTimingDelegate delegate(false); 458 CheckLoadTimingDelegate delegate(false);
453 delegate.set_quit_on_complete(false); 459 delegate.set_quit_on_complete(false);
(...skipping 11 matching lines...) Expand all
465 ASSERT_TRUE(request->is_pending()); 471 ASSERT_TRUE(request->is_pending());
466 ASSERT_TRUE(request2->is_pending()); 472 ASSERT_TRUE(request2->is_pending());
467 run_loop.Run(); 473 run_loop.Run();
468 474
469 EXPECT_TRUE(request->status().is_success()); 475 EXPECT_TRUE(request->status().is_success());
470 EXPECT_TRUE(request2->status().is_success()); 476 EXPECT_TRUE(request2->status().is_success());
471 EXPECT_EQ(kHelloBodyValue, delegate.data_received()); 477 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
472 EXPECT_EQ(kHelloBodyValue, delegate2.data_received()); 478 EXPECT_EQ(kHelloBodyValue, delegate2.data_received());
473 } 479 }
474 480
481 // Tests that if two requests use the same QUIC session, the second request
482 // should not have |LoadTimingInfo::connect_timing|.
483 TEST_F(URLRequestQuicTest, TestTwoRequestsSecondPush) {
484 base::RunLoop run_loop;
485 WaitForCompletionNetworkDelegate network_delegate(
486 run_loop.QuitClosure(), /*num_expected_requests=*/2);
487 SetNetworkDelegate(&network_delegate);
488 Init();
489 CheckLoadTimingDelegate delegate(false);
490 delegate.set_quit_on_complete(false);
491 std::string url =
492 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
493 std::string url2 =
494 base::StringPrintf("https://%s%s", kTestServerHost, "/favicon.ico");
495
496 std::unique_ptr<URLRequest> request =
497 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
498
499 CheckLoadTimingDelegate delegate2(true);
500 delegate2.set_quit_on_complete(false);
501 std::unique_ptr<URLRequest> request2 =
502 CreateRequest(GURL(url2), DEFAULT_PRIORITY, &delegate2);
503 request->Start();
504 ASSERT_TRUE(request->is_pending());
505 request2->Start();
506 run_loop.Run();
507 EXPECT_TRUE(request->status().is_success());
508 EXPECT_TRUE(request2->status().is_success());
509 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
510 EXPECT_EQ(kHelloBodyValue, delegate2.data_received());
511
512 net::TestNetLogEntry::List entries;
513 // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
514 // EXPECT_EQ(4u, entries.size());
515 ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
516 EXPECT_EQ(4u, entries.size());
517 EXPECT_EQ(100, GetPushPromiseSent());
518 }
519
520 TEST_F(URLRequestQuicTest, TestRequestsSentPush) {
521 base::RunLoop run_loop;
522 WaitForCompletionNetworkDelegate network_delegate(
523 run_loop.QuitClosure(), /*num_expected_requests=*/1);
524 SetNetworkDelegate(&network_delegate);
525 Init();
526 CheckLoadTimingDelegate delegate(false);
527 delegate.set_quit_on_complete(false);
528 std::string url =
529 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
530
531 std::unique_ptr<URLRequest> request =
532 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
533
534 request->Start();
535 ASSERT_TRUE(request->is_pending());
536 run_loop.Run();
537
538 EXPECT_TRUE(request->status().is_success());
539 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
540
541 net::TestNetLogEntry::List entries;
542 // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
543 // EXPECT_EQ(4u, entries.size());
544 ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
545 EXPECT_EQ(4u, entries.size());
546 EXPECT_EQ(100, GetPushPromiseSent());
547 }
548
549 TEST_F(URLRequestQuicTest, TestGetRequest2) {
550 Init();
551 CheckLoadTimingDelegate delegate(false);
552 std::string url =
553 base::StringPrintf("https://%s%s", kTestServerHost, "/index2.html");
554 std::unique_ptr<URLRequest> request =
555 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
556
557 request->Start();
558 ASSERT_TRUE(request->is_pending());
559 base::RunLoop().Run();
560
561 EXPECT_TRUE(request->status().is_success());
562 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
563
564 net::TestNetLogEntry::List entries;
565 // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
566 // EXPECT_EQ(4u, entries.size());
567 ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
568 EXPECT_EQ(4u, entries.size());
569 EXPECT_EQ(100, GetPushPromiseSent());
570 }
571
572 TEST_F(URLRequestQuicTest, TestRequestsSentPush3ManualAdd) {
573 base::RunLoop run_loop;
574 WaitForCompletionNetworkDelegate network_delegate(
575 run_loop.QuitClosure(), /*num_expected_requests=*/1);
576 SetNetworkDelegate(&network_delegate);
577 Init();
578 CheckLoadTimingDelegate delegate(false);
579 delegate.set_quit_on_complete(false);
580 std::string url =
581 base::StringPrintf("https://%s%s", kTestServerHost, "/index3.html");
582
583 std::unique_ptr<URLRequest> request =
584 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
585
586 request->Start();
587 ASSERT_TRUE(request->is_pending());
588 run_loop.Run();
589
590 EXPECT_TRUE(request->status().is_success());
591 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
592
593 net::TestNetLogEntry::List entries;
594 // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
595 // EXPECT_EQ(4u, entries.size());
596 ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
597 EXPECT_EQ(100u, entries.size());
598 EXPECT_EQ(100, GetPushPromiseSent());
599 }
600
601 TEST_F(URLRequestQuicTest, TestGetRequest3ManualAddPush) {
602 Init();
603 CheckLoadTimingDelegate delegate(false);
604 std::string url =
605 base::StringPrintf("https://%s%s", kTestServerHost, "/index3.html");
606 std::unique_ptr<URLRequest> request =
607 CreateRequest(GURL(url), DEFAULT_PRIORITY, &delegate);
608
609 request->Start();
610 ASSERT_TRUE(request->is_pending());
611 base::RunLoop().Run();
612
613 EXPECT_TRUE(request->status().is_success());
614 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
615
616 net::TestNetLogEntry::List entries;
617 // ExtractNetLog(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, &entries);
618 // EXPECT_EQ(4u, entries.size());
619 ExtractNetLog(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, &entries);
620 EXPECT_EQ(100u, entries.size());
621 EXPECT_EQ(100, GetPushPromiseSent());
622 }
623
624
475 } // namespace net 625 } // namespace net
OLDNEW
« 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