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

Side by Side Diff: net/quic/quartc/quartc_stream_test.cc

Issue 2487613002: Landing Recent QUIC changes until 12:43 PM, Nov 5, 2016 UTC+8 (Closed)
Patch Set: Created 4 years, 1 month 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/quic/quartc/quartc_stream.cc ('k') | net/quic/test_tools/quic_session_peer.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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/quartc/quartc_stream.h" 5 #include "net/quic/quartc/quartc_stream.h"
6 6
7 #include "base/threading/thread_task_runner_handle.h" 7 #include "base/threading/thread_task_runner_handle.h"
8 #include "net/quic/core/crypto/quic_random.h" 8 #include "net/quic/core/crypto/quic_random.h"
9 #include "net/quic/core/quic_session.h" 9 #include "net/quic/core/quic_session.h"
10 #include "net/quic/core/quic_simple_buffer_allocator.h" 10 #include "net/quic/core/quic_simple_buffer_allocator.h"
11 #include "net/quic/quartc/quartc_alarm_factory.h" 11 #include "net/quic/quartc/quartc_alarm_factory.h"
12 #include "net/quic/quartc/quartc_stream_interface.h" 12 #include "net/quic/quartc/quartc_stream_interface.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace net { 15 namespace net {
16 namespace test { 16 namespace test {
17 namespace { 17 namespace {
18 18
19 static const SpdyPriority kDefaultPriority = 3; 19 static const SpdyPriority kDefaultPriority = 3;
20 static const QuicStreamId kStreamId = 5; 20 static const QuicStreamId kStreamId = 5;
21 static const QuartcStreamInterface::WriteParameters kDefaultParam; 21 static const QuartcStreamInterface::WriteParameters kDefaultParam;
22 22
23 // MockQuicSession that does not create streams and writes data from 23 // MockQuicSession that does not create streams and writes data from
24 // ReliableQuicStream to a string. 24 // QuicStream to a string.
25 class MockQuicSession : public QuicSession { 25 class MockQuicSession : public QuicSession {
26 public: 26 public:
27 MockQuicSession(QuicConnection* connection, 27 MockQuicSession(QuicConnection* connection,
28 const QuicConfig& config, 28 const QuicConfig& config,
29 std::string* write_buffer) 29 std::string* write_buffer)
30 : QuicSession(connection, nullptr /*visitor*/, config), 30 : QuicSession(connection, nullptr /*visitor*/, config),
31 write_buffer_(write_buffer) {} 31 write_buffer_(write_buffer) {}
32 32
33 // Writes outgoing data from ReliableQuicStream to a string. 33 // Writes outgoing data from QuicStream to a string.
34 QuicConsumedData WritevData( 34 QuicConsumedData WritevData(
35 ReliableQuicStream* stream, 35 QuicStream* stream,
36 QuicStreamId id, 36 QuicStreamId id,
37 QuicIOVector iovector, 37 QuicIOVector iovector,
38 QuicStreamOffset offset, 38 QuicStreamOffset offset,
39 bool fin, 39 bool fin,
40 QuicAckListenerInterface* ack_notifier_delegate) override { 40 QuicAckListenerInterface* ack_notifier_delegate) override {
41 if (!writable_) { 41 if (!writable_) {
42 return QuicConsumedData(0, false); 42 return QuicConsumedData(0, false);
43 } 43 }
44 44
45 const char* data = reinterpret_cast<const char*>(iovector.iov->iov_base); 45 const char* data = reinterpret_cast<const char*>(iovector.iov->iov_base);
46 size_t len = iovector.total_length; 46 size_t len = iovector.total_length;
47 write_buffer_->append(data, len); 47 write_buffer_->append(data, len);
48 return QuicConsumedData(len, fin); 48 return QuicConsumedData(len, fin);
49 } 49 }
50 50
51 QuartcStream* CreateIncomingDynamicStream(QuicStreamId id) override { 51 QuartcStream* CreateIncomingDynamicStream(QuicStreamId id) override {
52 return nullptr; 52 return nullptr;
53 } 53 }
54 54
55 QuartcStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { 55 QuartcStream* CreateOutgoingDynamicStream(SpdyPriority priority) override {
56 return nullptr; 56 return nullptr;
57 } 57 }
58 58
59 QuicCryptoStream* GetCryptoStream() override { return nullptr; } 59 QuicCryptoStream* GetCryptoStream() override { return nullptr; }
60 60
61 // Called by ReliableQuicStream when they want to close stream. 61 // Called by QuicStream when they want to close stream.
62 void SendRstStream(QuicStreamId id, 62 void SendRstStream(QuicStreamId id,
63 QuicRstStreamErrorCode error, 63 QuicRstStreamErrorCode error,
64 QuicStreamOffset bytes_written) override {} 64 QuicStreamOffset bytes_written) override {}
65 65
66 // Sets whether data is written to buffer, or else if this is write blocked. 66 // Sets whether data is written to buffer, or else if this is write blocked.
67 void set_writable(bool writable) { writable_ = writable; } 67 void set_writable(bool writable) { writable_ = writable; }
68 68
69 // Tracks whether the stream is write blocked and its priority. 69 // Tracks whether the stream is write blocked and its priority.
70 void RegisterReliableStream(QuicStreamId stream_id, SpdyPriority priority) { 70 void RegisterReliableStream(QuicStreamId stream_id, SpdyPriority priority) {
71 write_blocked_streams()->RegisterStream(stream_id, priority); 71 write_blocked_streams()->RegisterStream(stream_id, priority);
72 } 72 }
73 73
74 // The session take ownership of the stream. 74 // The session take ownership of the stream.
75 void ActivateReliableStream(std::unique_ptr<ReliableQuicStream> stream) { 75 void ActivateReliableStream(std::unique_ptr<QuicStream> stream) {
76 ActivateStream(std::move(stream)); 76 ActivateStream(std::move(stream));
77 } 77 }
78 78
79 private: 79 private:
80 // Stores written data from ReliableQuicStreamAdapter. 80 // Stores written data from ReliableQuicStreamAdapter.
81 std::string* write_buffer_; 81 std::string* write_buffer_;
82 // Whether data is written to write_buffer_. 82 // Whether data is written to write_buffer_.
83 bool writable_ = true; 83 bool writable_ = true;
84 }; 84 };
85 85
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void OnClose(QuartcStreamInterface* stream, int error_code) override { 129 void OnClose(QuartcStreamInterface* stream, int error_code) override {
130 closed_ = true; 130 closed_ = true;
131 } 131 }
132 132
133 bool closed() { return closed_; } 133 bool closed() { return closed_; }
134 134
135 int queued_bytes_amount() { return queued_bytes_amount_; } 135 int queued_bytes_amount() { return queued_bytes_amount_; }
136 136
137 protected: 137 protected:
138 uint32_t id_; 138 uint32_t id_;
139 // Data read by the ReliableQuicStream. 139 // Data read by the QuicStream.
140 std::string& read_buffer_; 140 std::string& read_buffer_;
141 // Whether the ReliableQuicStream is closed. 141 // Whether the QuicStream is closed.
142 bool closed_ = false; 142 bool closed_ = false;
143 int queued_bytes_amount_ = -1; 143 int queued_bytes_amount_ = -1;
144 }; 144 };
145 145
146 class QuartcStreamTest : public ::testing::Test, 146 class QuartcStreamTest : public ::testing::Test,
147 public QuicConnectionHelperInterface { 147 public QuicConnectionHelperInterface {
148 public: 148 public:
149 void CreateReliableQuicStream() { 149 void CreateReliableQuicStream() {
150 // Arbitrary values for QuicConnection. 150 // Arbitrary values for QuicConnection.
151 Perspective perspective = Perspective::IS_SERVER; 151 Perspective perspective = Perspective::IS_SERVER;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 TEST_F(QuartcStreamTest, CloseStream) { 253 TEST_F(QuartcStreamTest, CloseStream) {
254 CreateReliableQuicStream(); 254 CreateReliableQuicStream();
255 EXPECT_FALSE(mock_stream_delegate_->closed()); 255 EXPECT_FALSE(mock_stream_delegate_->closed());
256 stream_->OnClose(); 256 stream_->OnClose();
257 EXPECT_TRUE(mock_stream_delegate_->closed()); 257 EXPECT_TRUE(mock_stream_delegate_->closed());
258 } 258 }
259 259
260 } // namespace 260 } // namespace
261 } // namespace test 261 } // namespace test
262 } // namespace net 262 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quartc/quartc_stream.cc ('k') | net/quic/test_tools/quic_session_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698