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_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 #include "net/spdy/spdy_session.h" | 6 #include "net/spdy/spdy_session.h" |
7 #include "net/spdy/spdy_test_util.h" | 7 #include "net/spdy/spdy_test_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); | 86 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); |
87 | 87 |
88 // This triggers the MockWrite and read 2 | 88 // This triggers the MockWrite and read 2 |
89 callback.WaitForResult(); | 89 callback.WaitForResult(); |
90 | 90 |
91 // This triggers read 3. The empty read causes the session to shut down. | 91 // This triggers read 3. The empty read causes the session to shut down. |
92 data()->CompleteRead(); | 92 data()->CompleteRead(); |
93 | 93 |
94 // Because we abandoned the stream, we don't expect to find a session in the | 94 // Because we abandoned the stream, we don't expect to find a session in the |
95 // pool anymore. | 95 // pool anymore. |
96 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair)); | 96 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
97 EXPECT_TRUE(data()->at_read_eof()); | 97 EXPECT_TRUE(data()->at_read_eof()); |
98 EXPECT_TRUE(data()->at_write_eof()); | 98 EXPECT_TRUE(data()->at_write_eof()); |
99 } | 99 } |
| 100 |
| 101 TEST_F(SpdyHttpStreamTest, SendChunkedPost) { |
| 102 EnableCompression(false); |
| 103 SpdySession::SetSSLMode(false); |
| 104 UploadDataStream::set_merge_chunks(false); |
| 105 |
| 106 scoped_ptr<spdy::SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
| 107 scoped_ptr<spdy::SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
| 108 scoped_ptr<spdy::SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
| 109 MockWrite writes[] = { |
| 110 CreateMockWrite(*req.get(), 1), |
| 111 CreateMockWrite(*chunk1, 2), // POST upload frames |
| 112 CreateMockWrite(*chunk2, 3), |
| 113 }; |
| 114 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 115 MockRead reads[] = { |
| 116 CreateMockRead(*resp, 4), |
| 117 CreateMockRead(*chunk1, 5), |
| 118 CreateMockRead(*chunk2, 5), |
| 119 MockRead(false, 0, 6) // EOF |
| 120 }; |
| 121 |
| 122 HostPortPair host_port_pair("www.google.com", 80); |
| 123 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
| 124 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), |
| 125 host_port_pair)); |
| 126 |
| 127 HttpRequestInfo request; |
| 128 request.method = "POST"; |
| 129 request.url = GURL("http://www.google.com/"); |
| 130 request.upload_data = new UploadData(); |
| 131 request.upload_data->set_is_chunked(true); |
| 132 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false); |
| 133 request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true); |
| 134 TestCompletionCallback callback; |
| 135 HttpResponseInfo response; |
| 136 HttpRequestHeaders headers; |
| 137 BoundNetLog net_log; |
| 138 SpdyHttpStream http_stream(session_.get(), true); |
| 139 ASSERT_EQ( |
| 140 OK, |
| 141 http_stream.InitializeStream(&request, net_log, NULL)); |
| 142 |
| 143 UploadDataStream* upload_stream = |
| 144 UploadDataStream::Create(request.upload_data, NULL); |
| 145 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( |
| 146 headers, upload_stream, &response, &callback)); |
| 147 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); |
| 148 |
| 149 // This triggers the MockWrite and read 2 |
| 150 callback.WaitForResult(); |
| 151 |
| 152 // This triggers read 3. The empty read causes the session to shut down. |
| 153 data()->CompleteRead(); |
| 154 MessageLoop::current()->RunAllPending(); |
| 155 |
| 156 // Because we abandoned the stream, we don't expect to find a session in the |
| 157 // pool anymore. |
| 158 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
| 159 EXPECT_TRUE(data()->at_read_eof()); |
| 160 EXPECT_TRUE(data()->at_write_eof()); |
| 161 } |
100 | 162 |
101 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 163 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
102 TEST_F(SpdyHttpStreamTest, SpdyURLTest) { | 164 TEST_F(SpdyHttpStreamTest, SpdyURLTest) { |
103 EnableCompression(false); | 165 EnableCompression(false); |
104 SpdySession::SetSSLMode(false); | 166 SpdySession::SetSSLMode(false); |
105 | 167 |
106 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 168 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
107 const char * const base_url = "http://www.google.com/foo?query=what"; | 169 const char * const base_url = "http://www.google.com/foo?query=what"; |
108 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); | 170 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); |
109 MockWrite writes[] = { | 171 MockWrite writes[] = { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 FAIL() << "No url is set in spdy_header!"; | 206 FAIL() << "No url is set in spdy_header!"; |
145 | 207 |
146 // This triggers the MockWrite and read 2 | 208 // This triggers the MockWrite and read 2 |
147 callback.WaitForResult(); | 209 callback.WaitForResult(); |
148 | 210 |
149 // This triggers read 3. The empty read causes the session to shut down. | 211 // This triggers read 3. The empty read causes the session to shut down. |
150 data()->CompleteRead(); | 212 data()->CompleteRead(); |
151 | 213 |
152 // Because we abandoned the stream, we don't expect to find a session in the | 214 // Because we abandoned the stream, we don't expect to find a session in the |
153 // pool anymore. | 215 // pool anymore. |
154 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair)); | 216 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
155 EXPECT_TRUE(data()->at_read_eof()); | 217 EXPECT_TRUE(data()->at_read_eof()); |
156 EXPECT_TRUE(data()->at_write_eof()); | 218 EXPECT_TRUE(data()->at_write_eof()); |
157 } | 219 } |
158 | 220 |
159 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 221 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
160 // methods. | 222 // methods. |
161 | 223 |
162 } // namespace net | 224 } // namespace net |
OLD | NEW |