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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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_test_util_common.cc ('k') | net/ssl/channel_id_service.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/spdy/spdy_write_queue.h" 5 #include "net/spdy/spdy_write_queue.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <cstring> 8 #include <cstring>
9 #include <string> 9 #include <string>
10 #include <utility>
10 11
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "net/base/request_priority.h" 15 #include "net/base/request_priority.h"
15 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
16 #include "net/spdy/spdy_buffer_producer.h" 17 #include "net/spdy/spdy_buffer_producer.h"
17 #include "net/spdy/spdy_stream.h" 18 #include "net/spdy/spdy_stream.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Producer whose produced buffer will enqueue yet another buffer into the 52 // Producer whose produced buffer will enqueue yet another buffer into the
52 // SpdyWriteQueue upon destruction. 53 // SpdyWriteQueue upon destruction.
53 class RequeingBufferProducer : public SpdyBufferProducer { 54 class RequeingBufferProducer : public SpdyBufferProducer {
54 public: 55 public:
55 RequeingBufferProducer(SpdyWriteQueue* queue) { 56 RequeingBufferProducer(SpdyWriteQueue* queue) {
56 buffer_.reset(new SpdyBuffer(kOriginal, arraysize(kOriginal))); 57 buffer_.reset(new SpdyBuffer(kOriginal, arraysize(kOriginal)));
57 buffer_->AddConsumeCallback( 58 buffer_->AddConsumeCallback(
58 base::Bind(RequeingBufferProducer::ConsumeCallback, queue)); 59 base::Bind(RequeingBufferProducer::ConsumeCallback, queue));
59 } 60 }
60 61
61 scoped_ptr<SpdyBuffer> ProduceBuffer() override { return buffer_.Pass(); } 62 scoped_ptr<SpdyBuffer> ProduceBuffer() override { return std::move(buffer_); }
62 63
63 static void ConsumeCallback(SpdyWriteQueue* queue, 64 static void ConsumeCallback(SpdyWriteQueue* queue,
64 size_t size, 65 size_t size,
65 SpdyBuffer::ConsumeSource source) { 66 SpdyBuffer::ConsumeSource source) {
66 scoped_ptr<SpdyBufferProducer> producer( 67 scoped_ptr<SpdyBufferProducer> producer(
67 new SimpleBufferProducer(scoped_ptr<SpdyBuffer>( 68 new SimpleBufferProducer(scoped_ptr<SpdyBuffer>(
68 new SpdyBuffer(kRequeued, arraysize(kRequeued))))); 69 new SpdyBuffer(kRequeued, arraysize(kRequeued)))));
69 70
70 queue->Enqueue( 71 queue->Enqueue(MEDIUM, RST_STREAM, std::move(producer),
71 MEDIUM, RST_STREAM, producer.Pass(), base::WeakPtr<SpdyStream>()); 72 base::WeakPtr<SpdyStream>());
72 } 73 }
73 74
74 private: 75 private:
75 scoped_ptr<SpdyBuffer> buffer_; 76 scoped_ptr<SpdyBuffer> buffer_;
76 }; 77 };
77 78
78 // Produces a frame with the given producer and returns a copy of its 79 // Produces a frame with the given producer and returns a copy of its
79 // data as a string. 80 // data as a string.
80 std::string ProducerToString(scoped_ptr<SpdyBufferProducer> producer) { 81 std::string ProducerToString(scoped_ptr<SpdyBufferProducer> producer) {
81 scoped_ptr<SpdyBuffer> buffer = producer->ProduceBuffer(); 82 scoped_ptr<SpdyBuffer> buffer = producer->ProduceBuffer();
82 return std::string(buffer->GetRemainingData(), buffer->GetRemainingSize()); 83 return std::string(buffer->GetRemainingData(), buffer->GetRemainingSize());
83 } 84 }
84 85
85 // Produces a frame with the given producer and returns a copy of its 86 // Produces a frame with the given producer and returns a copy of its
86 // data as an int (converted from a string). 87 // data as an int (converted from a string).
87 int ProducerToInt(scoped_ptr<SpdyBufferProducer> producer) { 88 int ProducerToInt(scoped_ptr<SpdyBufferProducer> producer) {
88 int i = 0; 89 int i = 0;
89 EXPECT_TRUE(base::StringToInt(ProducerToString(producer.Pass()), &i)); 90 EXPECT_TRUE(base::StringToInt(ProducerToString(std::move(producer)), &i));
90 return i; 91 return i;
91 } 92 }
92 93
93 // Makes a SpdyStream with the given priority and a NULL SpdySession 94 // Makes a SpdyStream with the given priority and a NULL SpdySession
94 // -- be careful to not call any functions that expect the session to 95 // -- be careful to not call any functions that expect the session to
95 // be there. 96 // be there.
96 SpdyStream* MakeTestStream(RequestPriority priority) { 97 SpdyStream* MakeTestStream(RequestPriority priority) {
97 return new SpdyStream( 98 return new SpdyStream(
98 SPDY_BIDIRECTIONAL_STREAM, base::WeakPtr<SpdySession>(), 99 SPDY_BIDIRECTIONAL_STREAM, base::WeakPtr<SpdySession>(),
99 GURL(), priority, 0, 0, BoundNetLog()); 100 GURL(), priority, 0, 0, BoundNetLog());
100 } 101 }
101 102
102 // Add some frame producers of different priority. The producers 103 // Add some frame producers of different priority. The producers
103 // should be dequeued in priority order with their associated stream. 104 // should be dequeued in priority order with their associated stream.
104 TEST_F(SpdyWriteQueueTest, DequeuesByPriority) { 105 TEST_F(SpdyWriteQueueTest, DequeuesByPriority) {
105 SpdyWriteQueue write_queue; 106 SpdyWriteQueue write_queue;
106 107
107 scoped_ptr<SpdyBufferProducer> producer_low = StringToProducer("LOW"); 108 scoped_ptr<SpdyBufferProducer> producer_low = StringToProducer("LOW");
108 scoped_ptr<SpdyBufferProducer> producer_medium = StringToProducer("MEDIUM"); 109 scoped_ptr<SpdyBufferProducer> producer_medium = StringToProducer("MEDIUM");
109 scoped_ptr<SpdyBufferProducer> producer_highest = StringToProducer("HIGHEST"); 110 scoped_ptr<SpdyBufferProducer> producer_highest = StringToProducer("HIGHEST");
110 111
111 scoped_ptr<SpdyStream> stream_medium(MakeTestStream(MEDIUM)); 112 scoped_ptr<SpdyStream> stream_medium(MakeTestStream(MEDIUM));
112 scoped_ptr<SpdyStream> stream_highest(MakeTestStream(HIGHEST)); 113 scoped_ptr<SpdyStream> stream_highest(MakeTestStream(HIGHEST));
113 114
114 // A NULL stream should still work. 115 // A NULL stream should still work.
115 write_queue.Enqueue( 116 write_queue.Enqueue(LOW, SYN_STREAM, std::move(producer_low),
116 LOW, SYN_STREAM, producer_low.Pass(), base::WeakPtr<SpdyStream>()); 117 base::WeakPtr<SpdyStream>());
117 write_queue.Enqueue( 118 write_queue.Enqueue(MEDIUM, SYN_REPLY, std::move(producer_medium),
118 MEDIUM, SYN_REPLY, producer_medium.Pass(), stream_medium->GetWeakPtr()); 119 stream_medium->GetWeakPtr());
119 write_queue.Enqueue( 120 write_queue.Enqueue(HIGHEST, RST_STREAM, std::move(producer_highest),
120 HIGHEST, RST_STREAM, producer_highest.Pass(), 121 stream_highest->GetWeakPtr());
121 stream_highest->GetWeakPtr());
122 122
123 SpdyFrameType frame_type = DATA; 123 SpdyFrameType frame_type = DATA;
124 scoped_ptr<SpdyBufferProducer> frame_producer; 124 scoped_ptr<SpdyBufferProducer> frame_producer;
125 base::WeakPtr<SpdyStream> stream; 125 base::WeakPtr<SpdyStream> stream;
126 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 126 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
127 EXPECT_EQ(RST_STREAM, frame_type); 127 EXPECT_EQ(RST_STREAM, frame_type);
128 EXPECT_EQ("HIGHEST", ProducerToString(frame_producer.Pass())); 128 EXPECT_EQ("HIGHEST", ProducerToString(std::move(frame_producer)));
129 EXPECT_EQ(stream_highest.get(), stream.get()); 129 EXPECT_EQ(stream_highest.get(), stream.get());
130 130
131 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 131 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
132 EXPECT_EQ(SYN_REPLY, frame_type); 132 EXPECT_EQ(SYN_REPLY, frame_type);
133 EXPECT_EQ("MEDIUM", ProducerToString(frame_producer.Pass())); 133 EXPECT_EQ("MEDIUM", ProducerToString(std::move(frame_producer)));
134 EXPECT_EQ(stream_medium.get(), stream.get()); 134 EXPECT_EQ(stream_medium.get(), stream.get());
135 135
136 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 136 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
137 EXPECT_EQ(SYN_STREAM, frame_type); 137 EXPECT_EQ(SYN_STREAM, frame_type);
138 EXPECT_EQ("LOW", ProducerToString(frame_producer.Pass())); 138 EXPECT_EQ("LOW", ProducerToString(std::move(frame_producer)));
139 EXPECT_EQ(nullptr, stream.get()); 139 EXPECT_EQ(nullptr, stream.get());
140 140
141 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 141 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
142 } 142 }
143 143
144 // Add some frame producers with the same priority. The producers 144 // Add some frame producers with the same priority. The producers
145 // should be dequeued in FIFO order with their associated stream. 145 // should be dequeued in FIFO order with their associated stream.
146 TEST_F(SpdyWriteQueueTest, DequeuesFIFO) { 146 TEST_F(SpdyWriteQueueTest, DequeuesFIFO) {
147 SpdyWriteQueue write_queue; 147 SpdyWriteQueue write_queue;
148 148
149 scoped_ptr<SpdyBufferProducer> producer1 = IntToProducer(1); 149 scoped_ptr<SpdyBufferProducer> producer1 = IntToProducer(1);
150 scoped_ptr<SpdyBufferProducer> producer2 = IntToProducer(2); 150 scoped_ptr<SpdyBufferProducer> producer2 = IntToProducer(2);
151 scoped_ptr<SpdyBufferProducer> producer3 = IntToProducer(3); 151 scoped_ptr<SpdyBufferProducer> producer3 = IntToProducer(3);
152 152
153 scoped_ptr<SpdyStream> stream1(MakeTestStream(DEFAULT_PRIORITY)); 153 scoped_ptr<SpdyStream> stream1(MakeTestStream(DEFAULT_PRIORITY));
154 scoped_ptr<SpdyStream> stream2(MakeTestStream(DEFAULT_PRIORITY)); 154 scoped_ptr<SpdyStream> stream2(MakeTestStream(DEFAULT_PRIORITY));
155 scoped_ptr<SpdyStream> stream3(MakeTestStream(DEFAULT_PRIORITY)); 155 scoped_ptr<SpdyStream> stream3(MakeTestStream(DEFAULT_PRIORITY));
156 156
157 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, producer1.Pass(), 157 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, std::move(producer1),
158 stream1->GetWeakPtr()); 158 stream1->GetWeakPtr());
159 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_REPLY, producer2.Pass(), 159 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_REPLY, std::move(producer2),
160 stream2->GetWeakPtr()); 160 stream2->GetWeakPtr());
161 write_queue.Enqueue(DEFAULT_PRIORITY, RST_STREAM, producer3.Pass(), 161 write_queue.Enqueue(DEFAULT_PRIORITY, RST_STREAM, std::move(producer3),
162 stream3->GetWeakPtr()); 162 stream3->GetWeakPtr());
163 163
164 SpdyFrameType frame_type = DATA; 164 SpdyFrameType frame_type = DATA;
165 scoped_ptr<SpdyBufferProducer> frame_producer; 165 scoped_ptr<SpdyBufferProducer> frame_producer;
166 base::WeakPtr<SpdyStream> stream; 166 base::WeakPtr<SpdyStream> stream;
167 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 167 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
168 EXPECT_EQ(SYN_STREAM, frame_type); 168 EXPECT_EQ(SYN_STREAM, frame_type);
169 EXPECT_EQ(1, ProducerToInt(frame_producer.Pass())); 169 EXPECT_EQ(1, ProducerToInt(std::move(frame_producer)));
170 EXPECT_EQ(stream1.get(), stream.get()); 170 EXPECT_EQ(stream1.get(), stream.get());
171 171
172 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 172 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
173 EXPECT_EQ(SYN_REPLY, frame_type); 173 EXPECT_EQ(SYN_REPLY, frame_type);
174 EXPECT_EQ(2, ProducerToInt(frame_producer.Pass())); 174 EXPECT_EQ(2, ProducerToInt(std::move(frame_producer)));
175 EXPECT_EQ(stream2.get(), stream.get()); 175 EXPECT_EQ(stream2.get(), stream.get());
176 176
177 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 177 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
178 EXPECT_EQ(RST_STREAM, frame_type); 178 EXPECT_EQ(RST_STREAM, frame_type);
179 EXPECT_EQ(3, ProducerToInt(frame_producer.Pass())); 179 EXPECT_EQ(3, ProducerToInt(std::move(frame_producer)));
180 EXPECT_EQ(stream3.get(), stream.get()); 180 EXPECT_EQ(stream3.get(), stream.get());
181 181
182 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 182 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
183 } 183 }
184 184
185 // Enqueue a bunch of writes and then call 185 // Enqueue a bunch of writes and then call
186 // RemovePendingWritesForStream() on one of the streams. No dequeued 186 // RemovePendingWritesForStream() on one of the streams. No dequeued
187 // write should be for that stream. 187 // write should be for that stream.
188 TEST_F(SpdyWriteQueueTest, RemovePendingWritesForStream) { 188 TEST_F(SpdyWriteQueueTest, RemovePendingWritesForStream) {
189 SpdyWriteQueue write_queue; 189 SpdyWriteQueue write_queue;
190 190
191 scoped_ptr<SpdyStream> stream1(MakeTestStream(DEFAULT_PRIORITY)); 191 scoped_ptr<SpdyStream> stream1(MakeTestStream(DEFAULT_PRIORITY));
192 scoped_ptr<SpdyStream> stream2(MakeTestStream(DEFAULT_PRIORITY)); 192 scoped_ptr<SpdyStream> stream2(MakeTestStream(DEFAULT_PRIORITY));
193 193
194 for (int i = 0; i < 100; ++i) { 194 for (int i = 0; i < 100; ++i) {
195 base::WeakPtr<SpdyStream> stream = 195 base::WeakPtr<SpdyStream> stream =
196 (((i % 3) == 0) ? stream1 : stream2)->GetWeakPtr(); 196 (((i % 3) == 0) ? stream1 : stream2)->GetWeakPtr();
197 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, IntToProducer(i), stream); 197 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, IntToProducer(i), stream);
198 } 198 }
199 199
200 write_queue.RemovePendingWritesForStream(stream2->GetWeakPtr()); 200 write_queue.RemovePendingWritesForStream(stream2->GetWeakPtr());
201 201
202 for (int i = 0; i < 100; i += 3) { 202 for (int i = 0; i < 100; i += 3) {
203 SpdyFrameType frame_type = DATA; 203 SpdyFrameType frame_type = DATA;
204 scoped_ptr<SpdyBufferProducer> frame_producer; 204 scoped_ptr<SpdyBufferProducer> frame_producer;
205 base::WeakPtr<SpdyStream> stream; 205 base::WeakPtr<SpdyStream> stream;
206 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 206 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
207 EXPECT_EQ(SYN_STREAM, frame_type); 207 EXPECT_EQ(SYN_STREAM, frame_type);
208 EXPECT_EQ(i, ProducerToInt(frame_producer.Pass())); 208 EXPECT_EQ(i, ProducerToInt(std::move(frame_producer)));
209 EXPECT_EQ(stream1.get(), stream.get()); 209 EXPECT_EQ(stream1.get(), stream.get());
210 } 210 }
211 211
212 SpdyFrameType frame_type = DATA; 212 SpdyFrameType frame_type = DATA;
213 scoped_ptr<SpdyBufferProducer> frame_producer; 213 scoped_ptr<SpdyBufferProducer> frame_producer;
214 base::WeakPtr<SpdyStream> stream; 214 base::WeakPtr<SpdyStream> stream;
215 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 215 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
216 } 216 }
217 217
218 // Enqueue a bunch of writes and then call 218 // Enqueue a bunch of writes and then call
(...skipping 23 matching lines...) Expand all
242 242
243 write_queue.RemovePendingWritesForStreamsAfter(stream1->stream_id()); 243 write_queue.RemovePendingWritesForStreamsAfter(stream1->stream_id());
244 244
245 for (int i = 0; i < 100; i += arraysize(streams)) { 245 for (int i = 0; i < 100; i += arraysize(streams)) {
246 SpdyFrameType frame_type = DATA; 246 SpdyFrameType frame_type = DATA;
247 scoped_ptr<SpdyBufferProducer> frame_producer; 247 scoped_ptr<SpdyBufferProducer> frame_producer;
248 base::WeakPtr<SpdyStream> stream; 248 base::WeakPtr<SpdyStream> stream;
249 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)) 249 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream))
250 << "Unable to Dequeue i: " << i; 250 << "Unable to Dequeue i: " << i;
251 EXPECT_EQ(SYN_STREAM, frame_type); 251 EXPECT_EQ(SYN_STREAM, frame_type);
252 EXPECT_EQ(i, ProducerToInt(frame_producer.Pass())); 252 EXPECT_EQ(i, ProducerToInt(std::move(frame_producer)));
253 EXPECT_EQ(stream1.get(), stream.get()); 253 EXPECT_EQ(stream1.get(), stream.get());
254 } 254 }
255 255
256 SpdyFrameType frame_type = DATA; 256 SpdyFrameType frame_type = DATA;
257 scoped_ptr<SpdyBufferProducer> frame_producer; 257 scoped_ptr<SpdyBufferProducer> frame_producer;
258 base::WeakPtr<SpdyStream> stream; 258 base::WeakPtr<SpdyStream> stream;
259 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); 259 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream));
260 } 260 }
261 261
262 // Enqueue a bunch of writes and then call Clear(). The write queue 262 // Enqueue a bunch of writes and then call Clear(). The write queue
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 scoped_ptr<SpdyBufferProducer> producer; 364 scoped_ptr<SpdyBufferProducer> producer;
365 base::WeakPtr<SpdyStream> weak_stream; 365 base::WeakPtr<SpdyStream> weak_stream;
366 366
367 EXPECT_TRUE(queue.Dequeue(&frame_type, &producer, &weak_stream)); 367 EXPECT_TRUE(queue.Dequeue(&frame_type, &producer, &weak_stream));
368 EXPECT_EQ(string(kRequeued), producer->ProduceBuffer()->GetRemainingData()); 368 EXPECT_EQ(string(kRequeued), producer->ProduceBuffer()->GetRemainingData());
369 } 369 }
370 370
371 } // namespace 371 } // namespace
372 372
373 } // namespace net 373 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.cc ('k') | net/ssl/channel_id_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698