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

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

Issue 3020032: Implement server push protocol 2. (Closed)
Patch Set: nits. Created 10 years, 4 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
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_io_buffer.h" 5 #include "net/spdy/spdy_io_buffer.h"
6 #include "net/spdy/spdy_session.h" 6 #include "net/spdy/spdy_session.h"
7 #include "net/spdy/spdy_stream.h" 7 #include "net/spdy/spdy_stream.h"
8 #include "net/spdy/spdy_test_util.h" 8 #include "net/spdy/spdy_test_util.h"
9 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 // Delete the first session. 105 // Delete the first session.
106 session = NULL; 106 session = NULL;
107 107
108 // Delete the second session. 108 // Delete the second session.
109 spdy_session_pool->Remove(session2); 109 spdy_session_pool->Remove(session2);
110 session2 = NULL; 110 session2 = NULL;
111 } 111 }
112 112
113 } // namespace 113 } // namespace
114
115 TEST_F(SpdySessionTest, GetActivePushStream) {
116 spdy::SpdyFramer framer;
117 SpdySessionTest::TurnOffCompression();
118
119 SpdySessionDependencies session_deps;
120 session_deps.host_resolver->set_synchronous_mode(true);
121
122 MockConnect connect_data(false, OK);
123 spdy::SpdyHeaderBlock headers;
124 headers["path"] = "/foo.js";
125 headers["status"] = "200";
126 headers["version"] = "HTTP/1.1";
127 scoped_ptr<spdy::SpdyFrame> push_syn(framer.CreateSynStream(
128 2, 1, 0, spdy::CONTROL_FLAG_NONE, false, &headers));
129 MockRead reads[] = {
130 CreateMockRead(*push_syn),
131 MockRead(true, ERR_IO_PENDING, 0) // EOF
132 };
133 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
134 data.set_connect_data(connect_data);
135 session_deps.socket_factory.AddSocketDataProvider(&data);
136
137 SSLSocketDataProvider ssl(false, OK);
138 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
139
140 scoped_refptr<HttpNetworkSession> http_session(
141 SpdySessionDependencies::SpdyCreateSession(&session_deps));
142
143 const std::string kTestHost("www.foo.com");
144 const int kTestPort = 80;
145 HostPortPair test_host_port_pair(kTestHost, kTestPort);
146 HostPortProxyPair pair(test_host_port_pair, "");
147
148 scoped_refptr<SpdySessionPool> spdy_session_pool(
149 http_session->spdy_session_pool());
150 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
151 scoped_refptr<SpdySession> session =
152 spdy_session_pool->Get(pair, http_session.get(), BoundNetLog());
153 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
154
155 // No push streams should exist in the beginning.
156 std::string test_push_path = "/foo.js";
157 scoped_refptr<SpdyStream> first_stream = session->GetActivePushStream(
158 test_push_path);
159 EXPECT_EQ(static_cast<SpdyStream*>(NULL), first_stream.get());
160
161 // Read in the data which contains a server-issued SYN_STREAM.
162 scoped_refptr<TCPSocketParams> tcp_params =
163 new TCPSocketParams(test_host_port_pair, MEDIUM, GURL(), false);
164 int rv = session->Connect(kTestHost, tcp_params, MEDIUM);
165 ASSERT_EQ(OK, rv);
166 MessageLoop::current()->RunAllPending();
167
168 // An unpushed path should not work.
169 scoped_refptr<SpdyStream> unpushed_stream = session->GetActivePushStream(
170 "/unpushed_path");
171 EXPECT_EQ(static_cast<SpdyStream*>(NULL), unpushed_stream.get());
172
173 // The pushed path should be found.
174 scoped_refptr<SpdyStream> second_stream = session->GetActivePushStream(
175 test_push_path);
176 ASSERT_NE(static_cast<SpdyStream*>(NULL), second_stream.get());
177 EXPECT_EQ(test_push_path, second_stream->path());
178 EXPECT_EQ(2U, second_stream->stream_id());
179 EXPECT_EQ(0, second_stream->priority());
180
181 // Clean up
182 second_stream = NULL;
183 session = NULL;
184 spdy_session_pool->CloseAllSessions();
185
186 // RunAllPending needs to be called here because the
187 // ClientSocketPoolBase posts a task to clean up and destroy the
188 // underlying socket.
189 MessageLoop::current()->RunAllPending();
190 }
191
192 } // namespace net 114 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698