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

Side by Side Diff: net/tools/quic/quic_simple_server_stream_test.cc

Issue 2518063007: Pass QuicInMemoryCache directly instead of using a singleton. (Closed)
Patch Set: Fix Cronet compile error Created 4 years 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/tools/quic/quic_simple_server_stream.cc ('k') | net/tools/quic/quic_simple_server_test.cc » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/tools/quic/quic_simple_server_stream.h" 5 #include "net/tools/quic/quic_simple_server_stream.h"
6 6
7 #include <list> 7 #include <list>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "net/quic/core/quic_connection.h" 14 #include "net/quic/core/quic_connection.h"
15 #include "net/quic/core/quic_flags.h" 15 #include "net/quic/core/quic_flags.h"
16 #include "net/quic/core/quic_protocol.h" 16 #include "net/quic/core/quic_protocol.h"
17 #include "net/quic/core/quic_utils.h" 17 #include "net/quic/core/quic_utils.h"
18 #include "net/quic/core/spdy_utils.h" 18 #include "net/quic/core/spdy_utils.h"
19 #include "net/quic/platform/api/quic_socket_address.h" 19 #include "net/quic/platform/api/quic_socket_address.h"
20 #include "net/quic/test_tools/crypto_test_utils.h" 20 #include "net/quic/test_tools/crypto_test_utils.h"
21 #include "net/quic/test_tools/quic_stream_peer.h" 21 #include "net/quic/test_tools/quic_stream_peer.h"
22 #include "net/quic/test_tools/quic_test_utils.h" 22 #include "net/quic/test_tools/quic_test_utils.h"
23 #include "net/test/gtest_util.h" 23 #include "net/test/gtest_util.h"
24 #include "net/tools/epoll_server/epoll_server.h" 24 #include "net/tools/epoll_server/epoll_server.h"
25 #include "net/tools/quic/quic_in_memory_cache.h" 25 #include "net/tools/quic/quic_in_memory_cache.h"
26 #include "net/tools/quic/quic_simple_server_session.h" 26 #include "net/tools/quic/quic_simple_server_session.h"
27 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h"
28 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
30 #include "url/gurl.h" 29 #include "url/gurl.h"
31 30
32 using base::StringPiece; 31 using base::StringPiece;
33 using net::test::MockQuicConnection; 32 using net::test::MockQuicConnection;
34 using net::test::MockQuicConnectionHelper; 33 using net::test::MockQuicConnectionHelper;
35 using net::test::MockQuicSpdySession; 34 using net::test::MockQuicSpdySession;
36 using net::test::QuicStreamPeer; 35 using net::test::QuicStreamPeer;
37 using net::test::SupportedVersions; 36 using net::test::SupportedVersions;
38 using net::test::kInitialSessionFlowControlWindowForTest; 37 using net::test::kInitialSessionFlowControlWindowForTest;
39 using net::test::kInitialStreamFlowControlWindowForTest; 38 using net::test::kInitialStreamFlowControlWindowForTest;
40 using std::string; 39 using std::string;
41 using testing::_; 40 using testing::_;
42 using testing::AnyNumber; 41 using testing::AnyNumber;
43 using testing::Invoke; 42 using testing::Invoke;
44 using testing::InvokeArgument; 43 using testing::InvokeArgument;
45 using testing::InSequence; 44 using testing::InSequence;
46 using testing::Return; 45 using testing::Return;
47 using testing::StrictMock; 46 using testing::StrictMock;
48 using testing::WithArgs; 47 using testing::WithArgs;
49 48
50 namespace net { 49 namespace net {
51 namespace test { 50 namespace test {
52 51
53 size_t kFakeFrameLen = 60; 52 size_t kFakeFrameLen = 60;
54 53
55 class QuicSimpleServerStreamPeer : public QuicSimpleServerStream { 54 class QuicSimpleServerStreamPeer : public QuicSimpleServerStream {
56 public: 55 public:
57 QuicSimpleServerStreamPeer(QuicStreamId stream_id, QuicSpdySession* session) 56 QuicSimpleServerStreamPeer(QuicStreamId stream_id,
58 : QuicSimpleServerStream(stream_id, session) {} 57 QuicSpdySession* session,
58 QuicInMemoryCache* in_memory_cache)
59 : QuicSimpleServerStream(stream_id, session, in_memory_cache) {}
59 60
60 ~QuicSimpleServerStreamPeer() override{}; 61 ~QuicSimpleServerStreamPeer() override{};
61 62
62 using QuicSimpleServerStream::SendResponse; 63 using QuicSimpleServerStream::SendResponse;
63 using QuicSimpleServerStream::SendErrorResponse; 64 using QuicSimpleServerStream::SendErrorResponse;
64 65
65 SpdyHeaderBlock* mutable_headers() { return &request_headers_; } 66 SpdyHeaderBlock* mutable_headers() { return &request_headers_; }
66 67
67 static void SendResponse(QuicSimpleServerStream* stream) { 68 static void SendResponse(QuicSimpleServerStream* stream) {
68 stream->SendResponse(); 69 stream->SendResponse();
(...skipping 18 matching lines...) Expand all
87 88
88 class MockQuicSimpleServerSession : public QuicSimpleServerSession { 89 class MockQuicSimpleServerSession : public QuicSimpleServerSession {
89 public: 90 public:
90 const size_t kMaxStreamsForTest = 100; 91 const size_t kMaxStreamsForTest = 100;
91 92
92 explicit MockQuicSimpleServerSession( 93 explicit MockQuicSimpleServerSession(
93 QuicConnection* connection, 94 QuicConnection* connection,
94 MockQuicSessionVisitor* owner, 95 MockQuicSessionVisitor* owner,
95 MockQuicCryptoServerStreamHelper* helper, 96 MockQuicCryptoServerStreamHelper* helper,
96 QuicCryptoServerConfig* crypto_config, 97 QuicCryptoServerConfig* crypto_config,
97 QuicCompressedCertsCache* compressed_certs_cache) 98 QuicCompressedCertsCache* compressed_certs_cache,
99 QuicInMemoryCache* in_memory_cache)
98 : QuicSimpleServerSession(DefaultQuicConfig(), 100 : QuicSimpleServerSession(DefaultQuicConfig(),
99 connection, 101 connection,
100 owner, 102 owner,
101 helper, 103 helper,
102 crypto_config, 104 crypto_config,
103 compressed_certs_cache) { 105 compressed_certs_cache,
106 in_memory_cache) {
104 set_max_open_incoming_streams(kMaxStreamsForTest); 107 set_max_open_incoming_streams(kMaxStreamsForTest);
105 set_max_open_outgoing_streams(kMaxStreamsForTest); 108 set_max_open_outgoing_streams(kMaxStreamsForTest);
106 ON_CALL(*this, WritevData(_, _, _, _, _, _)) 109 ON_CALL(*this, WritevData(_, _, _, _, _, _))
107 .WillByDefault(testing::Return(QuicConsumedData(0, false))); 110 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
108 } 111 }
109 112
110 ~MockQuicSimpleServerSession() override {} 113 ~MockQuicSimpleServerSession() override {}
111 114
112 MOCK_METHOD3(OnConnectionClosed, 115 MOCK_METHOD3(OnConnectionClosed,
113 void(QuicErrorCode error, 116 void(QuicErrorCode error,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 crypto_config_(new QuicCryptoServerConfig( 190 crypto_config_(new QuicCryptoServerConfig(
188 QuicCryptoServerConfig::TESTING, 191 QuicCryptoServerConfig::TESTING,
189 QuicRandom::GetInstance(), 192 QuicRandom::GetInstance(),
190 ::net::test::CryptoTestUtils::ProofSourceForTesting())), 193 ::net::test::CryptoTestUtils::ProofSourceForTesting())),
191 compressed_certs_cache_( 194 compressed_certs_cache_(
192 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), 195 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize),
193 session_(connection_, 196 session_(connection_,
194 &session_owner_, 197 &session_owner_,
195 &session_helper_, 198 &session_helper_,
196 crypto_config_.get(), 199 crypto_config_.get(),
197 &compressed_certs_cache_), 200 &compressed_certs_cache_,
201 &in_memory_cache_),
198 body_("hello world") { 202 body_("hello world") {
199 header_list_.OnHeaderBlockStart(); 203 header_list_.OnHeaderBlockStart();
200 header_list_.OnHeader(":authority", "www.google.com"); 204 header_list_.OnHeader(":authority", "www.google.com");
201 header_list_.OnHeader(":path", "/"); 205 header_list_.OnHeader(":path", "/");
202 header_list_.OnHeader(":method", "POST"); 206 header_list_.OnHeader(":method", "POST");
203 header_list_.OnHeader(":version", "HTTP/1.1"); 207 header_list_.OnHeader(":version", "HTTP/1.1");
204 header_list_.OnHeader("content-length", "11"); 208 header_list_.OnHeader("content-length", "11");
205 header_list_.OnHeaderBlockEnd(128); 209 header_list_.OnHeaderBlockEnd(128);
206 210
207 // New streams rely on having the peer's flow control receive window 211 // New streams rely on having the peer's flow control receive window
208 // negotiated in the config. 212 // negotiated in the config.
209 session_.config()->SetInitialStreamFlowControlWindowToSend( 213 session_.config()->SetInitialStreamFlowControlWindowToSend(
210 kInitialStreamFlowControlWindowForTest); 214 kInitialStreamFlowControlWindowForTest);
211 session_.config()->SetInitialSessionFlowControlWindowToSend( 215 session_.config()->SetInitialSessionFlowControlWindowToSend(
212 kInitialSessionFlowControlWindowForTest); 216 kInitialSessionFlowControlWindowForTest);
213 stream_ = new QuicSimpleServerStreamPeer(::net::test::kClientDataStreamId1, 217 stream_ = new QuicSimpleServerStreamPeer(::net::test::kClientDataStreamId1,
214 &session_); 218 &session_, &in_memory_cache_);
215 // Register stream_ in dynamic_stream_map_ and pass ownership to session_. 219 // Register stream_ in dynamic_stream_map_ and pass ownership to session_.
216 session_.ActivateStream(base::WrapUnique(stream_)); 220 session_.ActivateStream(base::WrapUnique(stream_));
217
218 QuicInMemoryCachePeer::ResetForTests();
219 }
220
221 ~QuicSimpleServerStreamTest() override {
222 QuicInMemoryCachePeer::ResetForTests();
223 } 221 }
224 222
225 const string& StreamBody() { 223 const string& StreamBody() {
226 return QuicSimpleServerStreamPeer::body(stream_); 224 return QuicSimpleServerStreamPeer::body(stream_);
227 } 225 }
228 226
229 string StreamHeadersValue(const string& key) { 227 string StreamHeadersValue(const string& key) {
230 return (*stream_->mutable_headers())[key].as_string(); 228 return (*stream_->mutable_headers())[key].as_string();
231 } 229 }
232 230
233 SpdyHeaderBlock response_headers_; 231 SpdyHeaderBlock response_headers_;
234 MockQuicConnectionHelper helper_; 232 MockQuicConnectionHelper helper_;
235 MockAlarmFactory alarm_factory_; 233 MockAlarmFactory alarm_factory_;
236 StrictMock<MockQuicConnection>* connection_; 234 StrictMock<MockQuicConnection>* connection_;
237 StrictMock<MockQuicSessionVisitor> session_owner_; 235 StrictMock<MockQuicSessionVisitor> session_owner_;
238 StrictMock<MockQuicCryptoServerStreamHelper> session_helper_; 236 StrictMock<MockQuicCryptoServerStreamHelper> session_helper_;
239 std::unique_ptr<QuicCryptoServerConfig> crypto_config_; 237 std::unique_ptr<QuicCryptoServerConfig> crypto_config_;
240 QuicCompressedCertsCache compressed_certs_cache_; 238 QuicCompressedCertsCache compressed_certs_cache_;
239 QuicInMemoryCache in_memory_cache_;
241 StrictMock<MockQuicSimpleServerSession> session_; 240 StrictMock<MockQuicSimpleServerSession> session_;
242 QuicSimpleServerStreamPeer* stream_; // Owned by session_. 241 QuicSimpleServerStreamPeer* stream_; // Owned by session_.
243 string headers_string_; 242 string headers_string_;
244 string body_; 243 string body_;
245 QuicHeaderList header_list_; 244 QuicHeaderList header_list_;
246 }; 245 };
247 246
248 INSTANTIATE_TEST_CASE_P(Tests, 247 INSTANTIATE_TEST_CASE_P(Tests,
249 QuicSimpleServerStreamTest, 248 QuicSimpleServerStreamTest,
250 ::testing::ValuesIn(AllSupportedVersions())); 249 ::testing::ValuesIn(AllSupportedVersions()));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 (*request_headers)[":path"] = "/bar"; 317 (*request_headers)[":path"] = "/bar";
319 (*request_headers)[":authority"] = "www.google.com"; 318 (*request_headers)[":authority"] = "www.google.com";
320 (*request_headers)[":version"] = "HTTP/1.1"; 319 (*request_headers)[":version"] = "HTTP/1.1";
321 (*request_headers)[":method"] = "GET"; 320 (*request_headers)[":method"] = "GET";
322 321
323 response_headers_[":version"] = "HTTP/1.1"; 322 response_headers_[":version"] = "HTTP/1.1";
324 // HTTP/2 only supports integer responsecode, so "200 OK" is illegal. 323 // HTTP/2 only supports integer responsecode, so "200 OK" is illegal.
325 response_headers_[":status"] = "200 OK"; 324 response_headers_[":status"] = "200 OK";
326 response_headers_["content-length"] = "5"; 325 response_headers_["content-length"] = "5";
327 string body = "Yummm"; 326 string body = "Yummm";
328 QuicInMemoryCache::GetInstance()->AddResponse( 327 in_memory_cache_.AddResponse("www.google.com", "/bar",
329 "www.google.com", "/bar", std::move(response_headers_), body); 328 std::move(response_headers_), body);
330 329
331 stream_->set_fin_received(true); 330 stream_->set_fin_received(true);
332 331
333 InSequence s; 332 InSequence s;
334 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, nullptr)); 333 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, nullptr));
335 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) 334 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _))
336 .Times(1) 335 .Times(1)
337 .WillOnce(Return(QuicConsumedData( 336 .WillOnce(Return(QuicConsumedData(
338 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); 337 strlen(QuicSimpleServerStream::kErrorResponseBody), true)));
339 338
340 QuicSimpleServerStreamPeer::SendResponse(stream_); 339 QuicSimpleServerStreamPeer::SendResponse(stream_);
341 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); 340 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
342 EXPECT_TRUE(stream_->reading_stopped()); 341 EXPECT_TRUE(stream_->reading_stopped());
343 EXPECT_TRUE(stream_->write_side_closed()); 342 EXPECT_TRUE(stream_->write_side_closed());
344 } 343 }
345 344
346 TEST_P(QuicSimpleServerStreamTest, SendResponseWithIllegalResponseStatus2) { 345 TEST_P(QuicSimpleServerStreamTest, SendResponseWithIllegalResponseStatus2) {
347 // Send an illegal response with response status not supported by HTTP/2. 346 // Send an illegal response with response status not supported by HTTP/2.
348 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); 347 SpdyHeaderBlock* request_headers = stream_->mutable_headers();
349 (*request_headers)[":path"] = "/bar"; 348 (*request_headers)[":path"] = "/bar";
350 (*request_headers)[":authority"] = "www.google.com"; 349 (*request_headers)[":authority"] = "www.google.com";
351 (*request_headers)[":version"] = "HTTP/1.1"; 350 (*request_headers)[":version"] = "HTTP/1.1";
352 (*request_headers)[":method"] = "GET"; 351 (*request_headers)[":method"] = "GET";
353 352
354 response_headers_[":version"] = "HTTP/1.1"; 353 response_headers_[":version"] = "HTTP/1.1";
355 // HTTP/2 only supports 3-digit-integer, so "+200" is illegal. 354 // HTTP/2 only supports 3-digit-integer, so "+200" is illegal.
356 response_headers_[":status"] = "+200"; 355 response_headers_[":status"] = "+200";
357 response_headers_["content-length"] = "5"; 356 response_headers_["content-length"] = "5";
358 string body = "Yummm"; 357 string body = "Yummm";
359 QuicInMemoryCache::GetInstance()->AddResponse( 358 in_memory_cache_.AddResponse("www.google.com", "/bar",
360 "www.google.com", "/bar", std::move(response_headers_), body); 359 std::move(response_headers_), body);
361 360
362 stream_->set_fin_received(true); 361 stream_->set_fin_received(true);
363 362
364 InSequence s; 363 InSequence s;
365 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, nullptr)); 364 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, nullptr));
366 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) 365 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _))
367 .Times(1) 366 .Times(1)
368 .WillOnce(Return(QuicConsumedData( 367 .WillOnce(Return(QuicConsumedData(
369 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); 368 strlen(QuicSimpleServerStream::kErrorResponseBody), true)));
370 369
371 QuicSimpleServerStreamPeer::SendResponse(stream_); 370 QuicSimpleServerStreamPeer::SendResponse(stream_);
372 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); 371 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
373 EXPECT_TRUE(stream_->reading_stopped()); 372 EXPECT_TRUE(stream_->reading_stopped());
374 EXPECT_TRUE(stream_->write_side_closed()); 373 EXPECT_TRUE(stream_->write_side_closed());
375 } 374 }
376 375
377 TEST_P(QuicSimpleServerStreamTest, SendPushResponseWith404Response) { 376 TEST_P(QuicSimpleServerStreamTest, SendPushResponseWith404Response) {
378 // Create a new promised stream with even id(). 377 // Create a new promised stream with even id().
379 QuicSimpleServerStreamPeer* promised_stream = 378 QuicSimpleServerStreamPeer* promised_stream =
380 new QuicSimpleServerStreamPeer(2, &session_); 379 new QuicSimpleServerStreamPeer(2, &session_, &in_memory_cache_);
381 session_.ActivateStream(base::WrapUnique(promised_stream)); 380 session_.ActivateStream(base::WrapUnique(promised_stream));
382 381
383 // Send a push response with response status 404, which will be regarded as 382 // Send a push response with response status 404, which will be regarded as
384 // invalid server push response. 383 // invalid server push response.
385 SpdyHeaderBlock* request_headers = promised_stream->mutable_headers(); 384 SpdyHeaderBlock* request_headers = promised_stream->mutable_headers();
386 (*request_headers)[":path"] = "/bar"; 385 (*request_headers)[":path"] = "/bar";
387 (*request_headers)[":authority"] = "www.google.com"; 386 (*request_headers)[":authority"] = "www.google.com";
388 (*request_headers)[":version"] = "HTTP/1.1"; 387 (*request_headers)[":version"] = "HTTP/1.1";
389 (*request_headers)[":method"] = "GET"; 388 (*request_headers)[":method"] = "GET";
390 389
391 response_headers_[":version"] = "HTTP/1.1"; 390 response_headers_[":version"] = "HTTP/1.1";
392 response_headers_[":status"] = "404"; 391 response_headers_[":status"] = "404";
393 response_headers_["content-length"] = "8"; 392 response_headers_["content-length"] = "8";
394 string body = "NotFound"; 393 string body = "NotFound";
395 QuicInMemoryCache::GetInstance()->AddResponse( 394 in_memory_cache_.AddResponse("www.google.com", "/bar",
396 "www.google.com", "/bar", std::move(response_headers_), body); 395 std::move(response_headers_), body);
397 396
398 InSequence s; 397 InSequence s;
399 EXPECT_CALL(session_, 398 EXPECT_CALL(session_,
400 SendRstStream(promised_stream->id(), QUIC_STREAM_CANCELLED, 0)); 399 SendRstStream(promised_stream->id(), QUIC_STREAM_CANCELLED, 0));
401 400
402 QuicSimpleServerStreamPeer::SendResponse(promised_stream); 401 QuicSimpleServerStreamPeer::SendResponse(promised_stream);
403 } 402 }
404 403
405 TEST_P(QuicSimpleServerStreamTest, SendResponseWithValidHeaders) { 404 TEST_P(QuicSimpleServerStreamTest, SendResponseWithValidHeaders) {
406 // Add a request and response with valid headers. 405 // Add a request and response with valid headers.
407 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); 406 SpdyHeaderBlock* request_headers = stream_->mutable_headers();
408 (*request_headers)[":path"] = "/bar"; 407 (*request_headers)[":path"] = "/bar";
409 (*request_headers)[":authority"] = "www.google.com"; 408 (*request_headers)[":authority"] = "www.google.com";
410 (*request_headers)[":version"] = "HTTP/1.1"; 409 (*request_headers)[":version"] = "HTTP/1.1";
411 (*request_headers)[":method"] = "GET"; 410 (*request_headers)[":method"] = "GET";
412 411
413 response_headers_[":version"] = "HTTP/1.1"; 412 response_headers_[":version"] = "HTTP/1.1";
414 response_headers_[":status"] = "200"; 413 response_headers_[":status"] = "200";
415 response_headers_["content-length"] = "5"; 414 response_headers_["content-length"] = "5";
416 string body = "Yummm"; 415 string body = "Yummm";
417 QuicInMemoryCache::GetInstance()->AddResponse( 416 in_memory_cache_.AddResponse("www.google.com", "/bar",
418 "www.google.com", "/bar", std::move(response_headers_), body); 417 std::move(response_headers_), body);
419 stream_->set_fin_received(true); 418 stream_->set_fin_received(true);
420 419
421 InSequence s; 420 InSequence s;
422 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, nullptr)); 421 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, nullptr));
423 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) 422 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _))
424 .Times(1) 423 .Times(1)
425 .WillOnce(Return(QuicConsumedData(body.length(), true))); 424 .WillOnce(Return(QuicConsumedData(body.length(), true)));
426 425
427 QuicSimpleServerStreamPeer::SendResponse(stream_); 426 QuicSimpleServerStreamPeer::SendResponse(stream_);
428 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); 427 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
429 EXPECT_TRUE(stream_->reading_stopped()); 428 EXPECT_TRUE(stream_->reading_stopped());
430 EXPECT_TRUE(stream_->write_side_closed()); 429 EXPECT_TRUE(stream_->write_side_closed());
431 } 430 }
432 431
433 TEST_P(QuicSimpleServerStreamTest, SendReponseWithPushResources) { 432 TEST_P(QuicSimpleServerStreamTest, SendReponseWithPushResources) {
434 // Tests that if a reponse has push resources to be send, SendResponse() will 433 // Tests that if a reponse has push resources to be send, SendResponse() will
435 // call PromisePushResources() to handle these resources. 434 // call PromisePushResources() to handle these resources.
436 435
437 // Add a request and response with valid headers into cache. 436 // Add a request and response with valid headers into cache.
438 string host = "www.google.com"; 437 string host = "www.google.com";
439 string request_path = "/foo"; 438 string request_path = "/foo";
440 string body = "Yummm"; 439 string body = "Yummm";
441 string url = host + "/bar"; 440 string url = host + "/bar";
442 QuicInMemoryCache::ServerPushInfo push_info(GURL(url), SpdyHeaderBlock(), 441 QuicInMemoryCache::ServerPushInfo push_info(GURL(url), SpdyHeaderBlock(),
443 kDefaultPriority, "Push body"); 442 kDefaultPriority, "Push body");
444 std::list<QuicInMemoryCache::ServerPushInfo> push_resources; 443 std::list<QuicInMemoryCache::ServerPushInfo> push_resources;
445 push_resources.push_back(push_info); 444 push_resources.push_back(push_info);
446 QuicInMemoryCache::GetInstance()->AddSimpleResponseWithServerPushResources( 445 in_memory_cache_.AddSimpleResponseWithServerPushResources(
447 host, request_path, 200, body, push_resources); 446 host, request_path, 200, body, push_resources);
448 447
449 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); 448 SpdyHeaderBlock* request_headers = stream_->mutable_headers();
450 (*request_headers)[":path"] = request_path; 449 (*request_headers)[":path"] = request_path;
451 (*request_headers)[":authority"] = host; 450 (*request_headers)[":authority"] = host;
452 (*request_headers)[":version"] = "HTTP/1.1"; 451 (*request_headers)[":version"] = "HTTP/1.1";
453 (*request_headers)[":method"] = "GET"; 452 (*request_headers)[":method"] = "GET";
454 453
455 stream_->set_fin_received(true); 454 stream_->set_fin_received(true);
456 InSequence s; 455 InSequence s;
(...skipping 17 matching lines...) Expand all
474 } 473 }
475 474
476 TEST_P(QuicSimpleServerStreamTest, PushResponseOnServerInitiatedStream) { 475 TEST_P(QuicSimpleServerStreamTest, PushResponseOnServerInitiatedStream) {
477 // Tests that PushResponse() should take the given headers as request headers 476 // Tests that PushResponse() should take the given headers as request headers
478 // and fetch response from cache, and send it out. 477 // and fetch response from cache, and send it out.
479 478
480 // Create a stream with even stream id and test against this stream. 479 // Create a stream with even stream id and test against this stream.
481 const QuicStreamId kServerInitiatedStreamId = 2; 480 const QuicStreamId kServerInitiatedStreamId = 2;
482 // Create a server initiated stream and pass it to session_. 481 // Create a server initiated stream and pass it to session_.
483 QuicSimpleServerStreamPeer* server_initiated_stream = 482 QuicSimpleServerStreamPeer* server_initiated_stream =
484 new QuicSimpleServerStreamPeer(kServerInitiatedStreamId, &session_); 483 new QuicSimpleServerStreamPeer(kServerInitiatedStreamId, &session_,
484 &in_memory_cache_);
485 session_.ActivateStream(base::WrapUnique(server_initiated_stream)); 485 session_.ActivateStream(base::WrapUnique(server_initiated_stream));
486 486
487 const string kHost = "www.foo.com"; 487 const string kHost = "www.foo.com";
488 const string kPath = "/bar"; 488 const string kPath = "/bar";
489 SpdyHeaderBlock headers; 489 SpdyHeaderBlock headers;
490 headers[":path"] = kPath; 490 headers[":path"] = kPath;
491 headers[":authority"] = kHost; 491 headers[":authority"] = kHost;
492 headers[":version"] = "HTTP/1.1"; 492 headers[":version"] = "HTTP/1.1";
493 headers[":method"] = "GET"; 493 headers[":method"] = "GET";
494 494
495 response_headers_[":version"] = "HTTP/1.1"; 495 response_headers_[":version"] = "HTTP/1.1";
496 response_headers_[":status"] = "200"; 496 response_headers_[":status"] = "200";
497 response_headers_["content-length"] = "5"; 497 response_headers_["content-length"] = "5";
498 const string kBody = "Hello"; 498 const string kBody = "Hello";
499 QuicInMemoryCache::GetInstance()->AddResponse( 499 in_memory_cache_.AddResponse(kHost, kPath, std::move(response_headers_),
500 kHost, kPath, std::move(response_headers_), kBody); 500 kBody);
501 501
502 // Call PushResponse() should trigger stream to fetch response from cache 502 // Call PushResponse() should trigger stream to fetch response from cache
503 // and send it back. 503 // and send it back.
504 EXPECT_CALL(session_, 504 EXPECT_CALL(session_,
505 WriteHeadersMock(kServerInitiatedStreamId, _, false, 505 WriteHeadersMock(kServerInitiatedStreamId, _, false,
506 server_initiated_stream->priority(), nullptr)); 506 server_initiated_stream->priority(), nullptr));
507 EXPECT_CALL(session_, WritevData(_, kServerInitiatedStreamId, _, _, _, _)) 507 EXPECT_CALL(session_, WritevData(_, kServerInitiatedStreamId, _, _, _, _))
508 .Times(1) 508 .Times(1)
509 .WillOnce(Return(QuicConsumedData(kBody.size(), true))); 509 .WillOnce(Return(QuicConsumedData(kBody.size(), true)));
510 server_initiated_stream->PushResponse(std::move(headers)); 510 server_initiated_stream->PushResponse(std::move(headers));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 }; 641 };
642 StringPiece data(arr, arraysize(arr)); 642 StringPiece data(arr, arraysize(arr));
643 QuicStreamFrame frame(stream_->id(), true, 0, data); 643 QuicStreamFrame frame(stream_->id(), true, 0, data);
644 // Verify that we don't crash when we get a invalid headers in stream frame. 644 // Verify that we don't crash when we get a invalid headers in stream frame.
645 stream_->OnStreamFrame(frame); 645 stream_->OnStreamFrame(frame);
646 } 646 }
647 647
648 } // namespace 648 } // namespace
649 } // namespace test 649 } // namespace test
650 } // namespace net 650 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_stream.cc ('k') | net/tools/quic/quic_simple_server_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698