OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/quic/core/quic_client_promised_info.h" | 5 #include "net/quic/core/quic_client_promised_info.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "net/quic/core/spdy_utils.h" | 10 #include "net/quic/core/spdy_utils.h" |
11 #include "net/quic/test_tools/crypto_test_utils.h" | 11 #include "net/quic/test_tools/crypto_test_utils.h" |
12 #include "net/quic/test_tools/quic_client_promised_info_peer.h" | 12 #include "net/quic/test_tools/quic_client_promised_info_peer.h" |
13 #include "net/test/gtest_util.h" | 13 #include "net/test/gtest_util.h" |
14 #include "net/tools/quic/quic_client_session.h" | 14 #include "net/tools/quic/quic_client_session.h" |
15 #include "net/tools/quic/test_tools/push_promise_delegate.h" | |
16 | 15 |
17 using std::string; | 16 using std::string; |
18 using testing::StrictMock; | 17 using testing::StrictMock; |
19 | 18 |
20 namespace net { | 19 namespace net { |
21 namespace test { | 20 namespace test { |
22 namespace { | 21 namespace { |
23 | 22 |
24 class MockQuicClientSession : public QuicClientSession { | 23 class MockQuicClientSession : public QuicClientSession { |
25 public: | 24 public: |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 ASSERT_NE(promised, nullptr); | 182 ASSERT_NE(promised, nullptr); |
184 | 183 |
185 // Need to send the promised response headers and initiate the | 184 // Need to send the promised response headers and initiate the |
186 // rendezvous for secondary validation to proceed. | 185 // rendezvous for secondary validation to proceed. |
187 QuicSpdyClientStream* promise_stream = static_cast<QuicSpdyClientStream*>( | 186 QuicSpdyClientStream* promise_stream = static_cast<QuicSpdyClientStream*>( |
188 session_.GetOrCreateStream(promise_id_)); | 187 session_.GetOrCreateStream(promise_id_)); |
189 auto headers = AsHeaderList(headers_); | 188 auto headers = AsHeaderList(headers_); |
190 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 189 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
191 headers); | 190 headers); |
192 | 191 |
193 PushPromiseDelegate delegate(/*match=*/false); | 192 TestPushPromiseDelegate delegate(/*match=*/false); |
194 EXPECT_CALL(*connection_, | 193 EXPECT_CALL(*connection_, |
195 SendRstStream(promise_id_, QUIC_PROMISE_VARY_MISMATCH, 0)); | 194 SendRstStream(promise_id_, QUIC_PROMISE_VARY_MISMATCH, 0)); |
196 EXPECT_CALL(session_, CloseStream(promise_id_)); | 195 EXPECT_CALL(session_, CloseStream(promise_id_)); |
197 | 196 |
198 promised->HandleClientRequest(client_request_, &delegate); | 197 promised->HandleClientRequest(client_request_, &delegate); |
199 } | 198 } |
200 | 199 |
201 TEST_F(QuicClientPromisedInfoTest, PushPromiseVaryWaits) { | 200 TEST_F(QuicClientPromisedInfoTest, PushPromiseVaryWaits) { |
202 ReceivePromise(promise_id_); | 201 ReceivePromise(promise_id_); |
203 | 202 |
204 QuicClientPromisedInfo* promised = session_.GetPromisedById(promise_id_); | 203 QuicClientPromisedInfo* promised = session_.GetPromisedById(promise_id_); |
| 204 EXPECT_FALSE(promised->is_validating()); |
205 ASSERT_NE(promised, nullptr); | 205 ASSERT_NE(promised, nullptr); |
206 | 206 |
207 // Now initiate rendezvous. | 207 // Now initiate rendezvous. |
208 PushPromiseDelegate delegate(/*match=*/true); | 208 TestPushPromiseDelegate delegate(/*match=*/true); |
209 promised->HandleClientRequest(client_request_, &delegate); | 209 promised->HandleClientRequest(client_request_, &delegate); |
| 210 EXPECT_TRUE(promised->is_validating()); |
210 | 211 |
211 // Promise is still there, waiting for response. | 212 // Promise is still there, waiting for response. |
212 EXPECT_NE(session_.GetPromisedById(promise_id_), nullptr); | 213 EXPECT_NE(session_.GetPromisedById(promise_id_), nullptr); |
213 | 214 |
214 // Send Response, should trigger promise validation and complete rendezvous | 215 // Send Response, should trigger promise validation and complete rendezvous |
215 QuicSpdyClientStream* promise_stream = static_cast<QuicSpdyClientStream*>( | 216 QuicSpdyClientStream* promise_stream = static_cast<QuicSpdyClientStream*>( |
216 session_.GetOrCreateStream(promise_id_)); | 217 session_.GetOrCreateStream(promise_id_)); |
217 ASSERT_NE(promise_stream, nullptr); | 218 ASSERT_NE(promise_stream, nullptr); |
218 auto headers = AsHeaderList(headers_); | 219 auto headers = AsHeaderList(headers_); |
219 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 220 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
(...skipping 12 matching lines...) Expand all Loading... |
232 QuicSpdyClientStream* promise_stream = static_cast<QuicSpdyClientStream*>( | 233 QuicSpdyClientStream* promise_stream = static_cast<QuicSpdyClientStream*>( |
233 session_.GetOrCreateStream(promise_id_)); | 234 session_.GetOrCreateStream(promise_id_)); |
234 ASSERT_NE(promise_stream, nullptr); | 235 ASSERT_NE(promise_stream, nullptr); |
235 | 236 |
236 // Send Response, should trigger promise validation and complete rendezvous | 237 // Send Response, should trigger promise validation and complete rendezvous |
237 auto headers = AsHeaderList(headers_); | 238 auto headers = AsHeaderList(headers_); |
238 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 239 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
239 headers); | 240 headers); |
240 | 241 |
241 // Now initiate rendezvous. | 242 // Now initiate rendezvous. |
242 PushPromiseDelegate delegate(/*match=*/true); | 243 TestPushPromiseDelegate delegate(/*match=*/true); |
243 promised->HandleClientRequest(client_request_, &delegate); | 244 promised->HandleClientRequest(client_request_, &delegate); |
244 | 245 |
245 // Promise is gone | 246 // Promise is gone |
246 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); | 247 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); |
247 // Have a push stream | 248 // Have a push stream |
248 EXPECT_TRUE(delegate.rendezvous_fired()); | 249 EXPECT_TRUE(delegate.rendezvous_fired()); |
249 | 250 |
250 EXPECT_NE(delegate.rendezvous_stream(), nullptr); | 251 EXPECT_NE(delegate.rendezvous_stream(), nullptr); |
251 } | 252 } |
252 | 253 |
253 TEST_F(QuicClientPromisedInfoTest, PushPromiseWaitCancels) { | 254 TEST_F(QuicClientPromisedInfoTest, PushPromiseWaitCancels) { |
254 ReceivePromise(promise_id_); | 255 ReceivePromise(promise_id_); |
255 | 256 |
256 QuicClientPromisedInfo* promised = session_.GetPromisedById(promise_id_); | 257 QuicClientPromisedInfo* promised = session_.GetPromisedById(promise_id_); |
257 ASSERT_NE(promised, nullptr); | 258 ASSERT_NE(promised, nullptr); |
258 | 259 |
259 // Now initiate rendezvous. | 260 // Now initiate rendezvous. |
260 PushPromiseDelegate delegate(/*match=*/true); | 261 TestPushPromiseDelegate delegate(/*match=*/true); |
261 promised->HandleClientRequest(client_request_, &delegate); | 262 promised->HandleClientRequest(client_request_, &delegate); |
262 | 263 |
263 // Promise is still there, waiting for response. | 264 // Promise is still there, waiting for response. |
264 EXPECT_NE(session_.GetPromisedById(promise_id_), nullptr); | 265 EXPECT_NE(session_.GetPromisedById(promise_id_), nullptr); |
265 | 266 |
266 // Create response stream, but no data yet. | 267 // Create response stream, but no data yet. |
267 session_.GetOrCreateStream(promise_id_); | 268 session_.GetOrCreateStream(promise_id_); |
268 | 269 |
269 // Cancel the promised stream. | 270 // Cancel the promised stream. |
270 EXPECT_CALL(session_, CloseStream(promise_id_)); | 271 EXPECT_CALL(session_, CloseStream(promise_id_)); |
(...skipping 19 matching lines...) Expand all Loading... |
290 auto headers = AsHeaderList(headers_); | 291 auto headers = AsHeaderList(headers_); |
291 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 292 promise_stream->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
292 headers); | 293 headers); |
293 | 294 |
294 EXPECT_CALL(session_, CloseStream(promise_id_)); | 295 EXPECT_CALL(session_, CloseStream(promise_id_)); |
295 EXPECT_CALL(*connection_, | 296 EXPECT_CALL(*connection_, |
296 SendRstStream(promise_id_, QUIC_STREAM_PEER_GOING_AWAY, 0)); | 297 SendRstStream(promise_id_, QUIC_STREAM_PEER_GOING_AWAY, 0)); |
297 session_.SendRstStream(promise_id_, QUIC_STREAM_PEER_GOING_AWAY, 0); | 298 session_.SendRstStream(promise_id_, QUIC_STREAM_PEER_GOING_AWAY, 0); |
298 | 299 |
299 // Now initiate rendezvous. | 300 // Now initiate rendezvous. |
300 PushPromiseDelegate delegate(/*match=*/true); | 301 TestPushPromiseDelegate delegate(/*match=*/true); |
301 EXPECT_EQ(promised->HandleClientRequest(client_request_, &delegate), | 302 EXPECT_EQ(promised->HandleClientRequest(client_request_, &delegate), |
302 QUIC_FAILURE); | 303 QUIC_FAILURE); |
303 | 304 |
304 // Got an indication of the stream failure, client should retry | 305 // Got an indication of the stream failure, client should retry |
305 // request. | 306 // request. |
306 EXPECT_FALSE(delegate.rendezvous_fired()); | 307 EXPECT_FALSE(delegate.rendezvous_fired()); |
307 EXPECT_EQ(delegate.rendezvous_stream(), nullptr); | 308 EXPECT_EQ(delegate.rendezvous_stream(), nullptr); |
308 | 309 |
309 // Promise is gone | 310 // Promise is gone |
310 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); | 311 EXPECT_EQ(session_.GetPromisedById(promise_id_), nullptr); |
311 } | 312 } |
312 | 313 |
313 } // namespace | 314 } // namespace |
314 } // namespace test | 315 } // namespace test |
315 } // namespace net | 316 } // namespace net |
OLD | NEW |