| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_stream_factory_impl_request.h" | 5 #include "net/http/http_stream_factory_impl_request.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "net/http/http_stream_factory_impl.h" | 11 #include "net/http/http_stream_factory_impl.h" |
| 12 #include "net/http/http_stream_factory_impl_job.h" | 12 #include "net/http/http_stream_factory_impl_job.h" |
| 13 #include "net/http/http_stream_factory_impl_job_controller.h" | 13 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 14 #include "net/http/http_stream_factory_test_util.h" | 14 #include "net/http/http_stream_factory_test_util.h" |
| 15 #include "net/log/net_log_with_source.h" |
| 15 #include "net/proxy/proxy_info.h" | 16 #include "net/proxy/proxy_info.h" |
| 16 #include "net/proxy/proxy_service.h" | 17 #include "net/proxy/proxy_service.h" |
| 17 #include "net/spdy/spdy_test_util_common.h" | 18 #include "net/spdy/spdy_test_util_common.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using testing::_; | 21 using testing::_; |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 class HttpStreamFactoryImplRequestTest : public ::testing::Test {}; | 25 class HttpStreamFactoryImplRequestTest : public ::testing::Test {}; |
| 25 | 26 |
| 26 // Make sure that Request passes on its priority updates to its jobs. | 27 // Make sure that Request passes on its priority updates to its jobs. |
| 27 TEST_F(HttpStreamFactoryImplRequestTest, SetPriority) { | 28 TEST_F(HttpStreamFactoryImplRequestTest, SetPriority) { |
| 28 SpdySessionDependencies session_deps(ProxyService::CreateDirect()); | 29 SpdySessionDependencies session_deps(ProxyService::CreateDirect()); |
| 29 std::unique_ptr<HttpNetworkSession> session = | 30 std::unique_ptr<HttpNetworkSession> session = |
| 30 SpdySessionDependencies::SpdyCreateSession(&session_deps); | 31 SpdySessionDependencies::SpdyCreateSession(&session_deps); |
| 31 HttpStreamFactoryImpl* factory = | 32 HttpStreamFactoryImpl* factory = |
| 32 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); | 33 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); |
| 33 MockHttpStreamRequestDelegate request_delegate; | 34 MockHttpStreamRequestDelegate request_delegate; |
| 34 TestJobFactory job_factory; | 35 TestJobFactory job_factory; |
| 36 NetLogWithSource net_log; |
| 35 HttpStreamFactoryImpl::JobController* job_controller = | 37 HttpStreamFactoryImpl::JobController* job_controller = |
| 36 new HttpStreamFactoryImpl::JobController(factory, &request_delegate, | 38 new HttpStreamFactoryImpl::JobController( |
| 37 session.get(), &job_factory); | 39 factory, &request_delegate, session.get(), &job_factory, |
| 40 /*is_preconnect=*/false, net_log); |
| 38 factory->job_controller_set_.insert(base::WrapUnique(job_controller)); | 41 factory->job_controller_set_.insert(base::WrapUnique(job_controller)); |
| 39 | 42 |
| 40 HttpRequestInfo request_info; | 43 HttpRequestInfo request_info; |
| 41 std::unique_ptr<HttpStreamFactoryImpl::Request> request( | 44 std::unique_ptr<HttpStreamFactoryImpl::Request> request(job_controller->Start( |
| 42 job_controller->Start(request_info, &request_delegate, nullptr, | 45 request_info, &request_delegate, nullptr, HttpStreamRequest::HTTP_STREAM, |
| 43 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 46 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 44 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 45 EXPECT_TRUE(job_controller->main_job()); | 47 EXPECT_TRUE(job_controller->main_job()); |
| 46 EXPECT_EQ(DEFAULT_PRIORITY, job_controller->main_job()->priority()); | 48 EXPECT_EQ(DEFAULT_PRIORITY, job_controller->main_job()->priority()); |
| 47 | 49 |
| 48 request->SetPriority(MEDIUM); | 50 request->SetPriority(MEDIUM); |
| 49 EXPECT_EQ(MEDIUM, job_controller->main_job()->priority()); | 51 EXPECT_EQ(MEDIUM, job_controller->main_job()->priority()); |
| 50 | 52 |
| 51 EXPECT_CALL(request_delegate, OnStreamFailed(_, _)).Times(1); | 53 EXPECT_CALL(request_delegate, OnStreamFailed(_, _)).Times(1); |
| 52 job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED, | 54 job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED, |
| 53 SSLConfig()); | 55 SSLConfig()); |
| 54 | 56 |
| 55 request->SetPriority(IDLE); | 57 request->SetPriority(IDLE); |
| 56 EXPECT_EQ(IDLE, job_controller->main_job()->priority()); | 58 EXPECT_EQ(IDLE, job_controller->main_job()->priority()); |
| 57 } | 59 } |
| 58 } // namespace net | 60 } // namespace net |
| OLD | NEW |