| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 HostPortPair host_port_pair("www.google.com", 80); | 61 HostPortPair host_port_pair("www.google.com", 80); |
| 62 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), | 62 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), |
| 63 host_port_pair)); | 63 host_port_pair)); |
| 64 | 64 |
| 65 HttpRequestInfo request; | 65 HttpRequestInfo request; |
| 66 request.method = "GET"; | 66 request.method = "GET"; |
| 67 request.url = GURL("http://www.google.com/"); | 67 request.url = GURL("http://www.google.com/"); |
| 68 TestCompletionCallback callback; | 68 TestCompletionCallback callback; |
| 69 HttpResponseInfo response; | 69 HttpResponseInfo response; |
| 70 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream()); | 70 BoundNetLog net_log; |
| 71 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream(session_.get())); |
| 71 ASSERT_EQ( | 72 ASSERT_EQ( |
| 72 OK, | 73 OK, |
| 73 http_stream->InitializeStream(session_, request, BoundNetLog(), NULL)); | 74 http_stream->InitializeStream(&request, net_log, NULL)); |
| 74 http_stream->InitializeRequest(base::Time::Now(), NULL); | |
| 75 | 75 |
| 76 EXPECT_EQ(ERR_IO_PENDING, | 76 EXPECT_EQ(ERR_IO_PENDING, |
| 77 http_stream->SendRequest(&response, &callback)); | 77 http_stream->SendRequest("", NULL, &response, &callback)); |
| 78 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); | 78 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); |
| 79 | 79 |
| 80 // This triggers the MockWrite and reads 2 & 3 | 80 // This triggers the MockWrite and reads 2 & 3 |
| 81 callback.WaitForResult(); | 81 callback.WaitForResult(); |
| 82 | 82 |
| 83 // This triggers read 4. The empty read causes the session to shut down. | 83 // This triggers read 4. The empty read causes the session to shut down. |
| 84 data()->CompleteRead(); | 84 data()->CompleteRead(); |
| 85 | 85 |
| 86 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(host_port_pair)); | 86 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(host_port_pair)); |
| 87 EXPECT_TRUE(data()->at_read_eof()); | 87 EXPECT_TRUE(data()->at_read_eof()); |
| 88 EXPECT_TRUE(data()->at_write_eof()); | 88 EXPECT_TRUE(data()->at_write_eof()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 91 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
| 92 TEST_F(SpdyHttpStreamTest, SpdyURLTest) { | 92 TEST_F(SpdyHttpStreamTest, SpdyURLTest) { |
| 93 EnableCompression(false); | 93 EnableCompression(false); |
| 94 SpdySession::SetSSLMode(false); | 94 SpdySession::SetSSLMode(false); |
| 95 | 95 |
| 96 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
| 97 const char * const base_url = "http://www.google.com/foo?query=what"; |
| 98 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); |
| 99 MockWrite writes[] = { |
| 100 CreateMockWrite(*req.get(), 1), |
| 101 }; |
| 96 MockRead reads[] = { | 102 MockRead reads[] = { |
| 97 MockRead(false, 0, 2), // EOF | 103 MockRead(false, 0, 2), // EOF |
| 98 }; | 104 }; |
| 99 | 105 |
| 100 HostPortPair host_port_pair("www.google.com", 80); | 106 HostPortPair host_port_pair("www.google.com", 80); |
| 101 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), NULL, 0, | 107 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), |
| 102 host_port_pair)); | 108 host_port_pair)); |
| 103 | 109 |
| 104 HttpRequestInfo request; | 110 HttpRequestInfo request; |
| 105 request.method = "GET"; | 111 request.method = "GET"; |
| 106 request.url = GURL("http://www.google.com/foo?query=what#anchor"); | 112 request.url = GURL(full_url); |
| 107 TestCompletionCallback callback; | 113 TestCompletionCallback callback; |
| 108 HttpResponseInfo response; | 114 HttpResponseInfo response; |
| 109 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream()); | 115 BoundNetLog net_log; |
| 116 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream(session_)); |
| 110 ASSERT_EQ( | 117 ASSERT_EQ( |
| 111 OK, | 118 OK, |
| 112 http_stream->InitializeStream(session_, request, BoundNetLog(), NULL)); | 119 http_stream->InitializeStream(&request, net_log, NULL)); |
| 113 http_stream->InitializeRequest(base::Time::Now(), NULL); | 120 |
| 121 EXPECT_EQ(ERR_IO_PENDING, |
| 122 http_stream->SendRequest("", NULL, &response, &callback)); |
| 114 | 123 |
| 115 spdy::SpdyHeaderBlock* spdy_header = | 124 spdy::SpdyHeaderBlock* spdy_header = |
| 116 http_stream->stream()->spdy_headers().get(); | 125 http_stream->stream()->spdy_headers().get(); |
| 126 EXPECT_TRUE(spdy_header != NULL); |
| 117 if (spdy_header->find("url") != spdy_header->end()) | 127 if (spdy_header->find("url") != spdy_header->end()) |
| 118 EXPECT_EQ("http://www.google.com/foo?query=what", | 128 EXPECT_EQ(base_url, spdy_header->find("url")->second); |
| 119 spdy_header->find("url")->second); | |
| 120 else | 129 else |
| 121 FAIL() << "No url is set in spdy_header!"; | 130 FAIL() << "No url is set in spdy_header!"; |
| 122 | 131 |
| 123 MessageLoop::current()->RunAllPending(); | 132 MessageLoop::current()->RunAllPending(); |
| 124 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); | 133 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); |
| 125 http_session_->spdy_session_pool()->CloseAllSessions(); | 134 http_session_->spdy_session_pool()->CloseAllSessions(); |
| 126 EXPECT_TRUE(!data()->at_read_eof()); | 135 EXPECT_TRUE(!data()->at_read_eof()); |
| 127 } | 136 } |
| 128 | 137 |
| 129 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 138 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 130 // methods. | 139 // methods. |
| 131 | 140 |
| 132 } // namespace net | 141 } // namespace net |
| OLD | NEW |