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

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

Issue 2102253003: Make SpdyHeaderBlock non-copyable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iOS fix. Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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_session.h" 5 #include "net/tools/quic/quic_simple_server_session.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 namespace test { 59 namespace test {
60 namespace { 60 namespace {
61 typedef QuicSimpleServerSession::PromisedStreamInfo PromisedStreamInfo; 61 typedef QuicSimpleServerSession::PromisedStreamInfo PromisedStreamInfo;
62 } // namespace 62 } // namespace
63 63
64 class MockQuicHeadersStream : public QuicHeadersStream { 64 class MockQuicHeadersStream : public QuicHeadersStream {
65 public: 65 public:
66 explicit MockQuicHeadersStream(QuicSpdySession* session) 66 explicit MockQuicHeadersStream(QuicSpdySession* session)
67 : QuicHeadersStream(session) {} 67 : QuicHeadersStream(session) {}
68 68
69 MOCK_METHOD4(WritePushPromise, 69 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be
70 // mocked directly.
71 size_t WritePushPromise(QuicStreamId original_stream_id,
72 QuicStreamId promised_stream_id,
73 SpdyHeaderBlock headers,
74 QuicAckListenerInterface* ack_listener) override {
75 return WritePushPromiseMock(original_stream_id, promised_stream_id, headers,
76 ack_listener);
77 }
78 MOCK_METHOD4(WritePushPromiseMock,
70 size_t(QuicStreamId original_stream_id, 79 size_t(QuicStreamId original_stream_id,
71 QuicStreamId promised_stream_id, 80 QuicStreamId promised_stream_id,
72 SpdyHeaderBlock headers, 81 const SpdyHeaderBlock& headers,
73 QuicAckListenerInterface* ack_listener)); 82 QuicAckListenerInterface* ack_listener));
74 83
75 MOCK_METHOD5(WriteHeaders, 84 size_t WriteHeaders(QuicStreamId stream_id,
85 SpdyHeaderBlock headers,
86 bool fin,
87 SpdyPriority priority,
88 QuicAckListenerInterface* ack_listener) override {
89 return WriteHeadersMock(stream_id, headers, fin, priority, ack_listener);
90 }
91 MOCK_METHOD5(WriteHeadersMock,
76 size_t(QuicStreamId stream_id, 92 size_t(QuicStreamId stream_id,
77 SpdyHeaderBlock headers, 93 const SpdyHeaderBlock& headers,
78 bool fin, 94 bool fin,
79 SpdyPriority priority, 95 SpdyPriority priority,
80 QuicAckListenerInterface* ack_listener)); 96 QuicAckListenerInterface* ack_listener));
81 }; 97 };
82 98
83 class MockQuicCryptoServerStream : public QuicCryptoServerStream { 99 class MockQuicCryptoServerStream : public QuicCryptoServerStream {
84 public: 100 public:
85 explicit MockQuicCryptoServerStream( 101 explicit MockQuicCryptoServerStream(
86 const QuicCryptoServerConfig* crypto_config, 102 const QuicCryptoServerConfig* crypto_config,
87 QuicCompressedCertsCache* compressed_certs_cache, 103 QuicCompressedCertsCache* compressed_certs_cache,
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 string partial_push_resource_path = "/server_push_src"; 471 string partial_push_resource_path = "/server_push_src";
456 std::list<QuicInMemoryCache::ServerPushInfo> push_resources; 472 std::list<QuicInMemoryCache::ServerPushInfo> push_resources;
457 string scheme = "http"; 473 string scheme = "http";
458 for (unsigned int i = 1; i <= num_resources; ++i) { 474 for (unsigned int i = 1; i <= num_resources; ++i) {
459 QuicStreamId stream_id = i * 2; 475 QuicStreamId stream_id = i * 2;
460 string path = partial_push_resource_path + base::UintToString(i); 476 string path = partial_push_resource_path + base::UintToString(i);
461 string url = scheme + "://" + resource_host + path; 477 string url = scheme + "://" + resource_host + path;
462 GURL resource_url = GURL(url); 478 GURL resource_url = GURL(url);
463 string body; 479 string body;
464 GenerateBody(&body, body_size); 480 GenerateBody(&body, body_size);
465 SpdyHeaderBlock response_headers;
466 QuicInMemoryCache::GetInstance()->AddSimpleResponse(resource_host, path, 481 QuicInMemoryCache::GetInstance()->AddSimpleResponse(resource_host, path,
467 200, body); 482 200, body);
468 push_resources.push_back(QuicInMemoryCache::ServerPushInfo( 483 push_resources.push_back(QuicInMemoryCache::ServerPushInfo(
469 resource_url, response_headers, kDefaultPriority, body)); 484 resource_url, SpdyHeaderBlock(), kDefaultPriority, body));
470 // PUSH_PROMISED are sent for all the resources. 485 // PUSH_PROMISED are sent for all the resources.
471 EXPECT_CALL(*headers_stream_, WritePushPromise(kClientDataStreamId1, 486 EXPECT_CALL(
472 stream_id, _, nullptr)); 487 *headers_stream_,
488 WritePushPromiseMock(kClientDataStreamId1, stream_id, _, nullptr));
473 if (i <= kMaxStreamsForTest) { 489 if (i <= kMaxStreamsForTest) {
474 // |kMaxStreamsForTest| promised responses should be sent. 490 // |kMaxStreamsForTest| promised responses should be sent.
475 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_id, _, false, 491 EXPECT_CALL(
476 kDefaultPriority, nullptr)); 492 *headers_stream_,
493 WriteHeadersMock(stream_id, _, false, kDefaultPriority, nullptr));
477 // Since flow control window is smaller than response body, not the 494 // Since flow control window is smaller than response body, not the
478 // whole body will be sent. 495 // whole body will be sent.
479 EXPECT_CALL(*connection_, 496 EXPECT_CALL(*connection_,
480 SendStreamData(stream_id, _, 0, false, nullptr)) 497 SendStreamData(stream_id, _, 0, false, nullptr))
481 .WillOnce( 498 .WillOnce(
482 Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 499 Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
483 EXPECT_CALL(*connection_, SendBlocked(stream_id)); 500 EXPECT_CALL(*connection_, SendBlocked(stream_id));
484 } 501 }
485 } 502 }
486 session_->PromisePushResources(request_url, push_resources, 503 session_->PromisePushResources(request_url, push_resources,
(...skipping 17 matching lines...) Expand all
504 TEST_P(QuicSimpleServerSessionServerPushTest, 521 TEST_P(QuicSimpleServerSessionServerPushTest,
505 HandlePromisedPushRequestsAfterStreamDraining) { 522 HandlePromisedPushRequestsAfterStreamDraining) {
506 // Tests that after promised stream queued up, when an opened stream is marked 523 // Tests that after promised stream queued up, when an opened stream is marked
507 // draining, a queued promised stream will become open and send push response. 524 // draining, a queued promised stream will become open and send push response.
508 size_t num_resources = kMaxStreamsForTest + 1; 525 size_t num_resources = kMaxStreamsForTest + 1;
509 PromisePushResources(num_resources); 526 PromisePushResources(num_resources);
510 QuicStreamId next_out_going_stream_id = num_resources * 2; 527 QuicStreamId next_out_going_stream_id = num_resources * 2;
511 528
512 // After an open stream is marked draining, a new stream is expected to be 529 // After an open stream is marked draining, a new stream is expected to be
513 // created and a response sent on the stream. 530 // created and a response sent on the stream.
514 EXPECT_CALL(*headers_stream_, WriteHeaders(next_out_going_stream_id, _, false, 531 EXPECT_CALL(*headers_stream_,
515 kDefaultPriority, nullptr)); 532 WriteHeadersMock(next_out_going_stream_id, _, false,
533 kDefaultPriority, nullptr));
516 EXPECT_CALL(*connection_, 534 EXPECT_CALL(*connection_,
517 SendStreamData(next_out_going_stream_id, _, 0, false, nullptr)) 535 SendStreamData(next_out_going_stream_id, _, 0, false, nullptr))
518 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 536 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
519 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); 537 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id));
520 session_->StreamDraining(2); 538 session_->StreamDraining(2);
521 // Number of open outgoing streams should still be the same, because a new 539 // Number of open outgoing streams should still be the same, because a new
522 // stream is opened. And the queue should be empty. 540 // stream is opened. And the queue should be empty.
523 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); 541 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams());
524 } 542 }
525 543
(...skipping 12 matching lines...) Expand all
538 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); 556 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0);
539 EXPECT_CALL(*connection_, 557 EXPECT_CALL(*connection_,
540 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); 558 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0));
541 visitor_->OnRstStream(rst); 559 visitor_->OnRstStream(rst);
542 560
543 // When the first 2 streams becomes draining, the two queued up stream could 561 // When the first 2 streams becomes draining, the two queued up stream could
544 // be created. But since one of them was marked cancelled due to RST frame, 562 // be created. But since one of them was marked cancelled due to RST frame,
545 // only one queued resource will be sent out. 563 // only one queued resource will be sent out.
546 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; 564 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2;
547 InSequence s; 565 InSequence s;
548 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_not_reset, _, false, 566 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_not_reset, _, false,
549 kDefaultPriority, nullptr)); 567 kDefaultPriority, nullptr));
550 EXPECT_CALL(*connection_, 568 EXPECT_CALL(*connection_,
551 SendStreamData(stream_not_reset, _, 0, false, nullptr)) 569 SendStreamData(stream_not_reset, _, 0, false, nullptr))
552 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 570 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
553 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); 571 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset));
554 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_got_reset, _, false, 572 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_got_reset, _, false,
555 kDefaultPriority, nullptr)) 573 kDefaultPriority, nullptr))
556 .Times(0); 574 .Times(0);
557 575
558 session_->StreamDraining(2); 576 session_->StreamDraining(2);
559 session_->StreamDraining(4); 577 session_->StreamDraining(4);
560 } 578 }
561 579
562 TEST_P(QuicSimpleServerSessionServerPushTest, 580 TEST_P(QuicSimpleServerSessionServerPushTest,
563 CloseStreamToHandleMorePromisedStream) { 581 CloseStreamToHandleMorePromisedStream) {
564 // Tests that closing a open outgoing stream can trigger a promised resource 582 // Tests that closing a open outgoing stream can trigger a promised resource
565 // in the queue to be send out. 583 // in the queue to be send out.
566 size_t num_resources = kMaxStreamsForTest + 1; 584 size_t num_resources = kMaxStreamsForTest + 1;
567 PromisePushResources(num_resources); 585 PromisePushResources(num_resources);
568 QuicStreamId stream_to_open = num_resources * 2; 586 QuicStreamId stream_to_open = num_resources * 2;
569 587
570 // Resetting 1st open stream will close the stream and give space for extra 588 // Resetting 1st open stream will close the stream and give space for extra
571 // stream to be opened. 589 // stream to be opened.
572 QuicStreamId stream_got_reset = 2; 590 QuicStreamId stream_got_reset = 2;
573 EXPECT_CALL(*connection_, 591 EXPECT_CALL(*connection_,
574 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); 592 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _));
575 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_to_open, _, false, 593 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_to_open, _, false,
576 kDefaultPriority, nullptr)); 594 kDefaultPriority, nullptr));
577 EXPECT_CALL(*connection_, 595 EXPECT_CALL(*connection_,
578 SendStreamData(stream_to_open, _, 0, false, nullptr)) 596 SendStreamData(stream_to_open, _, 0, false, nullptr))
579 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 597 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
580 598
581 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); 599 EXPECT_CALL(*connection_, SendBlocked(stream_to_open));
582 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); 600 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0);
583 visitor_->OnRstStream(rst); 601 visitor_->OnRstStream(rst);
584 } 602 }
585 603
586 } // namespace 604 } // namespace
587 } // namespace test 605 } // namespace test
588 } // namespace net 606 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_session.cc ('k') | net/tools/quic/quic_simple_server_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698