OLD | NEW |
---|---|
(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_pool.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "net/base/ssl_config_service.h" | |
9 #include "net/http/http_pipelined_host.h" | |
10 #include "net/proxy/proxy_info.h" | |
11 #include "testing/gmock/include/gmock/gmock.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 using testing::_; | |
15 using testing::Ref; | |
16 using testing::Return; | |
17 using testing::ReturnNull; | |
18 | |
19 namespace net { | |
20 | |
21 namespace { | |
22 | |
23 ClientSocketHandle* kDummyConnection = | |
24 reinterpret_cast<ClientSocketHandle*>(188); | |
25 HttpPipelinedStream* kDummyStream = | |
26 reinterpret_cast<HttpPipelinedStream*>(99); | |
27 | |
28 class MockPoolDelegate : public HttpPipelinedHostPool::Delegate { | |
29 public: | |
30 MOCK_METHOD1(OnHttpPipelinedHostHasAdditionalCapacity, | |
31 void(const HostPortPair& origin)); | |
32 }; | |
33 | |
34 class MockHostFactory : public HttpPipelinedHost::Factory { | |
35 public: | |
36 MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*( | |
37 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, | |
38 HttpPipelinedConnection::Factory* factory, | |
39 HttpPipelinedHost::Capability capability)); | |
40 }; | |
41 | |
42 class MockHost : public HttpPipelinedHost { | |
43 public: | |
44 MockHost(const HostPortPair& origin) | |
45 : origin_(origin) { | |
46 } | |
47 | |
48 MOCK_METHOD5(CreateStreamOnNewPipeline, HttpPipelinedStream*( | |
49 ClientSocketHandle* connection, | |
50 const SSLConfig& used_ssl_config, | |
51 const ProxyInfo& used_proxy_info, | |
52 const BoundNetLog& net_log, | |
53 bool was_npn_negotiated)); | |
54 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*()); | |
55 MOCK_METHOD0(IsExistingPipelineAvailable, bool()); | |
56 | |
57 virtual const HostPortPair& origin() const OVERRIDE { return origin_; } | |
58 | |
59 private: | |
60 HostPortPair origin_; | |
61 }; | |
62 | |
63 class HttpPipelinedHostPoolTest : public testing::Test { | |
64 public: | |
65 HttpPipelinedHostPoolTest() | |
66 : origin_("host", 123), | |
67 factory_(new MockHostFactory), // Owned by pool_. | |
68 host_(new MockHost(origin_)), // Owned by pool_. | |
69 pool_(new HttpPipelinedHostPool(&delegate_, factory_)), | |
70 was_npn_negotiated_(false) { | |
71 } | |
72 | |
73 void CreateDummyStream() { | |
74 EXPECT_CALL(*host_, CreateStreamOnNewPipeline(kDummyConnection, | |
75 Ref(ssl_config_), | |
76 Ref(proxy_info_), | |
77 Ref(net_log_), | |
78 was_npn_negotiated_)) | |
79 .Times(1) | |
80 .WillOnce(Return(kDummyStream)); | |
81 EXPECT_EQ(kDummyStream, | |
82 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, | |
83 ssl_config_, proxy_info_, | |
84 net_log_, was_npn_negotiated_)); | |
85 } | |
86 | |
87 HostPortPair origin_; | |
88 MockPoolDelegate delegate_; | |
89 MockHostFactory* factory_; | |
90 MockHost* host_; | |
91 scoped_ptr<HttpPipelinedHostPool> pool_; | |
92 | |
93 const SSLConfig ssl_config_; | |
94 const ProxyInfo proxy_info_; | |
95 const BoundNetLog net_log_; | |
96 bool was_npn_negotiated_; | |
97 }; | |
98 | |
99 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) { | |
100 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); | |
101 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
102 HttpPipelinedHost::UNKNOWN)) | |
103 .Times(1) | |
104 .WillOnce(Return(host_)); | |
105 | |
106 CreateDummyStream(); | |
107 pool_->OnHostIdle(host_); | |
mmenke
2011/11/28 23:05:28
Might want to make sure |host_| gets deleted. Thi
James Simonsen
2011/12/01 01:17:10
As with the other test file, I think this will be
mmenke
2011/12/01 02:17:31
There were one or two tests in particular that I w
James Simonsen
2011/12/01 20:36:42
Agreed.
We also have the CHECK() in the destructo
| |
108 } | |
109 | |
110 TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) { | |
111 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
112 HttpPipelinedHost::UNKNOWN)) | |
113 .Times(1) | |
114 .WillOnce(Return(host_)); | |
115 | |
116 CreateDummyStream(); | |
117 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::INCAPABLE); | |
118 pool_->OnHostIdle(host_); | |
119 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); | |
120 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
121 HttpPipelinedHost::INCAPABLE)) | |
122 .Times(0); | |
123 EXPECT_EQ(NULL, | |
124 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, | |
125 ssl_config_, proxy_info_, net_log_, | |
126 was_npn_negotiated_)); | |
127 } | |
128 | |
129 TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) { | |
130 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
131 HttpPipelinedHost::UNKNOWN)) | |
132 .Times(1) | |
133 .WillOnce(Return(host_)); | |
134 | |
135 CreateDummyStream(); | |
136 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE); | |
137 pool_->OnHostIdle(host_); | |
138 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); | |
139 | |
140 host_ = new MockHost(origin_); | |
141 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
142 HttpPipelinedHost::CAPABLE)) | |
143 .Times(1) | |
144 .WillOnce(Return(host_)); | |
145 CreateDummyStream(); | |
146 pool_->OnHostIdle(host_); | |
mmenke
2011/11/28 23:05:28
nit: The results would be the same on remembering
James Simonsen
2011/12/01 01:17:10
The difference is that CAPABLE is passed in to Cre
mmenke
2011/12/01 02:17:31
Ahh, right, good point.
| |
147 } | |
148 | |
149 TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) { | |
150 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
151 HttpPipelinedHost::UNKNOWN)) | |
152 .Times(1) | |
153 .WillOnce(Return(host_)); | |
154 | |
155 CreateDummyStream(); | |
mmenke
2011/11/28 23:05:28
Maybe do a CAPABLE up here, too?
James Simonsen
2011/12/01 01:17:10
Good idea. Done.
| |
156 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::INCAPABLE); | |
157 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE); | |
158 pool_->OnHostIdle(host_); | |
159 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); | |
160 } | |
161 | |
mmenke
2011/11/28 23:05:28
You might also want a test where we don't remember
| |
162 } // anonymous namespace | |
163 | |
164 } // namespace net | |
OLD | NEW |