| 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 5416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5427 | 5427 |
| 5428 scoped_ptr<SpdyFrame> | 5428 scoped_ptr<SpdyFrame> |
| 5429 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); | 5429 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5430 MockRead reads[] = { | 5430 MockRead reads[] = { |
| 5431 CreateMockRead(*stream1_reply, 1), | 5431 CreateMockRead(*stream1_reply, 1), |
| 5432 CreateMockRead(*stream2_syn, 2), | 5432 CreateMockRead(*stream2_syn, 2), |
| 5433 CreateMockRead(*stream1_body, 3), | 5433 CreateMockRead(*stream1_body, 3), |
| 5434 CreateMockRead(*stream2_headers, 4), | 5434 CreateMockRead(*stream2_headers, 4), |
| 5435 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), | 5435 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), |
| 5436 arraysize(kPushBodyFrame), 5), | 5436 arraysize(kPushBodyFrame), 5), |
| 5437 MockRead(ASYNC, 0, 5), // EOF | 5437 MockRead(ASYNC, 0, 6), // EOF |
| 5438 }; | 5438 }; |
| 5439 | 5439 |
| 5440 HttpResponseInfo response; | 5440 HttpResponseInfo response; |
| 5441 HttpResponseInfo response2; | 5441 HttpResponseInfo response2; |
| 5442 std::string expected_push_result("pushed"); | 5442 std::string expected_push_result("pushed"); |
| 5443 DeterministicSocketData data(reads, arraysize(reads), | 5443 DeterministicSocketData data(reads, arraysize(reads), |
| 5444 writes, arraysize(writes)); | 5444 writes, arraysize(writes)); |
| 5445 | 5445 |
| 5446 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 5446 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 5447 BoundNetLog(), GetParam(), NULL); | 5447 BoundNetLog(), GetParam(), NULL); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 5475 data.RunFor(3); | 5475 data.RunFor(3); |
| 5476 MessageLoop::current()->RunAllPending(); | 5476 MessageLoop::current()->RunAllPending(); |
| 5477 | 5477 |
| 5478 // Read the server push body. | 5478 // Read the server push body. |
| 5479 std::string result2; | 5479 std::string result2; |
| 5480 ReadResult(trans2.get(), &data, &result2); | 5480 ReadResult(trans2.get(), &data, &result2); |
| 5481 // Read the response body. | 5481 // Read the response body. |
| 5482 std::string result; | 5482 std::string result; |
| 5483 ReadResult(trans, &data, &result); | 5483 ReadResult(trans, &data, &result); |
| 5484 | 5484 |
| 5485 // Verify that we consumed all test data. | |
| 5486 EXPECT_TRUE(data.at_read_eof()); | |
| 5487 EXPECT_TRUE(data.at_write_eof()); | |
| 5488 | |
| 5489 // Verify that the received push data is same as the expected push data. | 5485 // Verify that the received push data is same as the expected push data. |
| 5490 EXPECT_EQ(result2.compare(expected_push_result), 0) | 5486 EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5491 << "Received data: " | 5487 << "Received data: " |
| 5492 << result2 | 5488 << result2 |
| 5493 << "||||| Expected data: " | 5489 << "||||| Expected data: " |
| 5494 << expected_push_result; | 5490 << expected_push_result; |
| 5495 | 5491 |
| 5496 // Verify the SYN_REPLY. | 5492 // Verify the SYN_REPLY. |
| 5497 // Copy the response info, because trans goes away. | 5493 // Copy the response info, because trans goes away. |
| 5498 response = *trans->GetResponseInfo(); | 5494 response = *trans->GetResponseInfo(); |
| 5499 response2 = *trans2->GetResponseInfo(); | 5495 response2 = *trans2->GetResponseInfo(); |
| 5500 | 5496 |
| 5501 VerifyStreamsClosed(helper); | 5497 VerifyStreamsClosed(helper); |
| 5502 | 5498 |
| 5503 // Verify the SYN_REPLY. | 5499 // Verify the SYN_REPLY. |
| 5504 EXPECT_TRUE(response.headers != NULL); | 5500 EXPECT_TRUE(response.headers != NULL); |
| 5505 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5501 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5506 | 5502 |
| 5507 // Verify the pushed stream. | 5503 // Verify the pushed stream. |
| 5508 EXPECT_TRUE(response2.headers != NULL); | 5504 EXPECT_TRUE(response2.headers != NULL); |
| 5509 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 5505 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5506 |
| 5507 // Read the final EOF (which will close the session) |
| 5508 data.RunFor(1); |
| 5509 |
| 5510 // Verify that we consumed all test data. |
| 5511 EXPECT_TRUE(data.at_read_eof()); |
| 5512 EXPECT_TRUE(data.at_write_eof()); |
| 5510 } | 5513 } |
| 5511 | 5514 |
| 5512 TEST_P(SpdyNetworkTransactionSpdy3Test, ServerPushWithTwoHeaderFrames) { | 5515 TEST_P(SpdyNetworkTransactionSpdy3Test, ServerPushWithTwoHeaderFrames) { |
| 5513 // We push a stream and attempt to claim it before the headers come down. | 5516 // We push a stream and attempt to claim it before the headers come down. |
| 5514 static const unsigned char kPushBodyFrame[] = { | 5517 static const unsigned char kPushBodyFrame[] = { |
| 5515 0x00, 0x00, 0x00, 0x02, // header, ID | 5518 0x00, 0x00, 0x00, 0x02, // header, ID |
| 5516 0x01, 0x00, 0x00, 0x06, // FIN, length | 5519 0x01, 0x00, 0x00, 0x06, // FIN, length |
| 5517 'p', 'u', 's', 'h', 'e', 'd' // "pushed" | 5520 'p', 'u', 's', 'h', 'e', 'd' // "pushed" |
| 5518 }; | 5521 }; |
| 5519 scoped_ptr<SpdyFrame> | 5522 scoped_ptr<SpdyFrame> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5576 scoped_ptr<SpdyFrame> | 5579 scoped_ptr<SpdyFrame> |
| 5577 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); | 5580 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5578 MockRead reads[] = { | 5581 MockRead reads[] = { |
| 5579 CreateMockRead(*stream1_reply, 1), | 5582 CreateMockRead(*stream1_reply, 1), |
| 5580 CreateMockRead(*stream2_syn, 2), | 5583 CreateMockRead(*stream2_syn, 2), |
| 5581 CreateMockRead(*stream1_body, 3), | 5584 CreateMockRead(*stream1_body, 3), |
| 5582 CreateMockRead(*stream2_headers1, 4), | 5585 CreateMockRead(*stream2_headers1, 4), |
| 5583 CreateMockRead(*stream2_headers2, 5), | 5586 CreateMockRead(*stream2_headers2, 5), |
| 5584 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), | 5587 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame), |
| 5585 arraysize(kPushBodyFrame), 6), | 5588 arraysize(kPushBodyFrame), 6), |
| 5586 MockRead(ASYNC, 0, 6), // EOF | 5589 MockRead(ASYNC, 0, 7), // EOF |
| 5587 }; | 5590 }; |
| 5588 | 5591 |
| 5589 HttpResponseInfo response; | 5592 HttpResponseInfo response; |
| 5590 HttpResponseInfo response2; | 5593 HttpResponseInfo response2; |
| 5591 std::string expected_push_result("pushed"); | 5594 std::string expected_push_result("pushed"); |
| 5592 DeterministicSocketData data(reads, arraysize(reads), | 5595 DeterministicSocketData data(reads, arraysize(reads), |
| 5593 writes, arraysize(writes)); | 5596 writes, arraysize(writes)); |
| 5594 | 5597 |
| 5595 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 5598 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 5596 BoundNetLog(), GetParam(), NULL); | 5599 BoundNetLog(), GetParam(), NULL); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 5624 data.RunFor(3); | 5627 data.RunFor(3); |
| 5625 MessageLoop::current()->RunAllPending(); | 5628 MessageLoop::current()->RunAllPending(); |
| 5626 | 5629 |
| 5627 // Read the server push body. | 5630 // Read the server push body. |
| 5628 std::string result2; | 5631 std::string result2; |
| 5629 ReadResult(trans2.get(), &data, &result2); | 5632 ReadResult(trans2.get(), &data, &result2); |
| 5630 // Read the response body. | 5633 // Read the response body. |
| 5631 std::string result; | 5634 std::string result; |
| 5632 ReadResult(trans, &data, &result); | 5635 ReadResult(trans, &data, &result); |
| 5633 | 5636 |
| 5634 // Verify that we consumed all test data. | |
| 5635 EXPECT_TRUE(data.at_read_eof()); | |
| 5636 EXPECT_TRUE(data.at_write_eof()); | |
| 5637 | |
| 5638 // Verify that the received push data is same as the expected push data. | 5637 // Verify that the received push data is same as the expected push data. |
| 5639 EXPECT_EQ(result2.compare(expected_push_result), 0) | 5638 EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5640 << "Received data: " | 5639 << "Received data: " |
| 5641 << result2 | 5640 << result2 |
| 5642 << "||||| Expected data: " | 5641 << "||||| Expected data: " |
| 5643 << expected_push_result; | 5642 << expected_push_result; |
| 5644 | 5643 |
| 5645 // Verify the SYN_REPLY. | 5644 // Verify the SYN_REPLY. |
| 5646 // Copy the response info, because trans goes away. | 5645 // Copy the response info, because trans goes away. |
| 5647 response = *trans->GetResponseInfo(); | 5646 response = *trans->GetResponseInfo(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5660 // Verify we got all the headers | 5659 // Verify we got all the headers |
| 5661 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5660 EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5662 "scheme", "http")); | 5661 "scheme", "http")); |
| 5663 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5662 EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5664 "host", "www.google.com")); | 5663 "host", "www.google.com")); |
| 5665 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5664 EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5666 "path", "/foo.dat")); | 5665 "path", "/foo.dat")); |
| 5667 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); | 5666 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5668 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); | 5667 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
| 5669 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1")); | 5668 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1")); |
| 5669 |
| 5670 // Read the final EOF (which will close the session) |
| 5671 data.RunFor(1); |
| 5672 |
| 5673 // Verify that we consumed all test data. |
| 5674 EXPECT_TRUE(data.at_read_eof()); |
| 5675 EXPECT_TRUE(data.at_write_eof()); |
| 5670 } | 5676 } |
| 5671 | 5677 |
| 5672 TEST_P(SpdyNetworkTransactionSpdy3Test, SynReplyWithHeaders) { | 5678 TEST_P(SpdyNetworkTransactionSpdy3Test, SynReplyWithHeaders) { |
| 5673 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 5679 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 5674 MockWrite writes[] = { CreateMockWrite(*req) }; | 5680 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 5675 | 5681 |
| 5676 static const char* const kInitialHeaders[] = { | 5682 static const char* const kInitialHeaders[] = { |
| 5677 ":status", | 5683 ":status", |
| 5678 "200 OK", | 5684 "200 OK", |
| 5679 ":version", | 5685 ":version", |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6085 // And now we can allow everything else to run to completion. | 6091 // And now we can allow everything else to run to completion. |
| 6086 data.SetStop(10); | 6092 data.SetStop(10); |
| 6087 data.Run(); | 6093 data.Run(); |
| 6088 EXPECT_EQ(OK, callback2.WaitForResult()); | 6094 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 6089 EXPECT_EQ(OK, callback3.WaitForResult()); | 6095 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 6090 | 6096 |
| 6091 helper.VerifyDataConsumed(); | 6097 helper.VerifyDataConsumed(); |
| 6092 } | 6098 } |
| 6093 | 6099 |
| 6094 } // namespace net | 6100 } // namespace net |
| OLD | NEW |