Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: net/spdy/spdy_http_stream_unittest.cc

Issue 2811072: SPDY sends RST_STREAM upon cancelling request, or bad header parse data. (Closed)
Patch Set: Merge trunk Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
11 11
12 class SpdyHttpStreamTest : public testing::Test { 12 class SpdyHttpStreamTest : public testing::Test {
13 public:
14 OrderedSocketData* data() { return data_; }
13 protected: 15 protected:
14 SpdyHttpStreamTest() {} 16 SpdyHttpStreamTest() {}
15 17
16 void EnableCompression(bool enabled) { 18 void EnableCompression(bool enabled) {
17 spdy::SpdyFramer::set_enable_compression_default(enabled); 19 spdy::SpdyFramer::set_enable_compression_default(enabled);
18 } 20 }
19 21
20 virtual void TearDown() { 22 virtual void TearDown() {
21 MessageLoop::current()->RunAllPending(); 23 MessageLoop::current()->RunAllPending();
22 } 24 }
(...skipping 19 matching lines...) Expand all
42 44
43 TEST_F(SpdyHttpStreamTest, SendRequest) { 45 TEST_F(SpdyHttpStreamTest, SendRequest) {
44 EnableCompression(false); 46 EnableCompression(false);
45 SpdySession::SetSSLMode(false); 47 SpdySession::SetSSLMode(false);
46 48
47 SpdySessionDependencies session_deps; 49 SpdySessionDependencies session_deps;
48 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 50 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
49 MockWrite writes[] = { 51 MockWrite writes[] = {
50 CreateMockWrite(*req.get(), 1), 52 CreateMockWrite(*req.get(), 1),
51 }; 53 };
54 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
52 MockRead reads[] = { 55 MockRead reads[] = {
53 MockRead(false, 0, 2) // EOF 56 CreateMockRead(*resp, 2),
57 MockRead(true, ERR_IO_PENDING, 3), // Force a pause
58 MockRead(false, 0, 4) // EOF
54 }; 59 };
55 60
56 HostPortPair host_port_pair("www.google.com", 80); 61 HostPortPair host_port_pair("www.google.com", 80);
57 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), 62 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes),
58 host_port_pair)); 63 host_port_pair));
59 64
60 HttpRequestInfo request; 65 HttpRequestInfo request;
61 request.method = "GET"; 66 request.method = "GET";
62 request.url = GURL("http://www.google.com/"); 67 request.url = GURL("http://www.google.com/");
63 TestCompletionCallback callback; 68 TestCompletionCallback callback;
64 HttpResponseInfo response; 69 HttpResponseInfo response;
65 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream()); 70 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream());
66 ASSERT_EQ( 71 ASSERT_EQ(
67 OK, 72 OK,
68 http_stream->InitializeStream(session_, request, BoundNetLog(), NULL)); 73 http_stream->InitializeStream(session_, request, BoundNetLog(), NULL));
69 http_stream->InitializeRequest(base::Time::Now(), NULL); 74 http_stream->InitializeRequest(base::Time::Now(), NULL);
70 75
71 EXPECT_EQ(ERR_IO_PENDING, 76 EXPECT_EQ(ERR_IO_PENDING,
72 http_stream->SendRequest(&response, &callback)); 77 http_stream->SendRequest(&response, &callback));
73 MessageLoop::current()->RunAllPending();
74 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); 78 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair));
75 http_session_->spdy_session_pool()->Remove(session_); 79
80 // This triggers the MockWrite and reads 2 & 3
81 callback.WaitForResult();
82
83 // This triggers read 4. The empty read causes the session to shut down.
84 data()->CompleteRead();
85
86 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(host_port_pair));
87 EXPECT_TRUE(data()->at_read_eof());
88 EXPECT_TRUE(data()->at_write_eof());
76 } 89 }
77 90
78 // 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
79 TEST_F(SpdyHttpStreamTest, SpdyURLTest) { 92 TEST_F(SpdyHttpStreamTest, SpdyURLTest) {
80 EnableCompression(false); 93 EnableCompression(false);
81 SpdySession::SetSSLMode(false); 94 SpdySession::SetSSLMode(false);
82 95
83 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
84 MockWrite writes[] = {
85 CreateMockWrite(*req.get(), 1),
86 };
87 MockRead reads[] = { 96 MockRead reads[] = {
88 MockRead(false, 0, 2), // EOF 97 MockRead(false, 0, 2), // EOF
89 }; 98 };
90 99
91 HostPortPair host_port_pair("www.google.com", 80); 100 HostPortPair host_port_pair("www.google.com", 80);
92 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), 101 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), NULL, 0,
93 host_port_pair)); 102 host_port_pair));
94 103
95 HttpRequestInfo request; 104 HttpRequestInfo request;
96 request.method = "GET"; 105 request.method = "GET";
97 request.url = GURL("http://www.google.com/foo?query=what#anchor"); 106 request.url = GURL("http://www.google.com/foo?query=what#anchor");
98 TestCompletionCallback callback; 107 TestCompletionCallback callback;
99 HttpResponseInfo response; 108 HttpResponseInfo response;
100 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream()); 109 scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream());
101 ASSERT_EQ( 110 ASSERT_EQ(
102 OK, 111 OK,
103 http_stream->InitializeStream(session_, request, BoundNetLog(), NULL)); 112 http_stream->InitializeStream(session_, request, BoundNetLog(), NULL));
104 http_stream->InitializeRequest(base::Time::Now(), NULL); 113 http_stream->InitializeRequest(base::Time::Now(), NULL);
105 114
106 spdy::SpdyHeaderBlock* spdy_header = 115 spdy::SpdyHeaderBlock* spdy_header =
107 http_stream->stream()->spdy_headers().get(); 116 http_stream->stream()->spdy_headers().get();
108 if (spdy_header->find("url") != spdy_header->end()) 117 if (spdy_header->find("url") != spdy_header->end())
109 EXPECT_EQ("http://www.google.com/foo?query=what", 118 EXPECT_EQ("http://www.google.com/foo?query=what",
110 spdy_header->find("url")->second); 119 spdy_header->find("url")->second);
111 else 120 else
112 FAIL() << "No url is set in spdy_header!"; 121 FAIL() << "No url is set in spdy_header!";
113 122
114 MessageLoop::current()->RunAllPending(); 123 MessageLoop::current()->RunAllPending();
115 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair)); 124 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(host_port_pair));
116 http_session_->spdy_session_pool()->Remove(session_); 125 http_session_->spdy_session_pool()->CloseAllSessions();
126 EXPECT_TRUE(!data()->at_read_eof());
117 } 127 }
118 128
119 // TODO(willchan): Write a longer test for SpdyStream that exercises all 129 // TODO(willchan): Write a longer test for SpdyStream that exercises all
120 // methods. 130 // methods.
121 131
122 } // namespace net 132 } // namespace net
OLDNEW
« no previous file with comments | « net/data/valgrind/net_unittests.gtest-tsan_win32.txt ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698