| 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" | |
| 11 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
| 11 #include "net/base/net_log_unittest.h" |
| 12 #include "net/base/ssl_config_service_defaults.h" | 12 #include "net/base/ssl_config_service_defaults.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "net/base/upload_data.h" | 14 #include "net/base/upload_data.h" |
| 15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
| 16 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
| 17 #include "net/http/http_transaction_unittest.h" | 17 #include "net/http/http_transaction_unittest.h" |
| 18 #include "net/proxy/proxy_config_service_fixed.h" | 18 #include "net/proxy/proxy_config_service_fixed.h" |
| 19 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
| 20 #include "net/spdy/spdy_protocol.h" | 20 #include "net/spdy/spdy_protocol.h" |
| 21 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 std::string response_data; | 278 std::string response_data; |
| 279 HttpResponseInfo response_info; | 279 HttpResponseInfo response_info; |
| 280 }; | 280 }; |
| 281 | 281 |
| 282 void EnableCompression(bool enabled) { | 282 void EnableCompression(bool enabled) { |
| 283 spdy::SpdyFramer::set_enable_compression_default(enabled); | 283 spdy::SpdyFramer::set_enable_compression_default(enabled); |
| 284 } | 284 } |
| 285 | 285 |
| 286 TransactionHelperResult TransactionHelper(const HttpRequestInfo& request, | 286 TransactionHelperResult TransactionHelper(const HttpRequestInfo& request, |
| 287 DelayedSocketData* data, | 287 DelayedSocketData* data, |
| 288 LoadLog* log) { | 288 const BoundNetLog& log) { |
| 289 TransactionHelperResult out; | 289 TransactionHelperResult out; |
| 290 | 290 |
| 291 // We disable SSL for this test. | 291 // We disable SSL for this test. |
| 292 SpdySession::SetSSLMode(false); | 292 SpdySession::SetSSLMode(false); |
| 293 | 293 |
| 294 SessionDependencies session_deps; | 294 SessionDependencies session_deps; |
| 295 scoped_ptr<SpdyNetworkTransaction> trans( | 295 scoped_ptr<SpdyNetworkTransaction> trans( |
| 296 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 296 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 297 | 297 |
| 298 session_deps.socket_factory.AddSocketDataProvider(data); | 298 session_deps.socket_factory.AddSocketDataProvider(data); |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 scoped_refptr<DelayedSocketData> data( | 1017 scoped_refptr<DelayedSocketData> data( |
| 1018 new DelayedSocketData(1, reads, arraysize(reads), | 1018 new DelayedSocketData(1, reads, arraysize(reads), |
| 1019 writes, arraysize(writes))); | 1019 writes, arraysize(writes))); |
| 1020 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1020 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
| 1021 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 1021 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); |
| 1022 data->Reset(); | 1022 data->Reset(); |
| 1023 | 1023 |
| 1024 EnableCompression(false); | 1024 EnableCompression(false); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 // Test that the LoadLog contains good data for a simple GET request. | 1027 // Test that the NetLog contains good data for a simple GET request. |
| 1028 TEST_F(SpdyNetworkTransactionTest, LoadLog) { | 1028 TEST_F(SpdyNetworkTransactionTest, NetLog) { |
| 1029 MockWrite writes[] = { | 1029 MockWrite writes[] = { |
| 1030 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1030 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| 1031 arraysize(kGetSyn)), | 1031 arraysize(kGetSyn)), |
| 1032 }; | 1032 }; |
| 1033 | 1033 |
| 1034 MockRead reads[] = { | 1034 MockRead reads[] = { |
| 1035 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1035 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
| 1036 arraysize(kGetSynReply)), | 1036 arraysize(kGetSynReply)), |
| 1037 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1037 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1038 arraysize(kGetBodyFrame)), | 1038 arraysize(kGetBodyFrame)), |
| 1039 MockRead(true, 0, 0) // EOF | 1039 MockRead(true, 0, 0) // EOF |
| 1040 }; | 1040 }; |
| 1041 | 1041 |
| 1042 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); | 1042 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); |
| 1043 | 1043 |
| 1044 HttpRequestInfo request; | 1044 HttpRequestInfo request; |
| 1045 request.method = "GET"; | 1045 request.method = "GET"; |
| 1046 request.url = GURL("http://www.google.com/"); | 1046 request.url = GURL("http://www.google.com/"); |
| 1047 request.load_flags = 0; | 1047 request.load_flags = 0; |
| 1048 scoped_refptr<DelayedSocketData> data( | 1048 scoped_refptr<DelayedSocketData> data( |
| 1049 new DelayedSocketData(1, reads, arraysize(reads), | 1049 new DelayedSocketData(1, reads, arraysize(reads), |
| 1050 writes, arraysize(writes))); | 1050 writes, arraysize(writes))); |
| 1051 TransactionHelperResult out = TransactionHelper(request, data.get(), | 1051 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1052 log); | 1052 log.bound()); |
| 1053 EXPECT_EQ(OK, out.rv); | 1053 EXPECT_EQ(OK, out.rv); |
| 1054 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1054 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1055 EXPECT_EQ("hello!", out.response_data); | 1055 EXPECT_EQ("hello!", out.response_data); |
| 1056 | 1056 |
| 1057 // Check that the LoadLog was filled reasonably. | 1057 // Check that the NetLog was filled reasonably. |
| 1058 // This test is intentionally non-specific about the exact ordering of | 1058 // This test is intentionally non-specific about the exact ordering of |
| 1059 // the log; instead we just check to make sure that certain events exist. | 1059 // the log; instead we just check to make sure that certain events exist. |
| 1060 EXPECT_LT(0u, log->entries().size()); | 1060 EXPECT_LT(0u, log.entries().size()); |
| 1061 int pos = 0; | 1061 int pos = 0; |
| 1062 // We know the first event at position 0. | 1062 // We know the first event at position 0. |
| 1063 EXPECT_TRUE(net::LogContainsBeginEvent( | 1063 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 1064 *log, 0, net::LoadLog::TYPE_SPDY_TRANSACTION_INIT_CONNECTION)); | 1064 log.entries(), 0, net::NetLog::TYPE_SPDY_TRANSACTION_INIT_CONNECTION)); |
| 1065 // For the rest of the events, allow additional events in the middle, | 1065 // For the rest of the events, allow additional events in the middle, |
| 1066 // but expect these to be logged in order. | 1066 // but expect these to be logged in order. |
| 1067 pos = net::ExpectLogContainsSomewhere(log, 0, | 1067 pos = net::ExpectLogContainsSomewhere(log.entries(), 0, |
| 1068 net::LoadLog::TYPE_SPDY_TRANSACTION_INIT_CONNECTION, | 1068 net::NetLog::TYPE_SPDY_TRANSACTION_INIT_CONNECTION, |
| 1069 net::LoadLog::PHASE_END); | 1069 net::NetLog::PHASE_END); |
| 1070 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1070 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1071 net::LoadLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, | 1071 net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, |
| 1072 net::LoadLog::PHASE_BEGIN); | 1072 net::NetLog::PHASE_BEGIN); |
| 1073 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1073 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1074 net::LoadLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, | 1074 net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, |
| 1075 net::LoadLog::PHASE_END); | 1075 net::NetLog::PHASE_END); |
| 1076 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1076 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1077 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, | 1077 net::NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, |
| 1078 net::LoadLog::PHASE_BEGIN); | 1078 net::NetLog::PHASE_BEGIN); |
| 1079 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1079 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1080 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, | 1080 net::NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, |
| 1081 net::LoadLog::PHASE_END); | 1081 net::NetLog::PHASE_END); |
| 1082 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1082 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1083 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_BODY, | 1083 net::NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, |
| 1084 net::LoadLog::PHASE_BEGIN); | 1084 net::NetLog::PHASE_BEGIN); |
| 1085 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1085 pos = net::ExpectLogContainsSomewhere(log.entries(), pos + 1, |
| 1086 net::LoadLog::TYPE_SPDY_TRANSACTION_READ_BODY, | 1086 net::NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, |
| 1087 net::LoadLog::PHASE_END); | 1087 net::NetLog::PHASE_END); |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 // Since we buffer the IO from the stream to the renderer, this test verifies | 1090 // Since we buffer the IO from the stream to the renderer, this test verifies |
| 1091 // that when we read out the maximum amount of data (e.g. we received 50 bytes | 1091 // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 1092 // on the network, but issued a Read for only 5 of those bytes) that the data | 1092 // on the network, but issued a Read for only 5 of those bytes) that the data |
| 1093 // flow still works correctly. | 1093 // flow still works correctly. |
| 1094 TEST_F(SpdyNetworkTransactionTest, BufferFull) { | 1094 TEST_F(SpdyNetworkTransactionTest, BufferFull) { |
| 1095 MockWrite writes[] = { | 1095 MockWrite writes[] = { |
| 1096 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1096 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| 1097 arraysize(kGetSyn)), | 1097 arraysize(kGetSyn)), |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 FAIL() << "Unexpected read: " << rv; | 1602 FAIL() << "Unexpected read: " << rv; |
| 1603 } while (rv > 0); | 1603 } while (rv > 0); |
| 1604 | 1604 |
| 1605 // Flush the MessageLoop; this will cause the buffered IO task | 1605 // Flush the MessageLoop; this will cause the buffered IO task |
| 1606 // to run for the final time. | 1606 // to run for the final time. |
| 1607 MessageLoop::current()->RunAllPending(); | 1607 MessageLoop::current()->RunAllPending(); |
| 1608 } | 1608 } |
| 1609 | 1609 |
| 1610 | 1610 |
| 1611 } // namespace net | 1611 } // namespace net |
| OLD | NEW |