Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "net/http/http_pipelined_host_forced.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "net/base/ssl_config_service.h" | |
| 9 #include "net/http/http_pipelined_host_test_util.h" | |
| 10 #include "net/proxy/proxy_info.h" | |
| 11 #include "net/socket/client_socket_handle.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 using testing::NiceMock; | |
| 16 using testing::Ref; | |
| 17 using testing::Return; | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 HttpPipelinedStream* kDummyStream = | |
| 24 reinterpret_cast<HttpPipelinedStream*>(24); | |
| 25 | |
| 26 class HttpPipelinedHostForcedTest : public testing::Test { | |
| 27 public: | |
| 28 HttpPipelinedHostForcedTest() | |
| 29 : key_(HostPortPair("host", 123), false), | |
| 30 factory_(new MockPipelineFactory), // Owned by host_. | |
|
mmenke
2012/02/23 18:54:58
nit: |host_|
James Simonsen
2012/02/23 23:49:46
Done.
| |
| 31 host_(new HttpPipelinedHostForced(&delegate_, key_, factory_)) { | |
| 32 } | |
| 33 | |
| 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_), | |
| 39 Ref(net_log_), true, | |
| 40 SSLClientSocket::kProtoSPDY21)) | |
| 41 .Times(1) | |
| 42 .WillOnce(Return(pipeline)); | |
| 43 EXPECT_CALL(*pipeline, CreateNewStream()) | |
| 44 .Times(1) | |
| 45 .WillOnce(Return(kDummyStream)); | |
| 46 EXPECT_EQ(kDummyStream, host_->CreateStreamOnNewPipeline( | |
| 47 &connection_, ssl_config_, proxy_info_, net_log_, true, | |
| 48 SSLClientSocket::kProtoSPDY21)); | |
| 49 return pipeline; | |
| 50 } | |
| 51 | |
| 52 void ClearTestPipeline(MockPipeline* pipeline) { | |
|
mmenke
2012/02/23 18:54:58
This isn't used.
James Simonsen
2012/02/23 23:49:46
Done.
| |
| 53 pipeline->SetState(0, true, true); | |
| 54 host_->OnPipelineHasCapacity(pipeline); | |
| 55 } | |
| 56 | |
| 57 ClientSocketHandle connection_; | |
| 58 NiceMock<MockHostDelegate> delegate_; | |
| 59 HttpPipelinedHost::Key key_; | |
| 60 MockPipelineFactory* factory_; | |
| 61 scoped_ptr<HttpPipelinedHostForced> host_; | |
| 62 | |
| 63 SSLConfig ssl_config_; | |
| 64 ProxyInfo proxy_info_; | |
| 65 BoundNetLog net_log_; | |
| 66 }; | |
| 67 | |
| 68 TEST_F(HttpPipelinedHostForcedTest, Delegate) { | |
| 69 EXPECT_TRUE(key_.origin().Equals(host_->key().origin())); | |
| 70 EXPECT_EQ(key_.force_pipelining(), host_->key().force_pipelining()); | |
| 71 } | |
| 72 | |
| 73 TEST_F(HttpPipelinedHostForcedTest, SingleUser) { | |
| 74 EXPECT_FALSE(host_->IsExistingPipelineAvailable()); | |
| 75 | |
| 76 MockPipeline* pipeline = AddTestPipeline(); | |
| 77 EXPECT_TRUE(host_->IsExistingPipelineAvailable()); | |
| 78 | |
| 79 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) | |
| 80 .Times(1); | |
| 81 EXPECT_CALL(delegate_, OnHostIdle(host_.get())) | |
| 82 .Times(1); | |
| 83 host_->OnPipelineHasCapacity(pipeline); | |
| 84 } | |
| 85 | |
| 86 TEST_F(HttpPipelinedHostForcedTest, ReuseExisting) { | |
| 87 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline()); | |
| 88 | |
| 89 MockPipeline* pipeline = AddTestPipeline(); | |
| 90 EXPECT_CALL(*pipeline, CreateNewStream()) | |
| 91 .Times(1) | |
| 92 .WillOnce(Return(kDummyStream)); | |
| 93 EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline()); | |
| 94 | |
| 95 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) | |
| 96 .Times(1); | |
| 97 EXPECT_CALL(delegate_, OnHostIdle(host_.get())) | |
| 98 .Times(1); | |
| 99 host_->OnPipelineHasCapacity(pipeline); | |
|
mmenke
2012/02/23 18:54:58
I suggest in one test you set depth to 1 before ca
James Simonsen
2012/02/23 23:49:46
Good idea. Done.
| |
| 100 } | |
| 101 | |
| 102 } // anonymous namespace | |
| 103 | |
| 104 } // namespace net | |
| OLD | NEW |