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
3 // found in the LICENSE file.
5 #include "net/http/http_pipelined_host_forced.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "net/http/http_pipelined_host_test_util.h"
9 #include "net/proxy/proxy_info.h"
10 #include "net/socket/client_socket_handle.h"
11 #include "net/ssl/ssl_config_service.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using testing::NiceMock
;
17 using testing::Return
;
23 HttpPipelinedStream
* kDummyStream
=
24 reinterpret_cast<HttpPipelinedStream
*>(24);
26 class HttpPipelinedHostForcedTest
: public testing::Test
{
28 HttpPipelinedHostForcedTest()
29 : key_(HostPortPair("host", 123)),
30 factory_(new MockPipelineFactory
), // Owned by |host_|.
31 host_(new HttpPipelinedHostForced(&delegate_
, key_
, factory_
)) {
34 MockPipeline
* AddTestPipeline() {
35 MockPipeline
* pipeline
= new MockPipeline(0, true, true);
36 EXPECT_CALL(*factory_
, CreateNewPipeline(&connection_
, host_
.get(),
37 MatchesOrigin(key_
.origin()),
38 Ref(ssl_config_
), Ref(proxy_info_
),
42 .WillOnce(Return(pipeline
));
43 EXPECT_CALL(*pipeline
, CreateNewStream())
45 .WillOnce(Return(kDummyStream
));
46 EXPECT_EQ(kDummyStream
, host_
->CreateStreamOnNewPipeline(
47 &connection_
, ssl_config_
, proxy_info_
, net_log_
, true,
52 ClientSocketHandle connection_
;
53 NiceMock
<MockHostDelegate
> delegate_
;
54 HttpPipelinedHost::Key key_
;
55 MockPipelineFactory
* factory_
;
56 scoped_ptr
<HttpPipelinedHostForced
> host_
;
58 SSLConfig ssl_config_
;
59 ProxyInfo proxy_info_
;
63 TEST_F(HttpPipelinedHostForcedTest
, Delegate
) {
64 EXPECT_TRUE(key_
.origin().Equals(host_
->GetKey().origin()));
67 TEST_F(HttpPipelinedHostForcedTest
, SingleUser
) {
68 EXPECT_FALSE(host_
->IsExistingPipelineAvailable());
70 MockPipeline
* pipeline
= AddTestPipeline();
71 EXPECT_TRUE(host_
->IsExistingPipelineAvailable());
73 EXPECT_CALL(delegate_
, OnHostHasAdditionalCapacity(host_
.get()))
75 EXPECT_CALL(delegate_
, OnHostIdle(host_
.get()))
77 host_
->OnPipelineHasCapacity(pipeline
);
80 TEST_F(HttpPipelinedHostForcedTest
, ReuseExisting
) {
81 EXPECT_EQ(NULL
, host_
->CreateStreamOnExistingPipeline());
83 MockPipeline
* pipeline
= AddTestPipeline();
84 EXPECT_CALL(*pipeline
, CreateNewStream())
86 .WillOnce(Return(kDummyStream
));
87 EXPECT_EQ(kDummyStream
, host_
->CreateStreamOnExistingPipeline());
89 pipeline
->SetState(1, true, true);
90 EXPECT_CALL(delegate_
, OnHostHasAdditionalCapacity(host_
.get()))
92 EXPECT_CALL(delegate_
, OnHostIdle(host_
.get()))
94 host_
->OnPipelineHasCapacity(pipeline
);
96 pipeline
->SetState(0, true, true);
97 EXPECT_CALL(delegate_
, OnHostHasAdditionalCapacity(host_
.get()))
99 EXPECT_CALL(delegate_
, OnHostIdle(host_
.get()))
101 host_
->OnPipelineHasCapacity(pipeline
);
104 } // anonymous namespace