OLD | NEW |
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 | 10 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 EXPECT_EQ(i, ProducerToInt(frame_producer.Pass())); | 171 EXPECT_EQ(i, ProducerToInt(frame_producer.Pass())); |
172 EXPECT_EQ(stream1, stream); | 172 EXPECT_EQ(stream1, stream); |
173 } | 173 } |
174 | 174 |
175 SpdyFrameType frame_type = DATA; | 175 SpdyFrameType frame_type = DATA; |
176 scoped_ptr<SpdyBufferProducer> frame_producer; | 176 scoped_ptr<SpdyBufferProducer> frame_producer; |
177 scoped_refptr<SpdyStream> stream; | 177 scoped_refptr<SpdyStream> stream; |
178 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); | 178 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); |
179 } | 179 } |
180 | 180 |
| 181 // Enqueue a bunch of writes and then call |
| 182 // RemovePendingWritesForStreamsAfter(). No dequeued write should be for |
| 183 // those streams without a stream id, or with a stream_id after that |
| 184 // argument. |
| 185 TEST_F(SpdyWriteQueueTest, RemovePendingWritesForStreamsAfter) { |
| 186 SpdyWriteQueue write_queue; |
| 187 |
| 188 scoped_refptr<SpdyStream> stream1(MakeTestStream(DEFAULT_PRIORITY)); |
| 189 stream1->set_stream_id(1); |
| 190 scoped_refptr<SpdyStream> stream2(MakeTestStream(DEFAULT_PRIORITY)); |
| 191 stream2->set_stream_id(3); |
| 192 scoped_refptr<SpdyStream> stream3(MakeTestStream(DEFAULT_PRIORITY)); |
| 193 stream3->set_stream_id(5); |
| 194 // No stream id assigned. |
| 195 scoped_refptr<SpdyStream> stream4(MakeTestStream(DEFAULT_PRIORITY)); |
| 196 scoped_refptr<SpdyStream> streams[] = { |
| 197 stream1, stream2, stream3, stream4 |
| 198 }; |
| 199 |
| 200 for (int i = 0; i < 100; ++i) { |
| 201 scoped_refptr<SpdyStream> stream = streams[i % arraysize(streams)]; |
| 202 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, IntToProducer(i), stream); |
| 203 } |
| 204 |
| 205 write_queue.RemovePendingWritesForStreamsAfter(stream1->stream_id()); |
| 206 |
| 207 for (int i = 0; i < 100; i += arraysize(streams)) { |
| 208 SpdyFrameType frame_type = DATA; |
| 209 scoped_ptr<SpdyBufferProducer> frame_producer; |
| 210 scoped_refptr<SpdyStream> stream; |
| 211 ASSERT_TRUE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)) |
| 212 << "Unable to Dequeue i: " << i; |
| 213 EXPECT_EQ(SYN_STREAM, frame_type); |
| 214 EXPECT_EQ(i, ProducerToInt(frame_producer.Pass())); |
| 215 EXPECT_EQ(stream1, stream); |
| 216 } |
| 217 |
| 218 SpdyFrameType frame_type = DATA; |
| 219 scoped_ptr<SpdyBufferProducer> frame_producer; |
| 220 scoped_refptr<SpdyStream> stream; |
| 221 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); |
| 222 } |
| 223 |
181 // Enqueue a bunch of writes and then call Clear(). The write queue | 224 // Enqueue a bunch of writes and then call Clear(). The write queue |
182 // should clean up the memory properly, and Dequeue() should return | 225 // should clean up the memory properly, and Dequeue() should return |
183 // false. | 226 // false. |
184 TEST_F(SpdyWriteQueueTest, Clear) { | 227 TEST_F(SpdyWriteQueueTest, Clear) { |
185 SpdyWriteQueue write_queue; | 228 SpdyWriteQueue write_queue; |
186 | 229 |
187 for (int i = 0; i < 100; ++i) { | 230 for (int i = 0; i < 100; ++i) { |
188 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, IntToProducer(i), NULL); | 231 write_queue.Enqueue(DEFAULT_PRIORITY, SYN_STREAM, IntToProducer(i), NULL); |
189 } | 232 } |
190 | 233 |
191 write_queue.Clear(); | 234 write_queue.Clear(); |
192 | 235 |
193 SpdyFrameType frame_type = DATA; | 236 SpdyFrameType frame_type = DATA; |
194 scoped_ptr<SpdyBufferProducer> frame_producer; | 237 scoped_ptr<SpdyBufferProducer> frame_producer; |
195 scoped_refptr<SpdyStream> stream; | 238 scoped_refptr<SpdyStream> stream; |
196 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); | 239 EXPECT_FALSE(write_queue.Dequeue(&frame_type, &frame_producer, &stream)); |
197 } | 240 } |
198 | 241 |
199 } // namespace | 242 } // namespace |
200 | 243 |
201 } // namespace net | 244 } // namespace net |
OLD | NEW |