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

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: Simplify transaction unit tests Created 9 years, 3 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
13 using testing::_;
14 using testing::NiceMock;
15 using testing::Ref;
16 using testing::Return;
17
18 static const int kMaxCapacity = 3;
19
20 namespace net {
21
22 class MockHostDelegate : public HttpPipelinedHost::Delegate {
23 public:
24 MOCK_METHOD1(OnHostIdle, void(HttpPipelinedHost* host));
25 MOCK_METHOD1(OnHostHasAdditionalCapacity, void(HttpPipelinedHost* host));
26 };
27
28 class MockPipelineFactory : public HttpPipelinedConnection::Factory {
29 public:
30 MOCK_METHOD6(CreateNewPipeline, HttpPipelinedConnection*(
31 ClientSocketHandle* connection,
32 HttpPipelinedConnection::Delegate* delegate,
33 const SSLConfig& used_ssl_config,
34 const ProxyInfo& used_proxy_info,
35 const BoundNetLog& net_log,
36 bool was_npn_negotiated));
37 };
38
39 class MockPipeline : public HttpPipelinedConnection {
40 public:
41 MockPipeline(int depth, bool usable, bool active)
42 : depth_(depth),
43 usable_(usable),
44 active_(active) {
45 }
46
47 void SetState(int depth, bool usable, bool active) {
48 depth_ = depth;
49 usable_ = usable;
50 active_ = active;
51 }
52
53 virtual int depth() const OVERRIDE { return depth_; }
54 virtual bool usable() const OVERRIDE { return usable_; }
55 virtual bool active() const OVERRIDE { return active_; }
56
57 MOCK_METHOD0(CreateNewStream, HttpStream*());
58 MOCK_METHOD1(OnStreamDeleted, void(int pipeline_id));
59 MOCK_CONST_METHOD0(used_ssl_config, const SSLConfig&());
60 MOCK_CONST_METHOD0(used_proxy_info, const ProxyInfo&());
61 MOCK_CONST_METHOD0(source, const NetLog::Source&());
62 MOCK_CONST_METHOD0(was_npn_negotiated, bool());
63
64 private:
65 int depth_;
66 bool usable_;
67 bool active_;
68 };
69
70 class HttpPipelinedHostTest : public testing::Test {
71 public:
72 HttpPipelinedHostTest()
73 : origin_("host", 123),
74 host_(&delegate_, origin_, &factory_) {
75 }
76
77 MockPipeline* AddTestPipeline(int depth, bool usable, bool active) {
78 MockPipeline* pipeline = new MockPipeline(depth, usable, active);
79 EXPECT_CALL(factory_, CreateNewPipeline(connection_, &host_,
80 Ref(ssl_config_), Ref(proxy_info_),
81 Ref(net_log_), true))
82 .Times(1)
83 .WillOnce(Return(pipeline));
84 EXPECT_EQ(pipeline, host_.CreateNewPipeline(connection_, ssl_config_,
85 proxy_info_, net_log_, true));
86 return pipeline;
87 }
88
89 void ClearTestPipeline(MockPipeline* pipeline) {
90 pipeline->SetState(0, true, true);
91 host_.OnPipelineHasCapacity(pipeline);
92 }
93
94 NiceMock<MockHostDelegate> delegate_;
95 HostPortPair origin_;
96 MockPipelineFactory factory_;
97 HttpPipelinedHost host_;
98
99 ClientSocketHandle* connection_;
100 SSLConfig ssl_config_;
101 ProxyInfo proxy_info_;
102 BoundNetLog net_log_;
103 };
104
105 TEST_F(HttpPipelinedHostTest, Delegate) {
106 EXPECT_TRUE(origin_.Equals(host_.origin()));
107 }
108
109 TEST_F(HttpPipelinedHostTest, OnHostIdle) {
110 MockPipeline* pipeline = AddTestPipeline(0, false, true);
111
112 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(&host_))
113 .Times(0);
114 EXPECT_CALL(delegate_, OnHostIdle(&host_))
115 .Times(1);
116 host_.OnPipelineHasCapacity(pipeline);
117 }
118
119 TEST_F(HttpPipelinedHostTest, OnHostHasAdditionalCapacity) {
120 MockPipeline* pipeline = AddTestPipeline(1, true, true);
121
122 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(&host_))
123 .Times(2);
124 EXPECT_CALL(delegate_, OnHostIdle(&host_))
125 .Times(0);
126
127 host_.OnPipelineHasCapacity(pipeline);
128
129 EXPECT_CALL(delegate_, OnHostIdle(&host_))
130 .Times(1);
131 ClearTestPipeline(pipeline);
132 }
133
134 TEST_F(HttpPipelinedHostTest, IgnoresUnusablePipeline) {
135 MockPipeline* pipeline = AddTestPipeline(1, false, true);
136
137 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
138
139 ClearTestPipeline(pipeline);
140 }
141
142 TEST_F(HttpPipelinedHostTest, IgnoresInactivePipeline) {
143 MockPipeline* pipeline = AddTestPipeline(1, true, false);
144
145 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
146
147 ClearTestPipeline(pipeline);
148 }
149
150 TEST_F(HttpPipelinedHostTest, IgnoresFullPipeline) {
151 MockPipeline* pipeline = AddTestPipeline(kMaxCapacity, true, true);
152
153 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
154
155 ClearTestPipeline(pipeline);
156 }
157
158 TEST_F(HttpPipelinedHostTest, PicksLeastLoadedPipeline) {
159 MockPipeline* full_pipeline = AddTestPipeline(kMaxCapacity, true, true);
160 MockPipeline* usable_pipeline = AddTestPipeline(kMaxCapacity - 1, true, true);
161 MockPipeline* empty_pipeline = AddTestPipeline(0, true, true);
162
163 EXPECT_EQ(empty_pipeline, host_.FindAvailablePipeline());
164
165 ClearTestPipeline(full_pipeline);
166 ClearTestPipeline(usable_pipeline);
167 ClearTestPipeline(empty_pipeline);
168 }
169
170 TEST_F(HttpPipelinedHostTest, EmptyPipelineIsRemoved) {
171 MockPipeline* empty_pipeline = AddTestPipeline(0, true, true);
172
173 EXPECT_EQ(empty_pipeline, host_.FindAvailablePipeline());
174
175 ClearTestPipeline(empty_pipeline);
176
177 EXPECT_EQ(NULL, host_.FindAvailablePipeline());
178 }
179
180 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698