| 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 "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 MockRead(true, 0, 0) // EOF | 724 MockRead(true, 0, 0) // EOF |
| 725 }; | 725 }; |
| 726 | 726 |
| 727 HttpRequestInfo request; | 727 HttpRequestInfo request; |
| 728 request.method = "GET"; | 728 request.method = "GET"; |
| 729 request.url = GURL("http://www.google.com/"); | 729 request.url = GURL("http://www.google.com/"); |
| 730 request.load_flags = 0; | 730 request.load_flags = 0; |
| 731 scoped_refptr<DelayedSocketData> data( | 731 scoped_refptr<DelayedSocketData> data( |
| 732 new DelayedSocketData(1, reads, arraysize(reads), | 732 new DelayedSocketData(1, reads, arraysize(reads), |
| 733 writes, arraysize(writes))); | 733 writes, arraysize(writes))); |
| 734 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 734 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 735 BoundNetLog()); |
| 735 EXPECT_EQ(OK, out.rv); | 736 EXPECT_EQ(OK, out.rv); |
| 736 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 737 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 737 EXPECT_EQ("hello!", out.response_data); | 738 EXPECT_EQ("hello!", out.response_data); |
| 738 } | 739 } |
| 739 | 740 |
| 740 // Test that a simple POST works. | 741 // Test that a simple POST works. |
| 741 TEST_F(SpdyNetworkTransactionTest, Post) { | 742 TEST_F(SpdyNetworkTransactionTest, Post) { |
| 742 static const char upload[] = { "hello world" }; | 743 static const char upload[] = { "hello world" }; |
| 743 | 744 |
| 744 // Setup the request | 745 // Setup the request |
| (...skipping 14 matching lines...) Expand all Loading... |
| 759 MockRead(true, reinterpret_cast<const char*>(kPostSynReply), | 760 MockRead(true, reinterpret_cast<const char*>(kPostSynReply), |
| 760 arraysize(kPostSynReply)), | 761 arraysize(kPostSynReply)), |
| 761 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), | 762 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), |
| 762 arraysize(kPostBodyFrame)), | 763 arraysize(kPostBodyFrame)), |
| 763 MockRead(true, 0, 0) // EOF | 764 MockRead(true, 0, 0) // EOF |
| 764 }; | 765 }; |
| 765 | 766 |
| 766 scoped_refptr<DelayedSocketData> data( | 767 scoped_refptr<DelayedSocketData> data( |
| 767 new DelayedSocketData(2, reads, arraysize(reads), | 768 new DelayedSocketData(2, reads, arraysize(reads), |
| 768 writes, arraysize(writes))); | 769 writes, arraysize(writes))); |
| 769 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 770 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 771 BoundNetLog()); |
| 770 EXPECT_EQ(OK, out.rv); | 772 EXPECT_EQ(OK, out.rv); |
| 771 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 773 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 772 EXPECT_EQ("hello!", out.response_data); | 774 EXPECT_EQ("hello!", out.response_data); |
| 773 } | 775 } |
| 774 | 776 |
| 775 // Test that a simple POST works. | 777 // Test that a simple POST works. |
| 776 TEST_F(SpdyNetworkTransactionTest, EmptyPost) { | 778 TEST_F(SpdyNetworkTransactionTest, EmptyPost) { |
| 777 static const unsigned char kEmptyPostSyn[] = { | 779 static const unsigned char kEmptyPostSyn[] = { |
| 778 0x80, 0x01, 0x00, 0x01, // header | 780 0x80, 0x01, 0x00, 0x01, // header |
| 779 0x01, 0x00, 0x00, 0x4a, // flags, len | 781 0x01, 0x00, 0x00, 0x4a, // flags, len |
| (...skipping 27 matching lines...) Expand all Loading... |
| 807 arraysize(kPostSynReply)), | 809 arraysize(kPostSynReply)), |
| 808 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), | 810 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), |
| 809 arraysize(kPostBodyFrame)), | 811 arraysize(kPostBodyFrame)), |
| 810 MockRead(true, 0, 0) // EOF | 812 MockRead(true, 0, 0) // EOF |
| 811 }; | 813 }; |
| 812 | 814 |
| 813 scoped_refptr<DelayedSocketData> data( | 815 scoped_refptr<DelayedSocketData> data( |
| 814 new DelayedSocketData(1, reads, arraysize(reads), | 816 new DelayedSocketData(1, reads, arraysize(reads), |
| 815 writes, arraysize(writes))); | 817 writes, arraysize(writes))); |
| 816 | 818 |
| 817 TransactionHelperResult out = TransactionHelper(request, data, NULL); | 819 TransactionHelperResult out = TransactionHelper(request, data, BoundNetLog()); |
| 818 EXPECT_EQ(OK, out.rv); | 820 EXPECT_EQ(OK, out.rv); |
| 819 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 821 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 820 EXPECT_EQ("hello!", out.response_data); | 822 EXPECT_EQ("hello!", out.response_data); |
| 821 } | 823 } |
| 822 | 824 |
| 823 // Test that the transaction doesn't crash when we don't have a reply. | 825 // Test that the transaction doesn't crash when we don't have a reply. |
| 824 TEST_F(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { | 826 TEST_F(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { |
| 825 MockRead reads[] = { | 827 MockRead reads[] = { |
| 826 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), | 828 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), |
| 827 arraysize(kPostBodyFrame)), | 829 arraysize(kPostBodyFrame)), |
| 828 MockRead(true, 0, 0) // EOF | 830 MockRead(true, 0, 0) // EOF |
| 829 }; | 831 }; |
| 830 | 832 |
| 831 HttpRequestInfo request; | 833 HttpRequestInfo request; |
| 832 request.method = "GET"; | 834 request.method = "GET"; |
| 833 request.url = GURL("http://www.google.com/"); | 835 request.url = GURL("http://www.google.com/"); |
| 834 request.load_flags = 0; | 836 request.load_flags = 0; |
| 835 scoped_refptr<DelayedSocketData> data( | 837 scoped_refptr<DelayedSocketData> data( |
| 836 new DelayedSocketData(1, reads, arraysize(reads), NULL, 0)); | 838 new DelayedSocketData(1, reads, arraysize(reads), NULL, 0)); |
| 837 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 839 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 840 BoundNetLog()); |
| 838 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 841 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); |
| 839 } | 842 } |
| 840 | 843 |
| 841 TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { | 844 TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { |
| 842 MockWrite writes[] = { | 845 MockWrite writes[] = { |
| 843 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 846 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| 844 arraysize(kGetSyn)), | 847 arraysize(kGetSyn)), |
| 845 MockRead(true, 0, 0) // EOF | 848 MockRead(true, 0, 0) // EOF |
| 846 }; | 849 }; |
| 847 | 850 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 866 SessionDependencies session_deps; | 869 SessionDependencies session_deps; |
| 867 scoped_ptr<SpdyNetworkTransaction> trans( | 870 scoped_ptr<SpdyNetworkTransaction> trans( |
| 868 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 871 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 869 | 872 |
| 870 StaticSocketDataProvider data(reads, arraysize(reads), | 873 StaticSocketDataProvider data(reads, arraysize(reads), |
| 871 writes, arraysize(writes)); | 874 writes, arraysize(writes)); |
| 872 session_deps.socket_factory.AddSocketDataProvider(&data); | 875 session_deps.socket_factory.AddSocketDataProvider(&data); |
| 873 | 876 |
| 874 TestCompletionCallback callback; | 877 TestCompletionCallback callback; |
| 875 | 878 |
| 876 int rv = trans->Start(&request, &callback, NULL); | 879 int rv = trans->Start(&request, &callback, BoundNetLog()); |
| 877 EXPECT_EQ(ERR_IO_PENDING, rv); | 880 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 878 trans.reset(); // Cancel the transaction. | 881 trans.reset(); // Cancel the transaction. |
| 879 | 882 |
| 880 // Flush the MessageLoop while the SessionDependencies (in particular, the | 883 // Flush the MessageLoop while the SessionDependencies (in particular, the |
| 881 // MockClientSocketFactory) are still alive. | 884 // MockClientSocketFactory) are still alive. |
| 882 MessageLoop::current()->RunAllPending(); | 885 MessageLoop::current()->RunAllPending(); |
| 883 } | 886 } |
| 884 | 887 |
| 885 // Verify that various SynReply headers parse correctly through the | 888 // Verify that various SynReply headers parse correctly through the |
| 886 // HTTP layer. | 889 // HTTP layer. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 MockRead(true, 0, 0) // EOF | 979 MockRead(true, 0, 0) // EOF |
| 977 }; | 980 }; |
| 978 | 981 |
| 979 HttpRequestInfo request; | 982 HttpRequestInfo request; |
| 980 request.method = "GET"; | 983 request.method = "GET"; |
| 981 request.url = GURL("http://www.google.com/"); | 984 request.url = GURL("http://www.google.com/"); |
| 982 request.load_flags = 0; | 985 request.load_flags = 0; |
| 983 scoped_refptr<DelayedSocketData> data( | 986 scoped_refptr<DelayedSocketData> data( |
| 984 new DelayedSocketData(1, reads, arraysize(reads), | 987 new DelayedSocketData(1, reads, arraysize(reads), |
| 985 writes, arraysize(writes))); | 988 writes, arraysize(writes))); |
| 986 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 989 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 990 BoundNetLog()); |
| 987 EXPECT_EQ(OK, out.rv); | 991 EXPECT_EQ(OK, out.rv); |
| 988 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 992 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 989 EXPECT_EQ("hello!", out.response_data); | 993 EXPECT_EQ("hello!", out.response_data); |
| 990 | 994 |
| 991 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; | 995 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 992 EXPECT_TRUE(headers.get() != NULL); | 996 EXPECT_TRUE(headers.get() != NULL); |
| 993 void* iter = NULL; | 997 void* iter = NULL; |
| 994 std::string name, value, lines; | 998 std::string name, value, lines; |
| 995 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 999 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 996 lines.append(name); | 1000 lines.append(name); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 | 1133 |
| 1130 for (int ct = 0; ct < header_count; ct++) { | 1134 for (int ct = 0; ct < header_count; ct++) { |
| 1131 const char* header_key = test_cases[i].extra_headers[0][ct * 2]; | 1135 const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 1132 const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; | 1136 const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 1133 request.extra_headers.SetHeader(header_key, header_value); | 1137 request.extra_headers.SetHeader(header_key, header_value); |
| 1134 } | 1138 } |
| 1135 | 1139 |
| 1136 scoped_refptr<DelayedSocketData> data( | 1140 scoped_refptr<DelayedSocketData> data( |
| 1137 new DelayedSocketData(1, reads, arraysize(reads), | 1141 new DelayedSocketData(1, reads, arraysize(reads), |
| 1138 writes, arraysize(writes))); | 1142 writes, arraysize(writes))); |
| 1139 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1143 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1144 BoundNetLog()); |
| 1140 EXPECT_EQ(OK, out.rv) << i; | 1145 EXPECT_EQ(OK, out.rv) << i; |
| 1141 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; | 1146 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; |
| 1142 EXPECT_EQ("hello!", out.response_data) << i; | 1147 EXPECT_EQ("hello!", out.response_data) << i; |
| 1143 | 1148 |
| 1144 // Test the response information. | 1149 // Test the response information. |
| 1145 EXPECT_TRUE(out.response_info.response_time > | 1150 EXPECT_TRUE(out.response_info.response_time > |
| 1146 out.response_info.request_time) << i; | 1151 out.response_info.request_time) << i; |
| 1147 base::TimeDelta test_delay = out.response_info.response_time - | 1152 base::TimeDelta test_delay = out.response_info.response_time - |
| 1148 out.response_info.request_time; | 1153 out.response_info.request_time; |
| 1149 base::TimeDelta min_expected_delay; | 1154 base::TimeDelta min_expected_delay; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 MockRead(true, 0, 0) // EOF | 1231 MockRead(true, 0, 0) // EOF |
| 1227 }; | 1232 }; |
| 1228 | 1233 |
| 1229 HttpRequestInfo request; | 1234 HttpRequestInfo request; |
| 1230 request.method = "GET"; | 1235 request.method = "GET"; |
| 1231 request.url = GURL("http://www.google.com/"); | 1236 request.url = GURL("http://www.google.com/"); |
| 1232 request.load_flags = 0; | 1237 request.load_flags = 0; |
| 1233 scoped_refptr<DelayedSocketData> data( | 1238 scoped_refptr<DelayedSocketData> data( |
| 1234 new DelayedSocketData(1, reads, arraysize(reads), | 1239 new DelayedSocketData(1, reads, arraysize(reads), |
| 1235 writes, arraysize(writes))); | 1240 writes, arraysize(writes))); |
| 1236 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1241 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1242 BoundNetLog()); |
| 1237 EXPECT_EQ(ERR_INVALID_RESPONSE, out.rv); | 1243 EXPECT_EQ(ERR_INVALID_RESPONSE, out.rv); |
| 1238 } | 1244 } |
| 1239 } | 1245 } |
| 1240 | 1246 |
| 1241 // Verify that we don't crash on some corrupt frames. | 1247 // Verify that we don't crash on some corrupt frames. |
| 1242 TEST_F(SpdyNetworkTransactionTest, CorruptFrameSessionError) { | 1248 TEST_F(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
| 1243 static const unsigned char kSynReplyMassiveLength[] = { | 1249 static const unsigned char kSynReplyMassiveLength[] = { |
| 1244 0x80, 0x01, 0x00, 0x02, | 1250 0x80, 0x01, 0x00, 0x02, |
| 1245 0x0f, 0x11, 0x11, 0x26, // This is the length field with a big number | 1251 0x0f, 0x11, 0x11, 0x26, // This is the length field with a big number |
| 1246 0x00, 0x00, 0x00, 0x01, | 1252 0x00, 0x00, 0x00, 0x01, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1273 MockRead(true, 0, 0) // EOF | 1279 MockRead(true, 0, 0) // EOF |
| 1274 }; | 1280 }; |
| 1275 | 1281 |
| 1276 HttpRequestInfo request; | 1282 HttpRequestInfo request; |
| 1277 request.method = "GET"; | 1283 request.method = "GET"; |
| 1278 request.url = GURL("http://www.google.com/"); | 1284 request.url = GURL("http://www.google.com/"); |
| 1279 request.load_flags = 0; | 1285 request.load_flags = 0; |
| 1280 scoped_refptr<DelayedSocketData> data( | 1286 scoped_refptr<DelayedSocketData> data( |
| 1281 new DelayedSocketData(1, reads, arraysize(reads), | 1287 new DelayedSocketData(1, reads, arraysize(reads), |
| 1282 writes, arraysize(writes))); | 1288 writes, arraysize(writes))); |
| 1283 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1289 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1290 BoundNetLog()); |
| 1284 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 1291 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 1285 } | 1292 } |
| 1286 } | 1293 } |
| 1287 | 1294 |
| 1288 // Server push: | 1295 // Server push: |
| 1289 // ------------ | 1296 // ------------ |
| 1290 // Client: Send the original SYN request. | 1297 // Client: Send the original SYN request. |
| 1291 // Server: Receive the SYN request. | 1298 // Server: Receive the SYN request. |
| 1292 // Server: Send a SYN reply, with X-Associated-Content and URL(s). | 1299 // Server: Send a SYN reply, with X-Associated-Content and URL(s). |
| 1293 // Server: For each URL, send a SYN_STREAM with the URL and a stream ID, | 1300 // Server: For each URL, send a SYN_STREAM with the URL and a stream ID, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 HttpRequestInfo request; | 1351 HttpRequestInfo request; |
| 1345 request.method = "GET"; | 1352 request.method = "GET"; |
| 1346 request.url = url; | 1353 request.url = url; |
| 1347 request.load_flags = 0; | 1354 request.load_flags = 0; |
| 1348 TestCompletionCallback callback; | 1355 TestCompletionCallback callback; |
| 1349 | 1356 |
| 1350 // Allows the STOP_LOOP flag to work. | 1357 // Allows the STOP_LOOP flag to work. |
| 1351 data->SetCompletionCallback(&callback); | 1358 data->SetCompletionCallback(&callback); |
| 1352 // Sends a request. In pass 1, this goes on the wire; in pass 2, it is | 1359 // Sends a request. In pass 1, this goes on the wire; in pass 2, it is |
| 1353 // preempted by the push data. | 1360 // preempted by the push data. |
| 1354 int rv = trans.Start(&request, &callback, NULL); | 1361 int rv = trans.Start(&request, &callback, BoundNetLog()); |
| 1355 EXPECT_EQ(ERR_IO_PENDING, rv); | 1362 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1356 | 1363 |
| 1357 // In the case where we are pushing beforehand, complete the next read now. | 1364 // In the case where we are pushing beforehand, complete the next read now. |
| 1358 if ((pass == 2) && (test_type == PUSH_AFTER_REQUEST)) { | 1365 if ((pass == 2) && (test_type == PUSH_AFTER_REQUEST)) { |
| 1359 data->CompleteRead(); | 1366 data->CompleteRead(); |
| 1360 } | 1367 } |
| 1361 | 1368 |
| 1362 // Process messages until either a FIN or a STOP_LOOP is encountered. | 1369 // Process messages until either a FIN or a STOP_LOOP is encountered. |
| 1363 rv = callback.WaitForResult(); | 1370 rv = callback.WaitForResult(); |
| 1364 if ((pass == 2) && (test_type == PUSH_DURING_REQUEST)) { | 1371 if ((pass == 2) && (test_type == PUSH_DURING_REQUEST)) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 MockRead(true, 0, 0) // EOF | 1625 MockRead(true, 0, 0) // EOF |
| 1619 }; | 1626 }; |
| 1620 | 1627 |
| 1621 HttpRequestInfo request; | 1628 HttpRequestInfo request; |
| 1622 request.method = "GET"; | 1629 request.method = "GET"; |
| 1623 request.url = GURL("http://www.google.com/"); | 1630 request.url = GURL("http://www.google.com/"); |
| 1624 request.load_flags = 0; | 1631 request.load_flags = 0; |
| 1625 scoped_refptr<DelayedSocketData> data( | 1632 scoped_refptr<DelayedSocketData> data( |
| 1626 new DelayedSocketData(2, reads, arraysize(reads), | 1633 new DelayedSocketData(2, reads, arraysize(reads), |
| 1627 writes, arraysize(writes))); | 1634 writes, arraysize(writes))); |
| 1628 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1635 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1636 BoundNetLog()); |
| 1629 EXPECT_EQ(ERR_FAILED, out.rv); | 1637 EXPECT_EQ(ERR_FAILED, out.rv); |
| 1630 data->Reset(); | 1638 data->Reset(); |
| 1631 } | 1639 } |
| 1632 | 1640 |
| 1633 // Test that partial writes work. | 1641 // Test that partial writes work. |
| 1634 TEST_F(SpdyNetworkTransactionTest, PartialWrite) { | 1642 TEST_F(SpdyNetworkTransactionTest, PartialWrite) { |
| 1635 // Chop the SYN_STREAM frame into 5 chunks. | 1643 // Chop the SYN_STREAM frame into 5 chunks. |
| 1636 const int kChunks = 5; | 1644 const int kChunks = 5; |
| 1637 scoped_array<MockWrite> writes(ChopFrame( | 1645 scoped_array<MockWrite> writes(ChopFrame( |
| 1638 reinterpret_cast<const char*>(kGetSyn), arraysize(kGetSyn), kChunks)); | 1646 reinterpret_cast<const char*>(kGetSyn), arraysize(kGetSyn), kChunks)); |
| 1639 | 1647 |
| 1640 MockRead reads[] = { | 1648 MockRead reads[] = { |
| 1641 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1649 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
| 1642 arraysize(kGetSynReply)), | 1650 arraysize(kGetSynReply)), |
| 1643 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1651 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
| 1644 arraysize(kGetBodyFrame)), | 1652 arraysize(kGetBodyFrame)), |
| 1645 MockRead(true, 0, 0) // EOF | 1653 MockRead(true, 0, 0) // EOF |
| 1646 }; | 1654 }; |
| 1647 | 1655 |
| 1648 HttpRequestInfo request; | 1656 HttpRequestInfo request; |
| 1649 request.method = "GET"; | 1657 request.method = "GET"; |
| 1650 request.url = GURL("http://www.google.com/"); | 1658 request.url = GURL("http://www.google.com/"); |
| 1651 request.load_flags = 0; | 1659 request.load_flags = 0; |
| 1652 scoped_refptr<DelayedSocketData> data( | 1660 scoped_refptr<DelayedSocketData> data( |
| 1653 new DelayedSocketData(kChunks, reads, arraysize(reads), | 1661 new DelayedSocketData(kChunks, reads, arraysize(reads), |
| 1654 writes.get(), kChunks)); | 1662 writes.get(), kChunks)); |
| 1655 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1663 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1664 BoundNetLog()); |
| 1656 EXPECT_EQ(OK, out.rv); | 1665 EXPECT_EQ(OK, out.rv); |
| 1657 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1666 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1658 EXPECT_EQ("hello!", out.response_data); | 1667 EXPECT_EQ("hello!", out.response_data); |
| 1659 } | 1668 } |
| 1660 | 1669 |
| 1661 TEST_F(SpdyNetworkTransactionTest, ConnectFailure) { | 1670 TEST_F(SpdyNetworkTransactionTest, ConnectFailure) { |
| 1662 MockConnect connects[] = { | 1671 MockConnect connects[] = { |
| 1663 MockConnect(true, ERR_NAME_NOT_RESOLVED), | 1672 MockConnect(true, ERR_NAME_NOT_RESOLVED), |
| 1664 MockConnect(false, ERR_NAME_NOT_RESOLVED), | 1673 MockConnect(false, ERR_NAME_NOT_RESOLVED), |
| 1665 MockConnect(true, ERR_INTERNET_DISCONNECTED), | 1674 MockConnect(true, ERR_INTERNET_DISCONNECTED), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1681 MockRead(true, 0, 0) // EOF | 1690 MockRead(true, 0, 0) // EOF |
| 1682 }; | 1691 }; |
| 1683 | 1692 |
| 1684 HttpRequestInfo request; | 1693 HttpRequestInfo request; |
| 1685 request.method = "GET"; | 1694 request.method = "GET"; |
| 1686 request.url = GURL("http://www.google.com/"); | 1695 request.url = GURL("http://www.google.com/"); |
| 1687 request.load_flags = 0; | 1696 request.load_flags = 0; |
| 1688 scoped_refptr<DelayedSocketData> data( | 1697 scoped_refptr<DelayedSocketData> data( |
| 1689 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), | 1698 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), |
| 1690 writes, arraysize(writes))); | 1699 writes, arraysize(writes))); |
| 1691 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1700 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1701 BoundNetLog()); |
| 1692 EXPECT_EQ(connects[index].result, out.rv); | 1702 EXPECT_EQ(connects[index].result, out.rv); |
| 1693 } | 1703 } |
| 1694 } | 1704 } |
| 1695 | 1705 |
| 1696 // In this test, we enable compression, but get a uncompressed SynReply from | 1706 // In this test, we enable compression, but get a uncompressed SynReply from |
| 1697 // the server. Verify that teardown is all clean. | 1707 // the server. Verify that teardown is all clean. |
| 1698 TEST_F(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { | 1708 TEST_F(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
| 1699 MockWrite writes[] = { | 1709 MockWrite writes[] = { |
| 1700 MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), | 1710 MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), |
| 1701 arraysize(kGetSynCompressed)), | 1711 arraysize(kGetSynCompressed)), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1713 // For this test, we turn on the normal compression. | 1723 // For this test, we turn on the normal compression. |
| 1714 EnableCompression(true); | 1724 EnableCompression(true); |
| 1715 | 1725 |
| 1716 HttpRequestInfo request; | 1726 HttpRequestInfo request; |
| 1717 request.method = "GET"; | 1727 request.method = "GET"; |
| 1718 request.url = GURL("http://www.google.com/"); | 1728 request.url = GURL("http://www.google.com/"); |
| 1719 request.load_flags = 0; | 1729 request.load_flags = 0; |
| 1720 scoped_refptr<DelayedSocketData> data( | 1730 scoped_refptr<DelayedSocketData> data( |
| 1721 new DelayedSocketData(1, reads, arraysize(reads), | 1731 new DelayedSocketData(1, reads, arraysize(reads), |
| 1722 writes, arraysize(writes))); | 1732 writes, arraysize(writes))); |
| 1723 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1733 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 1734 BoundNetLog()); |
| 1724 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 1735 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); |
| 1725 data->Reset(); | 1736 data->Reset(); |
| 1726 | 1737 |
| 1727 EnableCompression(false); | 1738 EnableCompression(false); |
| 1728 } | 1739 } |
| 1729 | 1740 |
| 1730 // Test that the NetLog contains good data for a simple GET request. | 1741 // Test that the NetLog contains good data for a simple GET request. |
| 1731 TEST_F(SpdyNetworkTransactionTest, NetLog) { | 1742 TEST_F(SpdyNetworkTransactionTest, NetLog) { |
| 1732 MockWrite writes[] = { | 1743 MockWrite writes[] = { |
| 1733 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1744 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 SpdySession::SetSSLMode(false); | 1855 SpdySession::SetSSLMode(false); |
| 1845 | 1856 |
| 1846 SessionDependencies session_deps; | 1857 SessionDependencies session_deps; |
| 1847 scoped_ptr<SpdyNetworkTransaction> trans( | 1858 scoped_ptr<SpdyNetworkTransaction> trans( |
| 1848 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 1859 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 1849 | 1860 |
| 1850 session_deps.socket_factory.AddSocketDataProvider(data); | 1861 session_deps.socket_factory.AddSocketDataProvider(data); |
| 1851 | 1862 |
| 1852 TestCompletionCallback callback; | 1863 TestCompletionCallback callback; |
| 1853 | 1864 |
| 1854 int rv = trans->Start(&request, &callback, NULL); | 1865 int rv = trans->Start(&request, &callback, BoundNetLog()); |
| 1855 EXPECT_EQ(ERR_IO_PENDING, rv); | 1866 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1856 | 1867 |
| 1857 out.rv = callback.WaitForResult(); | 1868 out.rv = callback.WaitForResult(); |
| 1858 EXPECT_EQ(out.rv, OK); | 1869 EXPECT_EQ(out.rv, OK); |
| 1859 | 1870 |
| 1860 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1871 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1861 EXPECT_TRUE(response->headers != NULL); | 1872 EXPECT_TRUE(response->headers != NULL); |
| 1862 EXPECT_TRUE(response->was_fetched_via_spdy); | 1873 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 1863 out.status_line = response->headers->GetStatusLine(); | 1874 out.status_line = response->headers->GetStatusLine(); |
| 1864 out.response_info = *response; // Make a copy so we can verify. | 1875 out.response_info = *response; // Make a copy so we can verify. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1950 SpdySession::SetSSLMode(false); | 1961 SpdySession::SetSSLMode(false); |
| 1951 | 1962 |
| 1952 SessionDependencies session_deps; | 1963 SessionDependencies session_deps; |
| 1953 scoped_ptr<SpdyNetworkTransaction> trans( | 1964 scoped_ptr<SpdyNetworkTransaction> trans( |
| 1954 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 1965 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 1955 | 1966 |
| 1956 session_deps.socket_factory.AddSocketDataProvider(data); | 1967 session_deps.socket_factory.AddSocketDataProvider(data); |
| 1957 | 1968 |
| 1958 TestCompletionCallback callback; | 1969 TestCompletionCallback callback; |
| 1959 | 1970 |
| 1960 int rv = trans->Start(&request, &callback, NULL); | 1971 int rv = trans->Start(&request, &callback, BoundNetLog()); |
| 1961 EXPECT_EQ(ERR_IO_PENDING, rv); | 1972 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1962 | 1973 |
| 1963 out.rv = callback.WaitForResult(); | 1974 out.rv = callback.WaitForResult(); |
| 1964 EXPECT_EQ(out.rv, OK); | 1975 EXPECT_EQ(out.rv, OK); |
| 1965 | 1976 |
| 1966 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1977 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1967 EXPECT_TRUE(response->headers != NULL); | 1978 EXPECT_TRUE(response->headers != NULL); |
| 1968 EXPECT_TRUE(response->was_fetched_via_spdy); | 1979 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 1969 out.status_line = response->headers->GetStatusLine(); | 1980 out.status_line = response->headers->GetStatusLine(); |
| 1970 out.response_info = *response; // Make a copy so we can verify. | 1981 out.response_info = *response; // Make a copy so we can verify. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 SpdySession::SetSSLMode(false); | 2078 SpdySession::SetSSLMode(false); |
| 2068 | 2079 |
| 2069 SessionDependencies session_deps; | 2080 SessionDependencies session_deps; |
| 2070 scoped_ptr<SpdyNetworkTransaction> trans( | 2081 scoped_ptr<SpdyNetworkTransaction> trans( |
| 2071 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 2082 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 2072 | 2083 |
| 2073 session_deps.socket_factory.AddSocketDataProvider(data); | 2084 session_deps.socket_factory.AddSocketDataProvider(data); |
| 2074 | 2085 |
| 2075 TestCompletionCallback callback; | 2086 TestCompletionCallback callback; |
| 2076 | 2087 |
| 2077 int rv = trans->Start(&request, &callback, NULL); | 2088 int rv = trans->Start(&request, &callback, BoundNetLog()); |
| 2078 EXPECT_EQ(ERR_IO_PENDING, rv); | 2089 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2079 | 2090 |
| 2080 out.rv = callback.WaitForResult(); | 2091 out.rv = callback.WaitForResult(); |
| 2081 EXPECT_EQ(out.rv, OK); | 2092 EXPECT_EQ(out.rv, OK); |
| 2082 | 2093 |
| 2083 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2094 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2084 EXPECT_TRUE(response->headers != NULL); | 2095 EXPECT_TRUE(response->headers != NULL); |
| 2085 EXPECT_TRUE(response->was_fetched_via_spdy); | 2096 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2086 out.status_line = response->headers->GetStatusLine(); | 2097 out.status_line = response->headers->GetStatusLine(); |
| 2087 out.response_info = *response; // Make a copy so we can verify. | 2098 out.response_info = *response; // Make a copy so we can verify. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 SpdySession::SetSSLMode(false); | 2183 SpdySession::SetSSLMode(false); |
| 2173 | 2184 |
| 2174 SessionDependencies session_deps; | 2185 SessionDependencies session_deps; |
| 2175 scoped_ptr<SpdyNetworkTransaction> trans( | 2186 scoped_ptr<SpdyNetworkTransaction> trans( |
| 2176 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 2187 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 2177 | 2188 |
| 2178 session_deps.socket_factory.AddSocketDataProvider(data); | 2189 session_deps.socket_factory.AddSocketDataProvider(data); |
| 2179 | 2190 |
| 2180 TestCompletionCallback callback; | 2191 TestCompletionCallback callback; |
| 2181 | 2192 |
| 2182 int rv = trans->Start(&request, &callback, NULL); | 2193 int rv = trans->Start(&request, &callback, BoundNetLog()); |
| 2183 EXPECT_EQ(ERR_IO_PENDING, rv); | 2194 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2184 | 2195 |
| 2185 out.rv = callback.WaitForResult(); | 2196 out.rv = callback.WaitForResult(); |
| 2186 EXPECT_EQ(out.rv, OK); | 2197 EXPECT_EQ(out.rv, OK); |
| 2187 | 2198 |
| 2188 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2199 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2189 EXPECT_TRUE(response->headers != NULL); | 2200 EXPECT_TRUE(response->headers != NULL); |
| 2190 EXPECT_TRUE(response->was_fetched_via_spdy); | 2201 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2191 out.status_line = response->headers->GetStatusLine(); | 2202 out.status_line = response->headers->GetStatusLine(); |
| 2192 out.response_info = *response; // Make a copy so we can verify. | 2203 out.response_info = *response; // Make a copy so we can verify. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2267 SpdySession::SetSSLMode(false); | 2278 SpdySession::SetSSLMode(false); |
| 2268 | 2279 |
| 2269 SessionDependencies session_deps; | 2280 SessionDependencies session_deps; |
| 2270 scoped_ptr<SpdyNetworkTransaction> trans( | 2281 scoped_ptr<SpdyNetworkTransaction> trans( |
| 2271 new SpdyNetworkTransaction(CreateSession(&session_deps))); | 2282 new SpdyNetworkTransaction(CreateSession(&session_deps))); |
| 2272 | 2283 |
| 2273 session_deps.socket_factory.AddSocketDataProvider(data); | 2284 session_deps.socket_factory.AddSocketDataProvider(data); |
| 2274 | 2285 |
| 2275 TestCompletionCallback callback; | 2286 TestCompletionCallback callback; |
| 2276 | 2287 |
| 2277 int rv = trans->Start(&request, &callback, NULL); | 2288 int rv = trans->Start(&request, &callback, BoundNetLog()); |
| 2278 EXPECT_EQ(ERR_IO_PENDING, rv); | 2289 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2279 | 2290 |
| 2280 out.rv = callback.WaitForResult(); | 2291 out.rv = callback.WaitForResult(); |
| 2281 EXPECT_EQ(out.rv, OK); | 2292 EXPECT_EQ(out.rv, OK); |
| 2282 | 2293 |
| 2283 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2294 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2284 EXPECT_TRUE(response->headers != NULL); | 2295 EXPECT_TRUE(response->headers != NULL); |
| 2285 EXPECT_TRUE(response->was_fetched_via_spdy); | 2296 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2286 out.status_line = response->headers->GetStatusLine(); | 2297 out.status_line = response->headers->GetStatusLine(); |
| 2287 out.response_info = *response; // Make a copy so we can verify. | 2298 out.response_info = *response; // Make a copy so we can verify. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2390 HttpRequestInfo request; | 2401 HttpRequestInfo request; |
| 2391 request.method = "GET"; | 2402 request.method = "GET"; |
| 2392 request.url = GURL("http://www.google.com/"); | 2403 request.url = GURL("http://www.google.com/"); |
| 2393 request.load_flags = 0; | 2404 request.load_flags = 0; |
| 2394 | 2405 |
| 2395 scoped_refptr<DelayedSocketData> data( | 2406 scoped_refptr<DelayedSocketData> data( |
| 2396 new DelayedSocketData(1, reads, arraysize(reads), | 2407 new DelayedSocketData(1, reads, arraysize(reads), |
| 2397 writes, arraysize(writes))); | 2408 writes, arraysize(writes))); |
| 2398 TransactionHelperResult out = TransactionHelperWithSession(request, | 2409 TransactionHelperResult out = TransactionHelperWithSession(request, |
| 2399 data.get(), | 2410 data.get(), |
| 2400 NULL, | 2411 BoundNetLog(), |
| 2401 &session_deps, | 2412 &session_deps, |
| 2402 session.get()); | 2413 session.get()); |
| 2403 EXPECT_EQ(OK, out.rv); | 2414 EXPECT_EQ(OK, out.rv); |
| 2404 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 2415 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2405 EXPECT_EQ("hello!", out.response_data); | 2416 EXPECT_EQ("hello!", out.response_data); |
| 2406 | 2417 |
| 2407 { | 2418 { |
| 2408 // Verify we had two persisted settings. | 2419 // Verify we had two persisted settings. |
| 2409 spdy::SpdySettings saved_settings = | 2420 spdy::SpdySettings saved_settings = |
| 2410 session->spdy_settings().Get(host_port_pair); | 2421 session->spdy_settings().Get(host_port_pair); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2507 HttpRequestInfo request; | 2518 HttpRequestInfo request; |
| 2508 request.method = "GET"; | 2519 request.method = "GET"; |
| 2509 request.url = GURL("http://www.google.com/"); | 2520 request.url = GURL("http://www.google.com/"); |
| 2510 request.load_flags = 0; | 2521 request.load_flags = 0; |
| 2511 | 2522 |
| 2512 scoped_refptr<DelayedSocketData> data( | 2523 scoped_refptr<DelayedSocketData> data( |
| 2513 new DelayedSocketData(2, reads, arraysize(reads), | 2524 new DelayedSocketData(2, reads, arraysize(reads), |
| 2514 writes, arraysize(writes))); | 2525 writes, arraysize(writes))); |
| 2515 TransactionHelperResult out = TransactionHelperWithSession(request, | 2526 TransactionHelperResult out = TransactionHelperWithSession(request, |
| 2516 data.get(), | 2527 data.get(), |
| 2517 NULL, | 2528 BoundNetLog(), |
| 2518 &session_deps, | 2529 &session_deps, |
| 2519 session.get()); | 2530 session.get()); |
| 2520 EXPECT_EQ(OK, out.rv); | 2531 EXPECT_EQ(OK, out.rv); |
| 2521 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 2532 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2522 EXPECT_EQ("hello!", out.response_data); | 2533 EXPECT_EQ("hello!", out.response_data); |
| 2523 | 2534 |
| 2524 { | 2535 { |
| 2525 // Verify we had two persisted settings. | 2536 // Verify we had two persisted settings. |
| 2526 spdy::SpdySettings saved_settings = | 2537 spdy::SpdySettings saved_settings = |
| 2527 session->spdy_settings().Get(host_port_pair); | 2538 session->spdy_settings().Get(host_port_pair); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2555 MockRead(true, 0, 0) // EOF | 2566 MockRead(true, 0, 0) // EOF |
| 2556 }; | 2567 }; |
| 2557 | 2568 |
| 2558 HttpRequestInfo request; | 2569 HttpRequestInfo request; |
| 2559 request.method = "GET"; | 2570 request.method = "GET"; |
| 2560 request.url = GURL("http://www.google.com/"); | 2571 request.url = GURL("http://www.google.com/"); |
| 2561 request.load_flags = 0; | 2572 request.load_flags = 0; |
| 2562 scoped_refptr<DelayedSocketData> data( | 2573 scoped_refptr<DelayedSocketData> data( |
| 2563 new DelayedSocketData(1, reads, arraysize(reads), | 2574 new DelayedSocketData(1, reads, arraysize(reads), |
| 2564 writes, arraysize(writes))); | 2575 writes, arraysize(writes))); |
| 2565 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 2576 TransactionHelperResult out = TransactionHelper(request, data.get(), |
| 2577 BoundNetLog()); |
| 2566 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 2578 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 2567 } | 2579 } |
| 2568 | 2580 |
| 2569 } // namespace net | 2581 } // namespace net |
| OLD | NEW |