| OLD | NEW |
| 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 4957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4968 | 4968 |
| 4969 scoped_ptr<SpdyFrame> | 4969 scoped_ptr<SpdyFrame> |
| 4970 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); | 4970 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4971 MockRead reads[] = { | 4971 MockRead reads[] = { |
| 4972 CreateMockRead(*stream1_reply, 1), | 4972 CreateMockRead(*stream1_reply, 1), |
| 4973 CreateMockRead(*stream2_syn, 2), | 4973 CreateMockRead(*stream2_syn, 2), |
| 4974 CreateMockRead(*stream1_body, 3), | 4974 CreateMockRead(*stream1_body, 3), |
| 4975 CreateMockRead(*stream2_headers, 4), | 4975 CreateMockRead(*stream2_headers, 4), |
| 4976 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), | 4976 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), |
| 4977 arraysize(kPushBodyFrame), 5), | 4977 arraysize(kPushBodyFrame), 5), |
| 4978 MockRead(ASYNC, 0, 5), // EOF | 4978 MockRead(ASYNC, 0, 6), // EOF |
| 4979 }; | 4979 }; |
| 4980 | 4980 |
| 4981 HttpResponseInfo response; | 4981 HttpResponseInfo response; |
| 4982 HttpResponseInfo response2; | 4982 HttpResponseInfo response2; |
| 4983 std::string expected_push_result("pushed"); | 4983 std::string expected_push_result("pushed"); |
| 4984 scoped_ptr<DeterministicSocketData> data( | 4984 scoped_ptr<DeterministicSocketData> data( |
| 4985 new DeterministicSocketData(reads, arraysize(reads), | 4985 new DeterministicSocketData(reads, arraysize(reads), |
| 4986 writes, arraysize(writes))); | 4986 writes, arraysize(writes))); |
| 4987 | 4987 |
| 4988 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 4988 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5017 data->RunFor(3); | 5017 data->RunFor(3); |
| 5018 MessageLoop::current()->RunAllPending(); | 5018 MessageLoop::current()->RunAllPending(); |
| 5019 | 5019 |
| 5020 // Read the server push body. | 5020 // Read the server push body. |
| 5021 std::string result2; | 5021 std::string result2; |
| 5022 ReadResult(trans2.get(), data.get(), &result2); | 5022 ReadResult(trans2.get(), data.get(), &result2); |
| 5023 // Read the response body. | 5023 // Read the response body. |
| 5024 std::string result; | 5024 std::string result; |
| 5025 ReadResult(trans, data.get(), &result); | 5025 ReadResult(trans, data.get(), &result); |
| 5026 | 5026 |
| 5027 // Verify that we consumed all test data. | |
| 5028 EXPECT_TRUE(data->at_read_eof()); | |
| 5029 EXPECT_TRUE(data->at_write_eof()); | |
| 5030 | |
| 5031 // Verify that the received push data is same as the expected push data. | 5027 // Verify that the received push data is same as the expected push data. |
| 5032 EXPECT_EQ(result2.compare(expected_push_result), 0) | 5028 EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5033 << "Received data: " | 5029 << "Received data: " |
| 5034 << result2 | 5030 << result2 |
| 5035 << "||||| Expected data: " | 5031 << "||||| Expected data: " |
| 5036 << expected_push_result; | 5032 << expected_push_result; |
| 5037 | 5033 |
| 5038 // Verify the SYN_REPLY. | 5034 // Verify the SYN_REPLY. |
| 5039 // Copy the response info, because trans goes away. | 5035 // Copy the response info, because trans goes away. |
| 5040 response = *trans->GetResponseInfo(); | 5036 response = *trans->GetResponseInfo(); |
| 5041 response2 = *trans2->GetResponseInfo(); | 5037 response2 = *trans2->GetResponseInfo(); |
| 5042 | 5038 |
| 5043 VerifyStreamsClosed(helper); | 5039 VerifyStreamsClosed(helper); |
| 5044 | 5040 |
| 5045 // Verify the SYN_REPLY. | 5041 // Verify the SYN_REPLY. |
| 5046 EXPECT_TRUE(response.headers != NULL); | 5042 EXPECT_TRUE(response.headers != NULL); |
| 5047 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5043 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5048 | 5044 |
| 5049 // Verify the pushed stream. | 5045 // Verify the pushed stream. |
| 5050 EXPECT_TRUE(response2.headers != NULL); | 5046 EXPECT_TRUE(response2.headers != NULL); |
| 5051 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 5047 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5048 |
| 5049 // Read the final EOF (which will close the session) |
| 5050 data->RunFor(1); |
| 5051 |
| 5052 // Verify that we consumed all test data. |
| 5053 EXPECT_TRUE(data->at_read_eof()); |
| 5054 EXPECT_TRUE(data->at_write_eof()); |
| 5052 } | 5055 } |
| 5053 | 5056 |
| 5054 TEST_P(SpdyNetworkTransactionSpdy2Test, ServerPushWithTwoHeaderFrames) { | 5057 TEST_P(SpdyNetworkTransactionSpdy2Test, ServerPushWithTwoHeaderFrames) { |
| 5055 // We push a stream and attempt to claim it before the headers come down. | 5058 // We push a stream and attempt to claim it before the headers come down. |
| 5056 static const unsigned char kPushBodyFrame[] = { | 5059 static const unsigned char kPushBodyFrame[] = { |
| 5057 0x00, 0x00, 0x00, 0x02, // header, ID | 5060 0x00, 0x00, 0x00, 0x02, // header, ID |
| 5058 0x01, 0x00, 0x00, 0x06, // FIN, length | 5061 0x01, 0x00, 0x00, 0x06, // FIN, length |
| 5059 'p', 'u', 's', 'h', 'e', 'd' // "pushed" | 5062 'p', 'u', 's', 'h', 'e', 'd' // "pushed" |
| 5060 }; | 5063 }; |
| 5061 scoped_ptr<SpdyFrame> | 5064 scoped_ptr<SpdyFrame> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5117 scoped_ptr<SpdyFrame> | 5120 scoped_ptr<SpdyFrame> |
| 5118 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); | 5121 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5119 MockRead reads[] = { | 5122 MockRead reads[] = { |
| 5120 CreateMockRead(*stream1_reply, 1), | 5123 CreateMockRead(*stream1_reply, 1), |
| 5121 CreateMockRead(*stream2_syn, 2), | 5124 CreateMockRead(*stream2_syn, 2), |
| 5122 CreateMockRead(*stream1_body, 3), | 5125 CreateMockRead(*stream1_body, 3), |
| 5123 CreateMockRead(*stream2_headers1, 4), | 5126 CreateMockRead(*stream2_headers1, 4), |
| 5124 CreateMockRead(*stream2_headers2, 5), | 5127 CreateMockRead(*stream2_headers2, 5), |
| 5125 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), | 5128 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), |
| 5126 arraysize(kPushBodyFrame), 6), | 5129 arraysize(kPushBodyFrame), 6), |
| 5127 MockRead(ASYNC, 0, 6), // EOF | 5130 MockRead(ASYNC, 0, 7), // EOF |
| 5128 }; | 5131 }; |
| 5129 | 5132 |
| 5130 HttpResponseInfo response; | 5133 HttpResponseInfo response; |
| 5131 HttpResponseInfo response2; | 5134 HttpResponseInfo response2; |
| 5132 std::string expected_push_result("pushed"); | 5135 std::string expected_push_result("pushed"); |
| 5133 scoped_ptr<DeterministicSocketData> data( | 5136 scoped_ptr<DeterministicSocketData> data( |
| 5134 new DeterministicSocketData(reads, arraysize(reads), | 5137 new DeterministicSocketData(reads, arraysize(reads), |
| 5135 writes, arraysize(writes))); | 5138 writes, arraysize(writes))); |
| 5136 | 5139 |
| 5137 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 5140 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5166 data->RunFor(3); | 5169 data->RunFor(3); |
| 5167 MessageLoop::current()->RunAllPending(); | 5170 MessageLoop::current()->RunAllPending(); |
| 5168 | 5171 |
| 5169 // Read the server push body. | 5172 // Read the server push body. |
| 5170 std::string result2; | 5173 std::string result2; |
| 5171 ReadResult(trans2.get(), data.get(), &result2); | 5174 ReadResult(trans2.get(), data.get(), &result2); |
| 5172 // Read the response body. | 5175 // Read the response body. |
| 5173 std::string result; | 5176 std::string result; |
| 5174 ReadResult(trans, data.get(), &result); | 5177 ReadResult(trans, data.get(), &result); |
| 5175 | 5178 |
| 5176 // Verify that we consumed all test data. | |
| 5177 EXPECT_TRUE(data->at_read_eof()); | |
| 5178 EXPECT_TRUE(data->at_write_eof()); | |
| 5179 | |
| 5180 // Verify that the received push data is same as the expected push data. | 5179 // Verify that the received push data is same as the expected push data. |
| 5181 EXPECT_EQ(result2.compare(expected_push_result), 0) | 5180 EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5182 << "Received data: " | 5181 << "Received data: " |
| 5183 << result2 | 5182 << result2 |
| 5184 << "||||| Expected data: " | 5183 << "||||| Expected data: " |
| 5185 << expected_push_result; | 5184 << expected_push_result; |
| 5186 | 5185 |
| 5187 // Verify the SYN_REPLY. | 5186 // Verify the SYN_REPLY. |
| 5188 // Copy the response info, because trans goes away. | 5187 // Copy the response info, because trans goes away. |
| 5189 response = *trans->GetResponseInfo(); | 5188 response = *trans->GetResponseInfo(); |
| 5190 response2 = *trans2->GetResponseInfo(); | 5189 response2 = *trans2->GetResponseInfo(); |
| 5191 | 5190 |
| 5192 VerifyStreamsClosed(helper); | 5191 VerifyStreamsClosed(helper); |
| 5193 | 5192 |
| 5194 // Verify the SYN_REPLY. | 5193 // Verify the SYN_REPLY. |
| 5195 EXPECT_TRUE(response.headers != NULL); | 5194 EXPECT_TRUE(response.headers != NULL); |
| 5196 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5195 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5197 | 5196 |
| 5198 // Verify the pushed stream. | 5197 // Verify the pushed stream. |
| 5199 EXPECT_TRUE(response2.headers != NULL); | 5198 EXPECT_TRUE(response2.headers != NULL); |
| 5200 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 5199 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5201 | 5200 |
| 5202 // Verify we got all the headers | 5201 // Verify we got all the headers |
| 5203 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5202 EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5204 "url", | 5203 "url", |
| 5205 "http://www.google.com/foo.dat")); | 5204 "http://www.google.com/foo.dat")); |
| 5206 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); | 5205 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5207 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); | 5206 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
| 5208 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1")); | 5207 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1")); |
| 5208 |
| 5209 // Read the final EOF (which will close the session) |
| 5210 data->RunFor(1); |
| 5211 |
| 5212 // Verify that we consumed all test data. |
| 5213 EXPECT_TRUE(data->at_read_eof()); |
| 5214 EXPECT_TRUE(data->at_write_eof()); |
| 5209 } | 5215 } |
| 5210 | 5216 |
| 5211 TEST_P(SpdyNetworkTransactionSpdy2Test, SynReplyWithHeaders) { | 5217 TEST_P(SpdyNetworkTransactionSpdy2Test, SynReplyWithHeaders) { |
| 5212 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 5218 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 5213 MockWrite writes[] = { CreateMockWrite(*req) }; | 5219 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 5214 | 5220 |
| 5215 static const char* const kInitialHeaders[] = { | 5221 static const char* const kInitialHeaders[] = { |
| 5216 "status", | 5222 "status", |
| 5217 "200 OK", | 5223 "200 OK", |
| 5218 "version", | 5224 "version", |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5632 // And now we can allow everything else to run to completion. | 5638 // And now we can allow everything else to run to completion. |
| 5633 data->SetStop(10); | 5639 data->SetStop(10); |
| 5634 data->Run(); | 5640 data->Run(); |
| 5635 EXPECT_EQ(OK, callback2.WaitForResult()); | 5641 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5636 EXPECT_EQ(OK, callback3.WaitForResult()); | 5642 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5637 | 5643 |
| 5638 helper.VerifyDataConsumed(); | 5644 helper.VerifyDataConsumed(); |
| 5639 } | 5645 } |
| 5640 | 5646 |
| 5641 } // namespace net | 5647 } // namespace net |
| OLD | NEW |