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

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

Issue 10185007: [net] Change order of RequestPriority to natural: higher > lower (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Responded to review Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "net/base/host_cache.h" 7 #include "net/base/host_cache.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_log_unittest.h" 9 #include "net/base/net_log_unittest.h"
10 #include "net/spdy/spdy_io_buffer.h" 10 #include "net/spdy/spdy_io_buffer.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 private: 68 private:
69 CompletionCallback callback_; 69 CompletionCallback callback_;
70 }; 70 };
71 71
72 // Test the SpdyIOBuffer class. 72 // Test the SpdyIOBuffer class.
73 TEST_F(SpdySessionSpdy2Test, SpdyIOBuffer) { 73 TEST_F(SpdySessionSpdy2Test, SpdyIOBuffer) {
74 std::priority_queue<SpdyIOBuffer> queue_; 74 std::priority_queue<SpdyIOBuffer> queue_;
75 const size_t kQueueSize = 100; 75 const size_t kQueueSize = 100;
76 76
77 // Insert 100 items; pri 100 to 1. 77 // Insert items with random priority and increasing buffer size.
szym 2012/04/24 18:15:25 Please, take a look at the new test.
Ryan Hamilton 2012/04/24 18:45:35 Cool.
78 for (size_t index = 0; index < kQueueSize; ++index) { 78 for (size_t index = 0; index < kQueueSize; ++index) {
79 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL); 79 queue_.push(SpdyIOBuffer(
80 queue_.push(buffer); 80 new IOBufferWithSize(index + 1),
81 index + 1,
82 static_cast<RequestPriority>(rand() % NUM_PRIORITIES),
83 NULL));
81 } 84 }
82 85
83 // Insert several priority 0 items last. 86 EXPECT_EQ(kQueueSize, queue_.size());
84 const size_t kNumDuplicates = 12;
85 IOBufferWithSize* buffers[kNumDuplicates];
86 for (size_t index = 0; index < kNumDuplicates; ++index) {
87 buffers[index] = new IOBufferWithSize(index+1);
88 queue_.push(SpdyIOBuffer(buffers[index], buffers[index]->size(), 0, NULL));
89 }
90 87
91 EXPECT_EQ(kQueueSize + kNumDuplicates, queue_.size()); 88 // Verify items come out with decreasing priority or FIFO order.
92 89 RequestPriority last_priority = NUM_PRIORITIES;
93 // Verify the P0 items come out in FIFO order. 90 size_t last_size = 0;
94 for (size_t index = 0; index < kNumDuplicates; ++index) { 91 for (size_t index = 0; index < kQueueSize; ++index) {
95 SpdyIOBuffer buffer = queue_.top(); 92 SpdyIOBuffer buffer = queue_.top();
96 EXPECT_EQ(0, buffer.priority()); 93 EXPECT_LE(buffer.priority(), last_priority);
97 EXPECT_EQ(index + 1, buffer.size()); 94 if (buffer.priority() < last_priority)
95 last_size = 0;
96 EXPECT_LT(last_size, buffer.size());
97 last_priority = buffer.priority();
98 last_size = buffer.size();
98 queue_.pop(); 99 queue_.pop();
99 } 100 }
100 101
101 int priority = 1; 102 EXPECT_EQ(0u, queue_.size());
102 while (queue_.size()) {
103 SpdyIOBuffer buffer = queue_.top();
104 EXPECT_EQ(priority++, buffer.priority());
105 queue_.pop();
106 }
107 } 103 }
108 104
109 TEST_F(SpdySessionSpdy2Test, GoAway) { 105 TEST_F(SpdySessionSpdy2Test, GoAway) {
110 SpdySessionDependencies session_deps; 106 SpdySessionDependencies session_deps;
111 session_deps.host_resolver->set_synchronous_mode(true); 107 session_deps.host_resolver->set_synchronous_mode(true);
112 108
113 MockConnect connect_data(SYNCHRONOUS, OK); 109 MockConnect connect_data(SYNCHRONOUS, OK);
114 scoped_ptr<SpdyFrame> goaway(ConstructSpdyGoAway()); 110 scoped_ptr<SpdyFrame> goaway(ConstructSpdyGoAway());
115 MockRead reads[] = { 111 MockRead reads[] = {
116 CreateMockRead(*goaway), 112 CreateMockRead(*goaway),
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 net::NetLog::PHASE_NONE); 1037 net::NetLog::PHASE_NONE);
1042 1038
1043 CapturingNetLog::Entry entry = entries[pos]; 1039 CapturingNetLog::Entry entry = entries[pos];
1044 NetLogSpdySessionCloseParameter* request_params = 1040 NetLogSpdySessionCloseParameter* request_params =
1045 static_cast<NetLogSpdySessionCloseParameter*>( 1041 static_cast<NetLogSpdySessionCloseParameter*>(
1046 entry.extra_parameters.get()); 1042 entry.extra_parameters.get());
1047 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); 1043 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status());
1048 } 1044 }
1049 1045
1050 } // namespace net 1046 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698