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

Side by Side Diff: net/http/http_pipelined_host_unittest.cc

Issue 7289006: Basic HTTP pipelining support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests Created 9 years, 4 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/http/http_pipelined_host.h"
6
7 #include "net/base/ssl_config_service.h"
8 #include "net/http/http_pipelined_connection.h"
9 #include "net/proxy/proxy_info.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #if 0
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h"
15 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h"
17 #include "net/base/request_priority.h"
18 #include "net/http/http_pipelined_stream.h"
19 #include "net/socket/client_socket_handle.h"
20 #include "net/socket/client_socket_pool_histograms.h"
21 #include "net/socket/socket_test_util.h"
22 #endif
23
24 using testing::_;
25 using testing::NiceMock;
26 using testing::Ref;
27 using testing::Return;
28
29 static const int kMaxCapacity = 3;
30
31 namespace net {
32
33 class MockHostOwner : public HttpPipelinedHost::Owner {
34 public:
35 MOCK_METHOD1(OnHostIdle, void(HttpPipelinedHost* host));
36 MOCK_METHOD1(OnHostHasAdditionalCapacity, void(HttpPipelinedHost* host));
37 };
38
39 class MockPipelineFactory : public HttpPipelinedConnection::Factory {
40 public:
41 MOCK_METHOD6(CreateNewPipeline, HttpPipelinedConnection*(
42 ClientSocketHandle* connection,
43 HttpPipelinedConnection::Owner* owner,
44 const SSLConfig& used_ssl_config,
45 const ProxyInfo& used_proxy_info,
46 const BoundNetLog& net_log,
47 bool was_npn_negotiated));
48 };
49
50 class MockPipeline : public HttpPipelinedConnection {
51 public:
52 MockPipeline(int depth, bool usable, bool active)
53 : depth_(depth),
54 usable_(usable),
55 active_(active) {
56 }
57
58 void SetState(int depth, bool usable, bool active) {
59 depth_ = depth;
60 usable_ = usable;
61 active_ = active;
62 }
63
64 int depth() const OVERRIDE { return depth_; }
65 bool usable() const OVERRIDE { return usable_; }
66 bool active() const OVERRIDE { return active_; }
mmenke 2011/08/23 19:05:25 nit: Use virtual as well as OVERRIDE.
James Simonsen 2011/08/26 22:19:07 Done.
67
68 MOCK_METHOD0(CreateNewStream, HttpStream*());
69 MOCK_METHOD1(OnStreamDeleted, void(int pipeline_id));
70 MOCK_CONST_METHOD0(used_ssl_config, const SSLConfig&());
71 MOCK_CONST_METHOD0(used_proxy_info, const ProxyInfo&());
72 MOCK_CONST_METHOD0(source, const NetLog::Source&());
73 MOCK_CONST_METHOD0(was_npn_negotiated, bool());
74
75 private:
76 int depth_;
77 bool usable_;
78 bool active_;
79 };
80
81 class HttpPipelinedHostTest : public testing::Test {
82 public:
83 HttpPipelinedHostTest()
84 : origin_("host", 123),
85 host_(&owner_, origin_, &factory_) {
86 }
87
88 MockPipeline* AddTestPipeline(int depth, bool usable, bool active) {
89 MockPipeline* pipeline = new MockPipeline(depth, usable, active);
90 EXPECT_CALL(factory_, CreateNewPipeline(connection_, &host_,
91 Ref(ssl_config_), Ref(proxy_info_),
92 Ref(net_log_), true))
93 .Times(1)
94 .WillOnce(Return(pipeline));
95 EXPECT_EQ(pipeline, host_.CreateNewPipeline(connection_, ssl_config_,
96 proxy_info_, net_log_, true));
97 return pipeline;
98 }
99
100 void ClearTestPipeline(MockPipeline* pipeline) {
101 pipeline->SetState(0, true, true);
102 host_.OnPipelineHasCapacity(pipeline);
103 }
104
105 NiceMock<MockHostOwner> owner_;
106 HostPortPair origin_;
107 MockPipelineFactory factory_;
108 HttpPipelinedHost host_;
109
110 ClientSocketHandle* connection_;
111 SSLConfig ssl_config_;
112 ProxyInfo proxy_info_;
113 BoundNetLog net_log_;
114 };
115
116 TEST_F(HttpPipelinedHostTest, Owner) {
117 EXPECT_TRUE(origin_.Equals(host_.origin()));
118 }
119
120 TEST_F(HttpPipelinedHostTest, OnHostIdle) {
121 MockPipeline* pipeline = AddTestPipeline(0, false, true);
122
123 EXPECT_CALL(owner_, OnHostHasAdditionalCapacity(&host_))
124 .Times(0);
125 EXPECT_CALL(owner_, OnHostIdle(&host_))
126 .Times(1);
127 host_.OnPipelineHasCapacity(pipeline);
128 }
129
130 TEST_F(HttpPipelinedHostTest, OnHostHasAdditionalCapacity) {
131 MockPipeline* pipeline = AddTestPipeline(1, true, true);
132
133 EXPECT_CALL(owner_, OnHostHasAdditionalCapacity(&host_))
134 .Times(2);
mmenke 2011/08/23 19:05:25 Maybe add: EXPECT_CALL(owner_, OnHostIdle(&host
James Simonsen 2011/08/26 22:19:07 Done.
135 host_.OnPipelineHasCapacity(pipeline);
136
137 EXPECT_CALL(owner_, OnHostIdle(&host_))
138 .Times(1);
139 ClearTestPipeline(pipeline);
140 }
141
142 TEST_F(HttpPipelinedHostTest, IgnoresUnusablePipeline) {
143 MockPipeline* pipeline = AddTestPipeline(1, false, true);
144
145 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
146
147 ClearTestPipeline(pipeline);
148 }
149
150 TEST_F(HttpPipelinedHostTest, IgnoresInactivePipeline) {
151 MockPipeline* pipeline = AddTestPipeline(1, true, false);
152
153 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
154
155 ClearTestPipeline(pipeline);
156 }
157
158 TEST_F(HttpPipelinedHostTest, IgnoresFullPipeline) {
159 MockPipeline* pipeline = AddTestPipeline(kMaxCapacity, true, true);
160
161 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
162
163 ClearTestPipeline(pipeline);
164 }
165
166 TEST_F(HttpPipelinedHostTest, PicksLeastLoadedPipeline) {
167 MockPipeline* full_pipeline = AddTestPipeline(kMaxCapacity, true, true);
168 MockPipeline* usable_pipeline = AddTestPipeline(kMaxCapacity - 1, true, true);
169 MockPipeline* empty_pipeline = AddTestPipeline(0, true, true);
170
171 EXPECT_EQ(empty_pipeline, host_.FindAvailablePipeline());
172
173 ClearTestPipeline(full_pipeline);
174 ClearTestPipeline(usable_pipeline);
175 ClearTestPipeline(empty_pipeline);
176 }
177
mmenke 2011/08/23 19:05:25 Maybe add something along the lines of: TEST_F(Ht
James Simonsen 2011/08/26 22:19:07 Done.
178 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698