OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_network_transaction.h" | 5 #include "net/spdy/spdy_network_transaction.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/load_log_unittest.h" | 10 #include "net/base/load_log_unittest.h" |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, | 1092 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, |
1093 net::LoadLog::PHASE_END); | 1093 net::LoadLog::PHASE_END); |
1094 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1094 pos = net::ExpectLogContainsSomewhere(log, pos + 1, |
1095 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_BODY, | 1095 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_BODY, |
1096 net::LoadLog::PHASE_BEGIN); | 1096 net::LoadLog::PHASE_BEGIN); |
1097 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1097 pos = net::ExpectLogContainsSomewhere(log, pos + 1, |
1098 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_BODY, | 1098 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_BODY, |
1099 net::LoadLog::PHASE_END); | 1099 net::LoadLog::PHASE_END); |
1100 } | 1100 } |
1101 | 1101 |
| 1102 // Since we buffer the IO from the stream to the renderer, this test verifies |
| 1103 // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 1104 // on the network, but issued a Read for only 5 of those bytes) that the data |
| 1105 // flow still works correctly. |
| 1106 TEST_F(SpdyNetworkTransactionTest, FullBuffer) { |
| 1107 MockWrite writes[] = { |
| 1108 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| 1109 arraysize(kGetSyn)), |
| 1110 }; |
| 1111 |
| 1112 static const unsigned char kCombinedDataFrames[] = { |
| 1113 0x00, 0x00, 0x00, 0x01, // header |
| 1114 0x00, 0x00, 0x00, 0x06, // length |
| 1115 'g', 'o', 'o', 'd', 'b', 'y', |
| 1116 0x00, 0x00, 0x00, 0x01, // header |
| 1117 0x00, 0x00, 0x00, 0x06, // length |
| 1118 'e', ' ', 'w', 'o', 'r', 'l', |
| 1119 }; |
| 1120 |
| 1121 static const unsigned char kLastFrame[] = { |
| 1122 0x00, 0x00, 0x00, 0x01, // header |
| 1123 0x01, 0x00, 0x00, 0x01, // FIN, length |
| 1124 'd', |
| 1125 }; |
| 1126 |
| 1127 MockRead reads[] = { |
| 1128 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
| 1129 arraysize(kGetSynReply)), |
| 1130 MockRead(true, ERR_IO_PENDING), // Force a pause |
| 1131 MockRead(true, reinterpret_cast<const char*>(kCombinedDataFrames), |
| 1132 arraysize(kCombinedDataFrames)), |
| 1133 MockRead(true, ERR_IO_PENDING), // Force a pause |
| 1134 MockRead(true, reinterpret_cast<const char*>(kLastFrame), |
| 1135 arraysize(kLastFrame)), |
| 1136 MockRead(true, 0, 0) // EOF |
| 1137 }; |
| 1138 |
| 1139 HttpRequestInfo request; |
| 1140 request.method = "GET"; |
| 1141 request.url = GURL("http://www.google.com/"); |
| 1142 request.load_flags = 0; |
| 1143 scoped_refptr<DelayedSocketData> data( |
| 1144 new DelayedSocketData(1, reads, arraysize(reads), |
| 1145 writes, arraysize(writes))); |
| 1146 |
| 1147 // For this test, we can't use the TransactionHelper, because we are |
| 1148 // going to tightly control how the IOs fly. |
| 1149 |
| 1150 TransactionHelperResult out; |
| 1151 |
| 1152 // We disable SSL for this test. |
| 1153 SpdySession::SetSSLMode(false); |
| 1154 |
| 1155 SessionDependencies session_deps; |
| 1156 scoped_ptr<SpdyNetworkTransaction> trans( |
| 1157 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 1158 |
| 1159 session_deps.socket_factory.AddSocketDataProvider(data); |
| 1160 |
| 1161 TestCompletionCallback callback; |
| 1162 |
| 1163 int rv = trans->Start(&request, &callback, NULL); |
| 1164 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1165 |
| 1166 out.rv = callback.WaitForResult(); |
| 1167 EXPECT_EQ(out.rv, OK); |
| 1168 |
| 1169 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1170 EXPECT_TRUE(response->headers != NULL); |
| 1171 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 1172 out.status_line = response->headers->GetStatusLine(); |
| 1173 out.response_info = *response; // Make a copy so we can verify. |
| 1174 |
| 1175 // Read Data |
| 1176 TestCompletionCallback read_callback; |
| 1177 |
| 1178 std::string content; |
| 1179 do { |
| 1180 // Read small chunks at a time. |
| 1181 const int kSmallReadSize = 3; |
| 1182 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSmallReadSize); |
| 1183 rv = trans->Read(buf, kSmallReadSize, &read_callback); |
| 1184 if (rv == net::ERR_IO_PENDING) { |
| 1185 data->CompleteRead(); |
| 1186 rv = read_callback.WaitForResult(); |
| 1187 } |
| 1188 if (rv > 0) { |
| 1189 content.append(buf->data(), rv); |
| 1190 } else if (rv < 0) { |
| 1191 NOTREACHED(); |
| 1192 } |
| 1193 } while (rv > 0); |
| 1194 |
| 1195 out.response_data.swap(content); |
| 1196 |
| 1197 // Verify that we consumed all test data. |
| 1198 EXPECT_TRUE(data->at_read_eof()); |
| 1199 EXPECT_TRUE(data->at_write_eof()); |
| 1200 |
| 1201 EXPECT_EQ(OK, out.rv); |
| 1202 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1203 EXPECT_EQ("goodbye world", out.response_data); |
| 1204 } |
| 1205 |
1102 } // namespace net | 1206 } // namespace net |
OLD | NEW |