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