OLD | NEW |
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_forced.h" | 5 #include "net/http/http_pipelined_host_forced.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "net/http/http_pipelined_host_test_util.h" | 8 #include "net/http/http_pipelined_host_test_util.h" |
9 #include "net/proxy/proxy_info.h" | 9 #include "net/proxy/proxy_info.h" |
10 #include "net/socket/client_socket_handle.h" | 10 #include "net/socket/client_socket_handle.h" |
11 #include "net/ssl/ssl_config_service.h" | 11 #include "net/ssl/ssl_config_service.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using testing::NiceMock; | 15 using testing::NiceMock; |
16 using testing::Ref; | 16 using testing::Ref; |
17 using testing::Return; | 17 using testing::Return; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 HttpPipelinedStream* kDummyStream = | 23 HttpPipelinedStream* kDummyStream = reinterpret_cast<HttpPipelinedStream*>(24); |
24 reinterpret_cast<HttpPipelinedStream*>(24); | |
25 | 24 |
26 class HttpPipelinedHostForcedTest : public testing::Test { | 25 class HttpPipelinedHostForcedTest : public testing::Test { |
27 public: | 26 public: |
28 HttpPipelinedHostForcedTest() | 27 HttpPipelinedHostForcedTest() |
29 : key_(HostPortPair("host", 123)), | 28 : key_(HostPortPair("host", 123)), |
30 factory_(new MockPipelineFactory), // Owned by |host_|. | 29 factory_(new MockPipelineFactory), // Owned by |host_|. |
31 host_(new HttpPipelinedHostForced(&delegate_, key_, factory_)) { | 30 host_(new HttpPipelinedHostForced(&delegate_, key_, factory_)) {} |
32 } | |
33 | 31 |
34 MockPipeline* AddTestPipeline() { | 32 MockPipeline* AddTestPipeline() { |
35 MockPipeline* pipeline = new MockPipeline(0, true, true); | 33 MockPipeline* pipeline = new MockPipeline(0, true, true); |
36 EXPECT_CALL(*factory_, CreateNewPipeline(&connection_, host_.get(), | 34 EXPECT_CALL(*factory_, |
37 MatchesOrigin(key_.origin()), | 35 CreateNewPipeline(&connection_, |
38 Ref(ssl_config_), Ref(proxy_info_), | 36 host_.get(), |
39 Ref(net_log_), true, | 37 MatchesOrigin(key_.origin()), |
40 kProtoSPDY3)) | 38 Ref(ssl_config_), |
| 39 Ref(proxy_info_), |
| 40 Ref(net_log_), |
| 41 true, |
| 42 kProtoSPDY3)) |
41 .Times(1) | 43 .Times(1) |
42 .WillOnce(Return(pipeline)); | 44 .WillOnce(Return(pipeline)); |
43 EXPECT_CALL(*pipeline, CreateNewStream()) | 45 EXPECT_CALL(*pipeline, CreateNewStream()).Times(1).WillOnce( |
44 .Times(1) | 46 Return(kDummyStream)); |
45 .WillOnce(Return(kDummyStream)); | 47 EXPECT_EQ(kDummyStream, |
46 EXPECT_EQ(kDummyStream, host_->CreateStreamOnNewPipeline( | 48 host_->CreateStreamOnNewPipeline(&connection_, |
47 &connection_, ssl_config_, proxy_info_, net_log_, true, | 49 ssl_config_, |
48 kProtoSPDY3)); | 50 proxy_info_, |
| 51 net_log_, |
| 52 true, |
| 53 kProtoSPDY3)); |
49 return pipeline; | 54 return pipeline; |
50 } | 55 } |
51 | 56 |
52 ClientSocketHandle connection_; | 57 ClientSocketHandle connection_; |
53 NiceMock<MockHostDelegate> delegate_; | 58 NiceMock<MockHostDelegate> delegate_; |
54 HttpPipelinedHost::Key key_; | 59 HttpPipelinedHost::Key key_; |
55 MockPipelineFactory* factory_; | 60 MockPipelineFactory* factory_; |
56 scoped_ptr<HttpPipelinedHostForced> host_; | 61 scoped_ptr<HttpPipelinedHostForced> host_; |
57 | 62 |
58 SSLConfig ssl_config_; | 63 SSLConfig ssl_config_; |
59 ProxyInfo proxy_info_; | 64 ProxyInfo proxy_info_; |
60 BoundNetLog net_log_; | 65 BoundNetLog net_log_; |
61 }; | 66 }; |
62 | 67 |
63 TEST_F(HttpPipelinedHostForcedTest, Delegate) { | 68 TEST_F(HttpPipelinedHostForcedTest, Delegate) { |
64 EXPECT_TRUE(key_.origin().Equals(host_->GetKey().origin())); | 69 EXPECT_TRUE(key_.origin().Equals(host_->GetKey().origin())); |
65 } | 70 } |
66 | 71 |
67 TEST_F(HttpPipelinedHostForcedTest, SingleUser) { | 72 TEST_F(HttpPipelinedHostForcedTest, SingleUser) { |
68 EXPECT_FALSE(host_->IsExistingPipelineAvailable()); | 73 EXPECT_FALSE(host_->IsExistingPipelineAvailable()); |
69 | 74 |
70 MockPipeline* pipeline = AddTestPipeline(); | 75 MockPipeline* pipeline = AddTestPipeline(); |
71 EXPECT_TRUE(host_->IsExistingPipelineAvailable()); | 76 EXPECT_TRUE(host_->IsExistingPipelineAvailable()); |
72 | 77 |
73 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) | 78 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())).Times(1); |
74 .Times(1); | 79 EXPECT_CALL(delegate_, OnHostIdle(host_.get())).Times(1); |
75 EXPECT_CALL(delegate_, OnHostIdle(host_.get())) | |
76 .Times(1); | |
77 host_->OnPipelineHasCapacity(pipeline); | 80 host_->OnPipelineHasCapacity(pipeline); |
78 } | 81 } |
79 | 82 |
80 TEST_F(HttpPipelinedHostForcedTest, ReuseExisting) { | 83 TEST_F(HttpPipelinedHostForcedTest, ReuseExisting) { |
81 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline()); | 84 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline()); |
82 | 85 |
83 MockPipeline* pipeline = AddTestPipeline(); | 86 MockPipeline* pipeline = AddTestPipeline(); |
84 EXPECT_CALL(*pipeline, CreateNewStream()) | 87 EXPECT_CALL(*pipeline, CreateNewStream()).Times(1).WillOnce( |
85 .Times(1) | 88 Return(kDummyStream)); |
86 .WillOnce(Return(kDummyStream)); | |
87 EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline()); | 89 EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline()); |
88 | 90 |
89 pipeline->SetState(1, true, true); | 91 pipeline->SetState(1, true, true); |
90 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) | 92 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())).Times(1); |
91 .Times(1); | 93 EXPECT_CALL(delegate_, OnHostIdle(host_.get())).Times(0); |
92 EXPECT_CALL(delegate_, OnHostIdle(host_.get())) | |
93 .Times(0); | |
94 host_->OnPipelineHasCapacity(pipeline); | 94 host_->OnPipelineHasCapacity(pipeline); |
95 | 95 |
96 pipeline->SetState(0, true, true); | 96 pipeline->SetState(0, true, true); |
97 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) | 97 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())).Times(1); |
98 .Times(1); | 98 EXPECT_CALL(delegate_, OnHostIdle(host_.get())).Times(1); |
99 EXPECT_CALL(delegate_, OnHostIdle(host_.get())) | |
100 .Times(1); | |
101 host_->OnPipelineHasCapacity(pipeline); | 99 host_->OnPipelineHasCapacity(pipeline); |
102 } | 100 } |
103 | 101 |
104 } // anonymous namespace | 102 } // anonymous namespace |
105 | 103 |
106 } // namespace net | 104 } // namespace net |
OLD | NEW |