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

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

Issue 9433015: Add a force pipelining option to load flags. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix build on other platforms Created 8 years, 10 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
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/http/http_pipelined_host_impl.h" 5 #include "net/http/http_pipelined_host_impl.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "net/base/ssl_config_service.h" 8 #include "net/base/ssl_config_service.h"
9 #include "net/http/http_pipelined_connection.h" 9 #include "net/http/http_pipelined_connection.h"
10 #include "net/http/http_pipelined_host_test_util.h"
10 #include "net/proxy/proxy_info.h" 11 #include "net/proxy/proxy_info.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 using testing::_; 15 using testing::_;
15 using testing::NiceMock; 16 using testing::NiceMock;
16 using testing::Ref; 17 using testing::Ref;
17 using testing::Return; 18 using testing::Return;
18 using testing::ReturnNull; 19 using testing::ReturnNull;
19 20
20 namespace net { 21 namespace net {
21 22
22 namespace { 23 namespace {
23 24
24 ClientSocketHandle* kDummyConnection = 25 ClientSocketHandle* kDummyConnection =
25 reinterpret_cast<ClientSocketHandle*>(84); 26 reinterpret_cast<ClientSocketHandle*>(84);
26 HttpPipelinedStream* kDummyStream = 27 HttpPipelinedStream* kDummyStream =
27 reinterpret_cast<HttpPipelinedStream*>(42); 28 reinterpret_cast<HttpPipelinedStream*>(42);
28 29
29 class MockHostDelegate : public HttpPipelinedHost::Delegate {
30 public:
31 MOCK_METHOD1(OnHostIdle, void(HttpPipelinedHost* host));
32 MOCK_METHOD1(OnHostHasAdditionalCapacity, void(HttpPipelinedHost* host));
33 MOCK_METHOD2(OnHostDeterminedCapability,
34 void(HttpPipelinedHost* host,
35 HttpPipelinedHostCapability capability));
36 };
37
38 class MockPipelineFactory : public HttpPipelinedConnection::Factory {
39 public:
40 MOCK_METHOD8(CreateNewPipeline, HttpPipelinedConnection*(
41 ClientSocketHandle* connection,
42 HttpPipelinedConnection::Delegate* delegate,
43 const HostPortPair& origin,
44 const SSLConfig& used_ssl_config,
45 const ProxyInfo& used_proxy_info,
46 const BoundNetLog& net_log,
47 bool was_npn_negotiated,
48 SSLClientSocket::NextProto protocol_negotiated));
49 };
50
51 class MockPipeline : public HttpPipelinedConnection {
52 public:
53 MockPipeline(int depth, bool usable, bool active)
54 : depth_(depth),
55 usable_(usable),
56 active_(active) {
57 }
58
59 void SetState(int depth, bool usable, bool active) {
60 depth_ = depth;
61 usable_ = usable;
62 active_ = active;
63 }
64
65 virtual int depth() const OVERRIDE { return depth_; }
66 virtual bool usable() const OVERRIDE { return usable_; }
67 virtual bool active() const OVERRIDE { return active_; }
68
69 MOCK_METHOD0(CreateNewStream, HttpPipelinedStream*());
70 MOCK_METHOD1(OnStreamDeleted, void(int pipeline_id));
71 MOCK_CONST_METHOD0(used_ssl_config, const SSLConfig&());
72 MOCK_CONST_METHOD0(used_proxy_info, const ProxyInfo&());
73 MOCK_CONST_METHOD0(net_log, const BoundNetLog&());
74 MOCK_CONST_METHOD0(was_npn_negotiated, bool());
75 MOCK_CONST_METHOD0(protocol_negotiated, SSLClientSocket::NextProto());
76
77 private:
78 int depth_;
79 bool usable_;
80 bool active_;
81 };
82
83 MATCHER_P(MatchesOrigin, expected, "") { return expected.Equals(arg); }
84
85 class HttpPipelinedHostImplTest : public testing::Test { 30 class HttpPipelinedHostImplTest : public testing::Test {
86 public: 31 public:
87 HttpPipelinedHostImplTest() 32 HttpPipelinedHostImplTest()
88 : origin_("host", 123), 33 : key_(HostPortPair("host", 123), false),
89 factory_(new MockPipelineFactory), // Owned by host_. 34 factory_(new MockPipelineFactory), // Owned by host_.
90 host_(new HttpPipelinedHostImpl(&delegate_, origin_, factory_, 35 host_(new HttpPipelinedHostImpl(&delegate_, key_, factory_,
91 PIPELINE_CAPABLE)) { 36 PIPELINE_CAPABLE)) {
92 } 37 }
93 38
94 void SetCapability(HttpPipelinedHostCapability capability) { 39 void SetCapability(HttpPipelinedHostCapability capability) {
95 factory_ = new MockPipelineFactory; 40 factory_ = new MockPipelineFactory;
96 host_.reset(new HttpPipelinedHostImpl( 41 host_.reset(new HttpPipelinedHostImpl(
97 &delegate_, origin_, factory_, capability)); 42 &delegate_, key_, factory_, capability));
98 } 43 }
99 44
100 MockPipeline* AddTestPipeline(int depth, bool usable, bool active) { 45 MockPipeline* AddTestPipeline(int depth, bool usable, bool active) {
101 MockPipeline* pipeline = new MockPipeline(depth, usable, active); 46 MockPipeline* pipeline = new MockPipeline(depth, usable, active);
102 EXPECT_CALL(*factory_, CreateNewPipeline(kDummyConnection, host_.get(), 47 EXPECT_CALL(*factory_, CreateNewPipeline(kDummyConnection, host_.get(),
103 MatchesOrigin(origin_), 48 MatchesOrigin(key_.origin()),
104 Ref(ssl_config_), Ref(proxy_info_), 49 Ref(ssl_config_), Ref(proxy_info_),
105 Ref(net_log_), true, 50 Ref(net_log_), true,
106 SSLClientSocket::kProtoSPDY21)) 51 SSLClientSocket::kProtoSPDY21))
107 .Times(1) 52 .Times(1)
108 .WillOnce(Return(pipeline)); 53 .WillOnce(Return(pipeline));
109 EXPECT_CALL(*pipeline, CreateNewStream()) 54 EXPECT_CALL(*pipeline, CreateNewStream())
110 .Times(1) 55 .Times(1)
111 .WillOnce(Return(kDummyStream)); 56 .WillOnce(Return(kDummyStream));
112 EXPECT_EQ(kDummyStream, host_->CreateStreamOnNewPipeline( 57 EXPECT_EQ(kDummyStream, host_->CreateStreamOnNewPipeline(
113 kDummyConnection, ssl_config_, proxy_info_, net_log_, true, 58 kDummyConnection, ssl_config_, proxy_info_, net_log_, true,
114 SSLClientSocket::kProtoSPDY21)); 59 SSLClientSocket::kProtoSPDY21));
115 return pipeline; 60 return pipeline;
116 } 61 }
117 62
118 void ClearTestPipeline(MockPipeline* pipeline) { 63 void ClearTestPipeline(MockPipeline* pipeline) {
119 pipeline->SetState(0, true, true); 64 pipeline->SetState(0, true, true);
120 host_->OnPipelineHasCapacity(pipeline); 65 host_->OnPipelineHasCapacity(pipeline);
121 } 66 }
122 67
123 NiceMock<MockHostDelegate> delegate_; 68 NiceMock<MockHostDelegate> delegate_;
124 HostPortPair origin_; 69 HttpPipelinedHost::Key key_;
125 MockPipelineFactory* factory_; 70 MockPipelineFactory* factory_;
126 scoped_ptr<HttpPipelinedHostImpl> host_; 71 scoped_ptr<HttpPipelinedHostImpl> host_;
127 72
128 SSLConfig ssl_config_; 73 SSLConfig ssl_config_;
129 ProxyInfo proxy_info_; 74 ProxyInfo proxy_info_;
130 BoundNetLog net_log_; 75 BoundNetLog net_log_;
131 }; 76 };
132 77
133 TEST_F(HttpPipelinedHostImplTest, Delegate) { 78 TEST_F(HttpPipelinedHostImplTest, Delegate) {
134 EXPECT_TRUE(origin_.Equals(host_->origin())); 79 EXPECT_TRUE(key_.origin().Equals(host_->key().origin()));
80 EXPECT_EQ(key_.force_pipelining(), host_->key().force_pipelining());
135 } 81 }
136 82
137 TEST_F(HttpPipelinedHostImplTest, OnUnusablePipelineHasCapacity) { 83 TEST_F(HttpPipelinedHostImplTest, OnUnusablePipelineHasCapacity) {
138 MockPipeline* pipeline = AddTestPipeline(0, false, true); 84 MockPipeline* pipeline = AddTestPipeline(0, false, true);
139 85
140 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) 86 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
141 .Times(0); 87 .Times(0);
142 EXPECT_CALL(delegate_, OnHostIdle(host_.get())) 88 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
143 .Times(1); 89 .Times(1);
144 host_->OnPipelineHasCapacity(pipeline); 90 host_->OnPipelineHasCapacity(pipeline);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 .Times(1); 300 .Times(1);
355 host_->OnPipelineFeedback(pipeline, 301 host_->OnPipelineFeedback(pipeline,
356 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR); 302 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR);
357 303
358 ClearTestPipeline(pipeline); 304 ClearTestPipeline(pipeline);
359 } 305 }
360 306
361 } // anonymous namespace 307 } // anonymous namespace
362 308
363 } // namespace net 309 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698