Add a function to create a bookmark app from a WebApplicationInfo.
[chromium-blink-merge.git] / net / http / http_pipelined_host_forced_unittest.cc
blobb86dd96d50abbef2b70f2922c7b5650929019840
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;
16 using testing::Ref;
17 using testing::Return;
19 namespace net {
21 namespace {
23 HttpPipelinedStream* kDummyStream =
24 reinterpret_cast<HttpPipelinedStream*>(24);
26 class HttpPipelinedHostForcedTest : public testing::Test {
27 public:
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_),
39 Ref(net_log_), true,
40 kProtoSPDY3))
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 kProtoSPDY3));
49 return pipeline;
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_;
60 BoundNetLog net_log_;
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()))
74 .Times(1);
75 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
76 .Times(1);
77 host_->OnPipelineHasCapacity(pipeline);
80 TEST_F(HttpPipelinedHostForcedTest, ReuseExisting) {
81 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
83 MockPipeline* pipeline = AddTestPipeline();
84 EXPECT_CALL(*pipeline, CreateNewStream())
85 .Times(1)
86 .WillOnce(Return(kDummyStream));
87 EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline());
89 pipeline->SetState(1, true, true);
90 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
91 .Times(1);
92 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
93 .Times(0);
94 host_->OnPipelineHasCapacity(pipeline);
96 pipeline->SetState(0, true, true);
97 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
98 .Times(1);
99 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
100 .Times(1);
101 host_->OnPipelineHasCapacity(pipeline);
104 } // anonymous namespace
106 } // namespace net