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

Side by Side Diff: net/spdy/spdy_http_stream_unittest.cc

Issue 2140673002: Remove SPDY/3.1 tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/spdy/spdy_http_stream.h" 5 #include "net/spdy/spdy_http_stream.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 22 matching lines...) Expand all
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 using net::test::IsError; 35 using net::test::IsError;
36 using net::test::IsOk; 36 using net::test::IsOk;
37 37
38 namespace net { 38 namespace net {
39 39
40 namespace { 40 namespace {
41 41
42 enum TestCase { 42 enum TestCase {
43 // Test using the SPDY/3.1 protocol. 43 // Test without specifying a stream dependency based on the RequestPriority.
44 kTestCaseSPDY31, 44 kTestCaseNoPriorityDependencies,
45 45
46 // Test using the HTTP/2 protocol, without specifying a stream 46 // Test specifying a stream dependency based on the RequestPriority.
47 // dependency based on the RequestPriority. 47 kTestCasePriorityDependencies
48 kTestCaseHTTP2NoPriorityDependencies,
49
50 // Test using the HTTP/2 protocol, specifying a stream
51 // dependency based on the RequestPriority.
52 kTestCaseHTTP2PriorityDependencies
53 }; 48 };
54 49
55 // Tests the load timing of a stream that's connected and is not the first 50 // Tests the load timing of a stream that's connected and is not the first
56 // request sent on a connection. 51 // request sent on a connection.
57 void TestLoadTimingReused(const HttpStream& stream) { 52 void TestLoadTimingReused(const HttpStream& stream) {
58 LoadTimingInfo load_timing_info; 53 LoadTimingInfo load_timing_info;
59 EXPECT_TRUE(stream.GetLoadTimingInfo(&load_timing_info)); 54 EXPECT_TRUE(stream.GetLoadTimingInfo(&load_timing_info));
60 55
61 EXPECT_TRUE(load_timing_info.socket_reused); 56 EXPECT_TRUE(load_timing_info.socket_reused);
62 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 57 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 105
111 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); 106 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream);
112 }; 107 };
113 108
114 } // namespace 109 } // namespace
115 110
116 class SpdyHttpStreamTest : public testing::Test, 111 class SpdyHttpStreamTest : public testing::Test,
117 public testing::WithParamInterface<TestCase> { 112 public testing::WithParamInterface<TestCase> {
118 public: 113 public:
119 SpdyHttpStreamTest() 114 SpdyHttpStreamTest()
120 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), 115 : spdy_util_(GetDependenciesFromPriority()),
121 session_deps_(GetProtocol()),
122 host_port_pair_(HostPortPair::FromURL(GURL(kDefaultUrl))), 116 host_port_pair_(HostPortPair::FromURL(GURL(kDefaultUrl))),
123 key_(host_port_pair_, ProxyServer::Direct(), PRIVACY_MODE_DISABLED) { 117 key_(host_port_pair_, ProxyServer::Direct(), PRIVACY_MODE_DISABLED) {
124 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); 118 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority();
125 session_deps_.net_log = &net_log_; 119 session_deps_.net_log = &net_log_;
126 spdy_util_.set_default_url(GURL("http://www.example.org/")); 120 spdy_util_.set_default_url(GURL("http://www.example.org/"));
127 } 121 }
128 122
129 ~SpdyHttpStreamTest() {} 123 ~SpdyHttpStreamTest() {}
130 124
131 protected: 125 protected:
132 NextProto GetProtocol() const {
133 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2;
134 }
135
136 bool GetDependenciesFromPriority() const { 126 bool GetDependenciesFromPriority() const {
137 return GetParam() == kTestCaseHTTP2PriorityDependencies; 127 return GetParam() == kTestCasePriorityDependencies;
138 } 128 }
139 129
140 void TearDown() override { 130 void TearDown() override {
141 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); 131 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr);
142 base::RunLoop().RunUntilIdle(); 132 base::RunLoop().RunUntilIdle();
143 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); 133 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed());
144 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); 134 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed());
145 } 135 }
146 136
147 // Initializes the session using SequencedSocketData. 137 // Initializes the session using SequencedSocketData.
(...skipping 22 matching lines...) Expand all
170 std::unique_ptr<SequencedSocketData> sequenced_data_; 160 std::unique_ptr<SequencedSocketData> sequenced_data_;
171 std::unique_ptr<HttpNetworkSession> http_session_; 161 std::unique_ptr<HttpNetworkSession> http_session_;
172 base::WeakPtr<SpdySession> session_; 162 base::WeakPtr<SpdySession> session_;
173 163
174 private: 164 private:
175 MockECSignatureCreatorFactory ec_signature_creator_factory_; 165 MockECSignatureCreatorFactory ec_signature_creator_factory_;
176 }; 166 };
177 167
178 INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, 168 INSTANTIATE_TEST_CASE_P(ProtoPlusDepend,
179 SpdyHttpStreamTest, 169 SpdyHttpStreamTest,
180 testing::Values(kTestCaseSPDY31, 170 testing::Values(kTestCaseNoPriorityDependencies,
181 kTestCaseHTTP2NoPriorityDependencies, 171 kTestCasePriorityDependencies));
182 kTestCaseHTTP2PriorityDependencies));
183 172
184 // SpdyHttpStream::GetUploadProgress() should still work even before the 173 // SpdyHttpStream::GetUploadProgress() should still work even before the
185 // stream is initialized. 174 // stream is initialized.
186 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { 175 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) {
187 MockRead reads[] = { 176 MockRead reads[] = {
188 MockRead(ASYNC, 0, 0) // EOF 177 MockRead(ASYNC, 0, 0) // EOF
189 }; 178 };
190 179
191 InitSession(reads, arraysize(reads), nullptr, 0); 180 InitSession(reads, arraysize(reads), nullptr, 0);
192 181
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Stream 2 still has queued body data. 340 // Stream 2 still has queued body data.
352 TestLoadTimingReused(*http_stream2); 341 TestLoadTimingReused(*http_stream2);
353 342
354 EXPECT_EQ(static_cast<int64_t>(req2->size()), 343 EXPECT_EQ(static_cast<int64_t>(req2->size()),
355 http_stream2->GetTotalSentBytes()); 344 http_stream2->GetTotalSentBytes());
356 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()), 345 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()),
357 http_stream2->GetTotalReceivedBytes()); 346 http_stream2->GetTotalReceivedBytes());
358 } 347 }
359 348
360 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { 349 TEST_P(SpdyHttpStreamTest, SendChunkedPost) {
361 BufferedSpdyFramer framer(spdy_util_.spdy_version()); 350 BufferedSpdyFramer framer(HTTP2);
362 351
363 std::unique_ptr<SpdySerializedFrame> req( 352 std::unique_ptr<SpdySerializedFrame> req(
364 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); 353 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0));
365 std::unique_ptr<SpdySerializedFrame> body( 354 std::unique_ptr<SpdySerializedFrame> body(
366 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); 355 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN));
367 MockWrite writes[] = { 356 MockWrite writes[] = {
368 CreateMockWrite(*req, 0), // request 357 CreateMockWrite(*req, 0), // request
369 CreateMockWrite(*body, 1) // POST upload frame 358 CreateMockWrite(*body, 1) // POST upload frame
370 }; 359 };
371 360
372 std::unique_ptr<SpdySerializedFrame> resp( 361 std::unique_ptr<SpdySerializedFrame> resp(
373 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); 362 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0));
374 MockRead reads[] = { 363 MockRead reads[] = {
375 CreateMockRead(*resp, 2), 364 CreateMockRead(*resp, 2),
376 CreateMockRead(*body, 3), 365 CreateMockRead(*body, 3),
377 MockRead(SYNCHRONOUS, 0, 4) // EOF 366 MockRead(SYNCHRONOUS, 0, 4) // EOF
378 }; 367 };
379 368
380 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 369 InitSession(reads, arraysize(reads), writes, arraysize(writes));
381 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 370 EXPECT_EQ(HTTP2, session_->GetProtocolVersion());
382 371
383 ChunkedUploadDataStream upload_stream(0); 372 ChunkedUploadDataStream upload_stream(0);
384 const int kFirstChunkSize = kUploadDataSize/2; 373 const int kFirstChunkSize = kUploadDataSize/2;
385 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); 374 upload_stream.AppendData(kUploadData, kFirstChunkSize, false);
386 upload_stream.AppendData(kUploadData + kFirstChunkSize, 375 upload_stream.AppendData(kUploadData + kFirstChunkSize,
387 kUploadDataSize - kFirstChunkSize, true); 376 kUploadDataSize - kFirstChunkSize, true);
388 377
389 HttpRequestInfo request; 378 HttpRequestInfo request;
390 request.method = "POST"; 379 request.method = "POST";
391 request.url = GURL("http://www.example.org/"); 380 request.url = GURL("http://www.example.org/");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 421
433 std::unique_ptr<SpdySerializedFrame> resp( 422 std::unique_ptr<SpdySerializedFrame> resp(
434 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); 423 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0));
435 MockRead reads[] = { 424 MockRead reads[] = {
436 CreateMockRead(*resp, 2), 425 CreateMockRead(*resp, 2),
437 CreateMockRead(*chunk, 3), 426 CreateMockRead(*chunk, 3),
438 MockRead(SYNCHRONOUS, 0, 4) // EOF 427 MockRead(SYNCHRONOUS, 0, 4) // EOF
439 }; 428 };
440 429
441 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 430 InitSession(reads, arraysize(reads), writes, arraysize(writes));
442 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 431 EXPECT_EQ(HTTP2, session_->GetProtocolVersion());
443 432
444 ChunkedUploadDataStream upload_stream(0); 433 ChunkedUploadDataStream upload_stream(0);
445 upload_stream.AppendData(nullptr, 0, true); 434 upload_stream.AppendData(nullptr, 0, true);
446 435
447 HttpRequestInfo request; 436 HttpRequestInfo request;
448 request.method = "POST"; 437 request.method = "POST";
449 request.url = GURL("http://www.example.org/"); 438 request.url = GURL("http://www.example.org/");
450 request.upload_data_stream = &upload_stream; 439 request.upload_data_stream = &upload_stream;
451 440
452 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); 441 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
(...skipping 15 matching lines...) Expand all
468 http_stream.GetTotalSentBytes()); 457 http_stream.GetTotalSentBytes());
469 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), 458 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()),
470 http_stream.GetTotalReceivedBytes()); 459 http_stream.GetTotalReceivedBytes());
471 460
472 // Because the server closed the connection, there shouldn't be a session 461 // Because the server closed the connection, there shouldn't be a session
473 // in the pool anymore. 462 // in the pool anymore.
474 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 463 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
475 } 464 }
476 465
477 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { 466 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) {
478 BufferedSpdyFramer framer(spdy_util_.spdy_version()); 467 BufferedSpdyFramer framer(HTTP2);
479 468
480 std::unique_ptr<SpdySerializedFrame> req( 469 std::unique_ptr<SpdySerializedFrame> req(
481 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); 470 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0));
482 std::unique_ptr<SpdySerializedFrame> body( 471 std::unique_ptr<SpdySerializedFrame> body(
483 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); 472 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE));
484 MockWrite writes[] = { 473 MockWrite writes[] = {
485 CreateMockWrite(*req, 0), // Request 474 CreateMockWrite(*req, 0), // Request
486 CreateMockWrite(*body, 1) // First POST upload frame 475 CreateMockWrite(*body, 1) // First POST upload frame
487 }; 476 };
488 477
489 std::unique_ptr<SpdySerializedFrame> resp( 478 std::unique_ptr<SpdySerializedFrame> resp(
490 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); 479 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0));
491 MockRead reads[] = { 480 MockRead reads[] = {
492 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. 481 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early.
493 }; 482 };
494 483
495 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 484 InitSession(reads, arraysize(reads), writes, arraysize(writes));
496 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 485 EXPECT_EQ(HTTP2, session_->GetProtocolVersion());
497 486
498 ChunkedUploadDataStream upload_stream(0); 487 ChunkedUploadDataStream upload_stream(0);
499 // Append first chunk. 488 // Append first chunk.
500 upload_stream.AppendData(kUploadData, kUploadDataSize, false); 489 upload_stream.AppendData(kUploadData, kUploadDataSize, false);
501 490
502 HttpRequestInfo request; 491 HttpRequestInfo request;
503 request.method = "POST"; 492 request.method = "POST";
504 request.url = GURL("http://www.example.org/"); 493 request.url = GURL("http://www.example.org/");
505 request.upload_data_stream = &upload_stream; 494 request.upload_data_stream = &upload_stream;
506 495
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 }; 961 };
973 962
974 std::unique_ptr<SpdySerializedFrame> resp( 963 std::unique_ptr<SpdySerializedFrame> resp(
975 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); 964 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0));
976 965
977 MockRead reads[] = { 966 MockRead reads[] = {
978 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3), 967 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3),
979 }; 968 };
980 969
981 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 970 InitSession(reads, arraysize(reads), writes, arraysize(writes));
982 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 971 EXPECT_EQ(HTTP2, session_->GetProtocolVersion());
983 972
984 ReadErrorUploadDataStream upload_data_stream( 973 ReadErrorUploadDataStream upload_data_stream(
985 ReadErrorUploadDataStream::FailureMode::SYNC); 974 ReadErrorUploadDataStream::FailureMode::SYNC);
986 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), 975 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()),
987 IsOk()); 976 IsOk());
988 977
989 HttpRequestInfo request; 978 HttpRequestInfo request;
990 request.method = "POST"; 979 request.method = "POST";
991 request.url = GURL("http://www.example.org/"); 980 request.url = GURL("http://www.example.org/");
992 request.upload_data_stream = &upload_data_stream; 981 request.upload_data_stream = &upload_data_stream;
(...skipping 30 matching lines...) Expand all
1023 }; 1012 };
1024 1013
1025 std::unique_ptr<SpdySerializedFrame> resp( 1014 std::unique_ptr<SpdySerializedFrame> resp(
1026 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); 1015 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0));
1027 1016
1028 MockRead reads[] = { 1017 MockRead reads[] = {
1029 MockRead(ASYNC, 0, 2), 1018 MockRead(ASYNC, 0, 2),
1030 }; 1019 };
1031 1020
1032 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 1021 InitSession(reads, arraysize(reads), writes, arraysize(writes));
1033 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 1022 EXPECT_EQ(HTTP2, session_->GetProtocolVersion());
1034 1023
1035 ReadErrorUploadDataStream upload_data_stream( 1024 ReadErrorUploadDataStream upload_data_stream(
1036 ReadErrorUploadDataStream::FailureMode::ASYNC); 1025 ReadErrorUploadDataStream::FailureMode::ASYNC);
1037 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), 1026 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()),
1038 IsOk()); 1027 IsOk());
1039 1028
1040 HttpRequestInfo request; 1029 HttpRequestInfo request;
1041 request.method = "POST"; 1030 request.method = "POST";
1042 request.url = GURL("http://www.example.org/"); 1031 request.url = GURL("http://www.example.org/");
1043 request.upload_data_stream = &upload_data_stream; 1032 request.upload_data_stream = &upload_data_stream;
(...skipping 12 matching lines...) Expand all
1056 1045
1057 // Because the server has closed the connection, there shouldn't be a session 1046 // Because the server has closed the connection, there shouldn't be a session
1058 // in the pool anymore. 1047 // in the pool anymore.
1059 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 1048 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
1060 } 1049 }
1061 1050
1062 // TODO(willchan): Write a longer test for SpdyStream that exercises all 1051 // TODO(willchan): Write a longer test for SpdyStream that exercises all
1063 // methods. 1052 // methods.
1064 1053
1065 } // namespace net 1054 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/buffered_spdy_framer_unittest.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698