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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 EXPECT_FALSE(spdy_stream1); | 2598 EXPECT_FALSE(spdy_stream1); |
2599 | 2599 |
2600 // Verify task that the observer's executed_count is 1, which indicates DoRead | 2600 // Verify task that the observer's executed_count is 1, which indicates DoRead |
2601 // has posted only one task and thus yielded though there is data available | 2601 // has posted only one task and thus yielded though there is data available |
2602 // for it to read. | 2602 // for it to read. |
2603 EXPECT_EQ(1u, observer.executed_count()); | 2603 EXPECT_EQ(1u, observer.executed_count()); |
2604 EXPECT_TRUE(data.AllWriteDataConsumed()); | 2604 EXPECT_TRUE(data.AllWriteDataConsumed()); |
2605 EXPECT_TRUE(data.AllReadDataConsumed()); | 2605 EXPECT_TRUE(data.AllReadDataConsumed()); |
2606 } | 2606 } |
2607 | 2607 |
| 2608 // Regression test for https://crbug.com/531570. |
| 2609 // Test the case where DoRead() takes long but returns synchronously. |
| 2610 TEST_P(SpdySessionTest, TestYieldingSlowSynchronousReads) { |
| 2611 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2612 session_deps_.time_func = SlowReads; |
| 2613 |
| 2614 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 2615 |
| 2616 scoped_ptr<SpdyFrame> req1( |
| 2617 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, MEDIUM, true)); |
| 2618 MockWrite writes[] = { |
| 2619 CreateMockWrite(*req1, 0), |
| 2620 }; |
| 2621 |
| 2622 scoped_ptr<SpdyFrame> partial_data_frame( |
| 2623 framer.CreateDataFrame(1, "foo ", 4, DATA_FLAG_NONE)); |
| 2624 scoped_ptr<SpdyFrame> finish_data_frame( |
| 2625 framer.CreateDataFrame(1, "bar", 3, DATA_FLAG_FIN)); |
| 2626 |
| 2627 scoped_ptr<SpdyFrame> resp1( |
| 2628 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 2629 |
| 2630 MockRead reads[] = { |
| 2631 CreateMockRead(*resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 2632 CreateMockRead(*partial_data_frame, 3, SYNCHRONOUS), |
| 2633 CreateMockRead(*partial_data_frame, 4, SYNCHRONOUS), |
| 2634 CreateMockRead(*partial_data_frame, 5, SYNCHRONOUS), |
| 2635 CreateMockRead(*finish_data_frame, 6, SYNCHRONOUS), |
| 2636 MockRead(ASYNC, 0, 7) // EOF |
| 2637 }; |
| 2638 |
| 2639 // Create SpdySession and SpdyStream and send the request. |
| 2640 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2641 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2642 |
| 2643 CreateNetworkSession(); |
| 2644 CreateInsecureSpdySession(); |
| 2645 |
| 2646 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( |
| 2647 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, MEDIUM, BoundNetLog()); |
| 2648 ASSERT_TRUE(spdy_stream1.get() != nullptr); |
| 2649 EXPECT_EQ(0u, spdy_stream1->stream_id()); |
| 2650 test::StreamDelegateDoNothing delegate1(spdy_stream1); |
| 2651 spdy_stream1->SetDelegate(&delegate1); |
| 2652 |
| 2653 scoped_ptr<SpdyHeaderBlock> headers1( |
| 2654 spdy_util_.ConstructGetHeaderBlock(kDefaultURL)); |
| 2655 spdy_stream1->SendRequestHeaders(headers1.Pass(), NO_MORE_DATA_TO_SEND); |
| 2656 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders()); |
| 2657 |
| 2658 // Run until 1st read. |
| 2659 EXPECT_EQ(0u, delegate1.stream_id()); |
| 2660 base::RunLoop().RunUntilIdle(); |
| 2661 EXPECT_EQ(1u, delegate1.stream_id()); |
| 2662 |
| 2663 // Read all the data and verify SpdySession::DoReadLoop has posted a task. |
| 2664 data.CompleteRead(); |
| 2665 base::RunLoop().RunUntilIdle(); |
| 2666 EXPECT_EQ("foo foo foo bar", delegate1.TakeReceivedData()); |
| 2667 EXPECT_FALSE(spdy_stream1); |
| 2668 |
| 2669 EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2670 EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2671 } |
| 2672 |
2608 // Test that SpdySession::DoReadLoop yields while reading the | 2673 // Test that SpdySession::DoReadLoop yields while reading the |
2609 // data. This test makes 32k + 1 bytes of data available on the socket | 2674 // data. This test makes 32k + 1 bytes of data available on the socket |
2610 // for reading. It then verifies that DoRead has yielded even though | 2675 // for reading. It then verifies that DoRead has yielded even though |
2611 // there is data available for it to read (i.e, socket()->Read didn't | 2676 // there is data available for it to read (i.e, socket()->Read didn't |
2612 // return ERR_IO_PENDING during socket reads). | 2677 // return ERR_IO_PENDING during socket reads). |
2613 TEST_P(SpdySessionTest, TestYieldingDuringReadData) { | 2678 TEST_P(SpdySessionTest, TestYieldingDuringReadData) { |
2614 session_deps_.host_resolver->set_synchronous_mode(true); | 2679 session_deps_.host_resolver->set_synchronous_mode(true); |
2615 session_deps_.time_func = InstantaneousReads; | 2680 session_deps_.time_func = InstantaneousReads; |
2616 | 2681 |
2617 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 2682 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
(...skipping 2430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5048 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5113 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5049 "spdy_pooling.pem"); | 5114 "spdy_pooling.pem"); |
5050 ssl_info.is_issued_by_known_root = true; | 5115 ssl_info.is_issued_by_known_root = true; |
5051 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5116 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5052 | 5117 |
5053 EXPECT_TRUE(SpdySession::CanPool( | 5118 EXPECT_TRUE(SpdySession::CanPool( |
5054 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5119 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5055 } | 5120 } |
5056 | 5121 |
5057 } // namespace net | 5122 } // namespace net |
OLD | NEW |