Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 static bool main_job_is_resumed( | 155 static bool main_job_is_resumed( |
| 156 HttpStreamFactoryImpl::JobController* job_controller) { | 156 HttpStreamFactoryImpl::JobController* job_controller) { |
| 157 return job_controller->main_job_is_resumed_; | 157 return job_controller->main_job_is_resumed_; |
| 158 } | 158 } |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { | 161 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
| 162 public: | 162 public: |
| 163 HttpStreamFactoryImplJobControllerTest() | 163 HttpStreamFactoryImplJobControllerTest() |
| 164 : session_deps_(ProxyService::CreateDirect()), | 164 : session_deps_(ProxyService::CreateDirect()), |
| 165 random_generator_(0), | 165 random_generator_(0), |
|
Bence
2017/06/09 19:17:39
Please assign default value at member declaration
xunjieli
2017/06/13 15:23:11
Done.
| |
| 166 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], | 166 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], |
| 167 0, | 167 0, |
| 168 &clock_, | 168 &clock_, |
| 169 kServerHostname, | 169 kServerHostname, |
| 170 Perspective::IS_CLIENT), | 170 Perspective::IS_CLIENT) { |
| 171 use_alternative_proxy_(false), | |
| 172 is_preconnect_(false), | |
| 173 enable_ip_based_pooling_(true), | |
| 174 enable_alternative_services_(true), | |
| 175 test_proxy_delegate_(nullptr) { | |
| 176 session_deps_.enable_quic = true; | 171 session_deps_.enable_quic = true; |
| 177 } | 172 } |
| 178 | 173 |
| 179 void UseAlternativeProxy() { | 174 void UseAlternativeProxy() { |
| 180 ASSERT_FALSE(test_proxy_delegate_); | 175 ASSERT_FALSE(test_proxy_delegate_); |
| 181 use_alternative_proxy_ = true; | 176 use_alternative_proxy_ = true; |
| 182 } | 177 } |
| 183 | 178 |
| 184 void SetPreconnect() { | 179 void SetPreconnect() { |
| 185 ASSERT_FALSE(test_proxy_delegate_); | 180 ASSERT_FALSE(test_proxy_delegate_); |
| 186 is_preconnect_ = true; | 181 is_preconnect_ = true; |
| 187 } | 182 } |
| 188 | 183 |
| 189 void DisableIPBasedPooling() { | 184 void DisableIPBasedPooling() { |
| 190 ASSERT_FALSE(test_proxy_delegate_); | 185 ASSERT_FALSE(test_proxy_delegate_); |
| 191 enable_ip_based_pooling_ = false; | 186 enable_ip_based_pooling_ = false; |
| 192 } | 187 } |
| 193 | 188 |
| 194 void DisableAlternativeServices() { | 189 void DisableAlternativeServices() { |
| 195 ASSERT_FALSE(test_proxy_delegate_); | 190 ASSERT_FALSE(test_proxy_delegate_); |
| 196 enable_alternative_services_ = false; | 191 enable_alternative_services_ = false; |
| 197 } | 192 } |
| 198 | 193 |
| 194 void SetSkipCreateJobController() { | |
| 195 ASSERT_FALSE(job_controller_); | |
| 196 skip_create_job_controller_ = true; | |
| 197 } | |
| 198 | |
| 199 void Initialize(const HttpRequestInfo& request_info) { | 199 void Initialize(const HttpRequestInfo& request_info) { |
| 200 ASSERT_FALSE(test_proxy_delegate_); | 200 ASSERT_FALSE(test_proxy_delegate_); |
| 201 auto test_proxy_delegate = base::MakeUnique<TestProxyDelegate>(); | 201 auto test_proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
| 202 test_proxy_delegate_ = test_proxy_delegate.get(); | 202 test_proxy_delegate_ = test_proxy_delegate.get(); |
| 203 | 203 |
| 204 test_proxy_delegate->set_alternative_proxy_server( | 204 test_proxy_delegate->set_alternative_proxy_server( |
| 205 ProxyServer::FromPacString("QUIC myproxy.org:443")); | 205 ProxyServer::FromPacString("QUIC myproxy.org:443")); |
| 206 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | 206 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); |
| 207 session_deps_.proxy_delegate = std::move(test_proxy_delegate); | 207 session_deps_.proxy_delegate = std::move(test_proxy_delegate); |
| 208 | 208 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 220 SpdySessionDependencies::CreateSessionParams(&session_deps_); | 220 SpdySessionDependencies::CreateSessionParams(&session_deps_); |
| 221 HttpNetworkSession::Context session_context = | 221 HttpNetworkSession::Context session_context = |
| 222 SpdySessionDependencies::CreateSessionContext(&session_deps_); | 222 SpdySessionDependencies::CreateSessionContext(&session_deps_); |
| 223 | 223 |
| 224 session_context.quic_crypto_client_stream_factory = | 224 session_context.quic_crypto_client_stream_factory = |
| 225 &crypto_client_stream_factory_; | 225 &crypto_client_stream_factory_; |
| 226 session_context.quic_random = &random_generator_; | 226 session_context.quic_random = &random_generator_; |
| 227 session_ = base::MakeUnique<HttpNetworkSession>(params, session_context); | 227 session_ = base::MakeUnique<HttpNetworkSession>(params, session_context); |
| 228 factory_ = | 228 factory_ = |
| 229 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 229 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 230 job_controller_ = new HttpStreamFactoryImpl::JobController( | 230 if (!skip_create_job_controller_) { |
|
Bence
2017/06/09 19:17:39
This feels like a double negation. It might be le
xunjieli
2017/06/13 15:23:11
Done. Good idea.
| |
| 231 factory_, &request_delegate_, session_.get(), &job_factory_, | 231 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 232 request_info, is_preconnect_, enable_ip_based_pooling_, | 232 factory_, &request_delegate_, session_.get(), &job_factory_, |
| 233 enable_alternative_services_, SSLConfig(), SSLConfig()); | 233 request_info, is_preconnect_, enable_ip_based_pooling_, |
| 234 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 234 enable_alternative_services_, SSLConfig(), SSLConfig()); |
| 235 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | |
| 236 } | |
| 235 } | 237 } |
| 236 | 238 |
| 237 TestProxyDelegate* test_proxy_delegate() const { | 239 TestProxyDelegate* test_proxy_delegate() const { |
| 238 return test_proxy_delegate_; | 240 return test_proxy_delegate_; |
| 239 } | 241 } |
| 240 | 242 |
| 241 ~HttpStreamFactoryImplJobControllerTest() override { | 243 ~HttpStreamFactoryImplJobControllerTest() override { |
| 242 if (quic_data_) { | 244 if (quic_data_) { |
| 243 EXPECT_TRUE(quic_data_->AllReadDataConsumed()); | 245 EXPECT_TRUE(quic_data_->AllReadDataConsumed()); |
| 244 EXPECT_TRUE(quic_data_->AllWriteDataConsumed()); | 246 EXPECT_TRUE(quic_data_->AllWriteDataConsumed()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 266 EXPECT_EQ(1u, alternative_service_info_vector.size()); | 268 EXPECT_EQ(1u, alternative_service_info_vector.size()); |
| 267 EXPECT_EQ(should_mark_broken, | 269 EXPECT_EQ(should_mark_broken, |
| 268 session_->http_server_properties()->IsAlternativeServiceBroken( | 270 session_->http_server_properties()->IsAlternativeServiceBroken( |
| 269 alternative_service_info_vector[0].alternative_service)); | 271 alternative_service_info_vector[0].alternative_service)); |
| 270 } | 272 } |
| 271 | 273 |
| 272 TestJobFactory job_factory_; | 274 TestJobFactory job_factory_; |
| 273 MockHttpStreamRequestDelegate request_delegate_; | 275 MockHttpStreamRequestDelegate request_delegate_; |
| 274 SpdySessionDependencies session_deps_; | 276 SpdySessionDependencies session_deps_; |
| 275 std::unique_ptr<HttpNetworkSession> session_; | 277 std::unique_ptr<HttpNetworkSession> session_; |
| 276 HttpStreamFactoryImpl* factory_; | 278 HttpStreamFactoryImpl* factory_ = nullptr; |
| 277 HttpStreamFactoryImpl::JobController* job_controller_; | 279 HttpStreamFactoryImpl::JobController* job_controller_ = nullptr; |
| 278 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; | 280 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; |
| 279 std::unique_ptr<SequencedSocketData> tcp_data_; | 281 std::unique_ptr<SequencedSocketData> tcp_data_; |
| 280 std::unique_ptr<test::MockQuicData> quic_data_; | 282 std::unique_ptr<test::MockQuicData> quic_data_; |
| 281 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 283 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 282 MockClock clock_; | 284 MockClock clock_; |
| 283 test::MockRandom random_generator_; | 285 test::MockRandom random_generator_; |
| 284 test::QuicTestPacketMaker client_maker_; | 286 test::QuicTestPacketMaker client_maker_; |
| 285 | 287 |
| 286 protected: | 288 protected: |
| 287 bool use_alternative_proxy_; | 289 bool use_alternative_proxy_ = false; |
| 288 bool is_preconnect_; | 290 bool is_preconnect_ = false; |
| 289 bool enable_ip_based_pooling_; | 291 bool enable_ip_based_pooling_ = true; |
| 290 bool enable_alternative_services_; | 292 bool enable_alternative_services_ = true; |
| 293 bool skip_create_job_controller_ = false; | |
| 291 | 294 |
| 292 private: | 295 private: |
| 293 // Not owned by |this|. | 296 // Not owned by |this|. |
| 294 TestProxyDelegate* test_proxy_delegate_; | 297 TestProxyDelegate* test_proxy_delegate_ = nullptr; |
| 295 | 298 |
| 296 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 299 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 297 }; | 300 }; |
| 298 | 301 |
| 299 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsSync) { | 302 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsSync) { |
| 300 ProxyConfig proxy_config; | 303 ProxyConfig proxy_config; |
| 301 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | 304 proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 302 proxy_config.set_pac_mandatory(true); | 305 proxy_config.set_pac_mandatory(true); |
| 303 session_deps_.proxy_service.reset(new ProxyService( | 306 session_deps_.proxy_service.reset(new ProxyService( |
| 304 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 307 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| (...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1556 PreconnectMultipleStreamsToH2Server) { | 1559 PreconnectMultipleStreamsToH2Server) { |
| 1557 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | 1560 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 1558 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); | 1561 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); |
| 1559 SetPreconnect(); | 1562 SetPreconnect(); |
| 1560 | 1563 |
| 1561 HttpRequestInfo request_info; | 1564 HttpRequestInfo request_info; |
| 1562 request_info.method = "GET"; | 1565 request_info.method = "GET"; |
| 1563 request_info.url = GURL("http://www.example.com"); | 1566 request_info.url = GURL("http://www.example.com"); |
| 1564 Initialize(request_info); | 1567 Initialize(request_info); |
| 1565 | 1568 |
| 1569 // Sets server support Http/2. | |
| 1566 url::SchemeHostPort server(request_info.url); | 1570 url::SchemeHostPort server(request_info.url); |
| 1567 | |
| 1568 // Sets server support Http/2. | |
| 1569 session_->http_server_properties()->SetSupportsSpdy(server, true); | 1571 session_->http_server_properties()->SetSupportsSpdy(server, true); |
| 1570 | 1572 |
| 1571 job_controller_->Preconnect(/*num_streams=*/5); | 1573 job_controller_->Preconnect(/*num_streams=*/5); |
| 1572 // Only one job is started. | 1574 // Only one job is started. |
| 1573 EXPECT_TRUE(job_controller_->main_job()); | 1575 EXPECT_TRUE(job_controller_->main_job()); |
| 1574 EXPECT_FALSE(job_controller_->alternative_job()); | 1576 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1575 EXPECT_EQ(HttpStreamFactoryImpl::PRECONNECT, | 1577 EXPECT_EQ(HttpStreamFactoryImpl::PRECONNECT, |
| 1576 job_controller_->main_job()->job_type()); | 1578 job_controller_->main_job()->job_type()); |
| 1577 // There is only 1 connect even though multiple streams were requested. | 1579 // There is only 1 connect even though multiple streams were requested. |
| 1578 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( | 1580 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( |
| 1579 job_controller_->main_job())); | 1581 job_controller_->main_job())); |
| 1580 | 1582 |
| 1581 base::RunLoop().RunUntilIdle(); | 1583 base::RunLoop().RunUntilIdle(); |
| 1582 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1584 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1583 } | 1585 } |
| 1584 | 1586 |
| 1587 class LimitMultipleH2Requests : public HttpStreamFactoryImplJobControllerTest { | |
|
Bence
2017/06/09 23:14:02
Optional: add a test case where the server is thou
xunjieli
2017/06/13 15:23:11
Good idea. Done.
| |
| 1588 protected: | |
| 1589 const int kNumRequests = 5; | |
| 1590 void SetUp() override { SetSkipCreateJobController(); } | |
|
Bence
2017/06/09 19:17:39
Why not set |skip_create_job_controller_| directly
xunjieli
2017/06/13 15:23:11
Done.
| |
| 1591 }; | |
| 1592 | |
| 1593 TEST_F(LimitMultipleH2Requests, MultipleRequests) { | |
| 1594 // Make sure there are only one socket connect. | |
|
Bence
2017/06/09 19:17:39
s/are/is/
xunjieli
2017/06/13 15:23:10
Done.
| |
| 1595 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; | |
| 1596 tcp_data_ = base::MakeUnique<SequencedSocketData>(reads, arraysize(reads), | |
| 1597 nullptr, 0); | |
| 1598 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); | |
| 1599 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
| 1600 ssl_data->next_proto = kProtoHTTP2; | |
| 1601 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
| 1602 HttpRequestInfo request_info; | |
| 1603 request_info.method = "GET"; | |
| 1604 request_info.url = GURL("https://www.example.com"); | |
| 1605 Initialize(request_info); | |
| 1606 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); | |
| 1607 pool_peer.SetEnableSendingInitialData(false); | |
| 1608 | |
| 1609 // Sets server support Http/2. | |
| 1610 url::SchemeHostPort server(request_info.url); | |
| 1611 session_->http_server_properties()->SetSupportsSpdy(server, true); | |
| 1612 | |
| 1613 std::vector<std::unique_ptr<MockHttpStreamRequestDelegate>> request_delegates; | |
|
Bence
2017/06/09 19:17:39
Could you use std::vector<MockHttpStreamRequestDel
xunjieli
2017/06/13 15:23:11
Acknowledged. MockHttpStreamRequestDelegate has no
| |
| 1614 std::vector<std::unique_ptr<HttpStreamRequest>> requests; | |
|
Bence
2017/06/09 19:17:39
I understand that this needs to use unique_ptr bec
xunjieli
2017/06/13 15:23:11
Acknowledged.
| |
| 1615 for (int i = 0; i < kNumRequests; ++i) { | |
| 1616 request_delegates.emplace_back( | |
|
Bence
2017/06/09 19:17:39
I think a simple push_back() would be enough here.
xunjieli
2017/06/13 15:23:10
Done.
| |
| 1617 base::MakeUnique<MockHttpStreamRequestDelegate>()); | |
| 1618 HttpStreamFactoryImpl::JobController* job_controller = | |
| 1619 new HttpStreamFactoryImpl::JobController( | |
| 1620 factory_, request_delegates[i].get(), session_.get(), &job_factory_, | |
| 1621 request_info, is_preconnect_, enable_ip_based_pooling_, | |
| 1622 enable_alternative_services_, SSLConfig(), SSLConfig()); | |
| 1623 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller); | |
| 1624 auto request = job_controller->Start( | |
| 1625 request_delegates[i].get(), nullptr, NetLogWithSource(), | |
| 1626 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); | |
| 1627 EXPECT_TRUE(job_controller->main_job()); | |
| 1628 EXPECT_FALSE(job_controller->alternative_job()); | |
| 1629 requests.push_back(std::move(request)); | |
| 1630 } | |
| 1631 | |
| 1632 for (int i = 0; i < kNumRequests; ++i) { | |
| 1633 EXPECT_CALL(*request_delegates[i].get(), OnStreamReadyImpl(_, _, _)); | |
| 1634 } | |
| 1635 | |
| 1636 base::RunLoop().RunUntilIdle(); | |
| 1637 requests.clear(); | |
| 1638 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | |
| 1639 } | |
| 1640 | |
| 1641 TEST_F(LimitMultipleH2Requests, MultipleRequestsFirstRequestHang) { | |
| 1642 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; | |
| 1643 // First socket connect hang. | |
| 1644 auto hangdata = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
| 1645 hangdata->set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); | |
| 1646 session_deps_.socket_factory->AddSocketDataProvider(hangdata.get()); | |
| 1647 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; | |
| 1648 std::vector<std::unique_ptr<SequencedSocketData>> socket_data; | |
|
Bence
2017/06/09 19:17:39
Hm, could you not just use std::vector<SequencedSo
xunjieli
2017/06/13 15:23:11
Same here. SequencedSocketData has DISALLOW_COPY_A
| |
| 1649 std::vector<std::unique_ptr<SSLSocketDataProvider>> ssl_socket_data; | |
|
Bence
2017/06/09 19:17:39
Same here.
xunjieli
2017/06/13 15:23:11
Acknowledged.
| |
| 1650 // kNumRequests - 1 will resume themselves after a delay. There will be | |
| 1651 // kNumRequests - 1 sockets opened. | |
| 1652 for (int i = 0; i < kNumRequests - 1; i++) { | |
| 1653 // Only the first one needs a MockRead because subsequent sockets are | |
| 1654 // not used to establish a SpdySession. | |
| 1655 auto tcp_data = | |
| 1656 i == 0 ? base::MakeUnique<SequencedSocketData>(reads, arraysize(reads), | |
| 1657 nullptr, 0) | |
| 1658 : base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
| 1659 tcp_data->set_connect_data(MockConnect(ASYNC, OK)); | |
| 1660 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
| 1661 ssl_data->next_proto = kProtoHTTP2; | |
| 1662 session_deps_.socket_factory->AddSocketDataProvider(tcp_data.get()); | |
| 1663 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
| 1664 socket_data.push_back(std::move(tcp_data)); | |
| 1665 ssl_socket_data.push_back(std::move(ssl_data)); | |
| 1666 } | |
| 1667 HttpRequestInfo request_info; | |
| 1668 request_info.method = "GET"; | |
| 1669 request_info.url = GURL("https://www.example.com"); | |
| 1670 SetSkipCreateJobController(); | |
|
Bence
2017/06/09 19:17:39
Please remove this call, as SetUp() already takes
xunjieli
2017/06/13 15:23:10
Done.
| |
| 1671 Initialize(request_info); | |
| 1672 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); | |
| 1673 pool_peer.SetEnableSendingInitialData(false); | |
| 1674 | |
| 1675 // Sets server support Http/2. | |
| 1676 url::SchemeHostPort server(request_info.url); | |
| 1677 session_->http_server_properties()->SetSupportsSpdy(server, true); | |
| 1678 | |
| 1679 std::vector<std::unique_ptr<MockHttpStreamRequestDelegate>> request_delegates; | |
| 1680 std::vector<std::unique_ptr<HttpStreamRequest>> requests; | |
| 1681 for (int i = 0; i < kNumRequests; ++i) { | |
| 1682 request_delegates.emplace_back( | |
| 1683 base::MakeUnique<MockHttpStreamRequestDelegate>()); | |
| 1684 HttpStreamFactoryImpl::JobController* job_controller = | |
| 1685 new HttpStreamFactoryImpl::JobController( | |
| 1686 factory_, request_delegates[i].get(), session_.get(), &job_factory_, | |
| 1687 request_info, is_preconnect_, enable_ip_based_pooling_, | |
| 1688 enable_alternative_services_, SSLConfig(), SSLConfig()); | |
| 1689 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller); | |
| 1690 auto request = job_controller->Start( | |
| 1691 request_delegates[i].get(), nullptr, NetLogWithSource(), | |
| 1692 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); | |
| 1693 EXPECT_TRUE(job_controller->main_job()); | |
| 1694 EXPECT_FALSE(job_controller->alternative_job()); | |
| 1695 requests.push_back(std::move(request)); | |
| 1696 } | |
| 1697 | |
| 1698 for (int i = 0; i < kNumRequests; ++i) { | |
| 1699 // Delete |request[i] when request completes is needed because | |
|
Bence
2017/06/09 19:17:39
s/request/requests/
Bence
2017/06/09 19:17:39
Nit: unmatched '|'.
xunjieli
2017/06/13 15:23:10
Done.
xunjieli
2017/06/13 15:23:11
Done.
| |
| 1700 // otherwise request will be completed twice. See crbug.com/706974. | |
| 1701 EXPECT_CALL(*request_delegates[i].get(), OnStreamReadyImpl(_, _, _)) | |
| 1702 .WillOnce(testing::InvokeWithoutArgs( | |
| 1703 [this, &requests, i]() { requests[i].reset(); })); | |
| 1704 } | |
| 1705 | |
| 1706 EXPECT_TRUE(test_task_runner->HasPendingTask()); | |
| 1707 test_task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(300)); | |
|
Bence
2017/06/09 19:17:39
Do you not need to use a larger time here to make
xunjieli
2017/06/13 15:23:11
Probably not. The delayed task is posted when |job
Bence
2017/06/13 16:04:51
Acknowledged.
| |
| 1708 base::RunLoop().RunUntilIdle(); | |
| 1709 | |
| 1710 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | |
| 1711 for (const auto& data : socket_data) { | |
| 1712 EXPECT_TRUE(data->AllReadDataConsumed()); | |
| 1713 EXPECT_TRUE(data->AllWriteDataConsumed()); | |
| 1714 } | |
| 1715 } | |
| 1716 | |
| 1717 TEST_F(LimitMultipleH2Requests, MultipleRequestsFirstRequestCanceled) { | |
| 1718 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; | |
| 1719 auto first_socket = base::MakeUnique<SequencedSocketData>( | |
| 1720 reads, arraysize(reads), nullptr, 0); | |
| 1721 first_socket->set_connect_data(MockConnect(ASYNC, OK)); | |
| 1722 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
| 1723 ssl_data->next_proto = kProtoHTTP2; | |
| 1724 session_deps_.socket_factory->AddSocketDataProvider(first_socket.get()); | |
| 1725 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
| 1726 auto second_socket = | |
| 1727 base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
| 1728 second_socket->set_connect_data(MockConnect(ASYNC, OK)); | |
| 1729 session_deps_.socket_factory->AddSocketDataProvider(second_socket.get()); | |
| 1730 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
| 1731 | |
| 1732 HttpRequestInfo request_info; | |
| 1733 request_info.method = "GET"; | |
| 1734 request_info.url = GURL("https://www.example.com"); | |
| 1735 SetSkipCreateJobController(); | |
|
Bence
2017/06/09 19:17:39
Please remove this call, as SetUp() already takes
xunjieli
2017/06/13 15:23:11
Done.
| |
| 1736 Initialize(request_info); | |
| 1737 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); | |
| 1738 pool_peer.SetEnableSendingInitialData(false); | |
| 1739 | |
| 1740 // Sets server support Http/2. | |
| 1741 url::SchemeHostPort server(request_info.url); | |
| 1742 session_->http_server_properties()->SetSupportsSpdy(server, true); | |
| 1743 | |
| 1744 std::vector<std::unique_ptr<MockHttpStreamRequestDelegate>> request_delegates; | |
| 1745 std::vector<std::unique_ptr<HttpStreamRequest>> requests; | |
| 1746 for (int i = 0; i < kNumRequests; ++i) { | |
| 1747 request_delegates.emplace_back( | |
| 1748 base::MakeUnique<MockHttpStreamRequestDelegate>()); | |
| 1749 HttpStreamFactoryImpl::JobController* job_controller = | |
| 1750 new HttpStreamFactoryImpl::JobController( | |
| 1751 factory_, request_delegates[i].get(), session_.get(), &job_factory_, | |
| 1752 request_info, is_preconnect_, enable_ip_based_pooling_, | |
| 1753 enable_alternative_services_, SSLConfig(), SSLConfig()); | |
| 1754 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller); | |
| 1755 auto request = job_controller->Start( | |
| 1756 request_delegates[i].get(), nullptr, NetLogWithSource(), | |
| 1757 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); | |
| 1758 EXPECT_TRUE(job_controller->main_job()); | |
| 1759 EXPECT_FALSE(job_controller->alternative_job()); | |
| 1760 requests.push_back(std::move(request)); | |
| 1761 } | |
| 1762 // Cancel the first one. | |
| 1763 requests[0].reset(); | |
| 1764 | |
| 1765 for (int i = 1; i < kNumRequests; ++i) { | |
| 1766 EXPECT_CALL(*request_delegates[i].get(), OnStreamReadyImpl(_, _, _)); | |
| 1767 } | |
| 1768 base::RunLoop().RunUntilIdle(); | |
| 1769 requests.clear(); | |
| 1770 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | |
| 1771 EXPECT_TRUE(first_socket->AllReadDataConsumed()); | |
| 1772 EXPECT_TRUE(second_socket->AllReadDataConsumed()); | |
| 1773 } | |
| 1774 | |
| 1775 TEST_F(LimitMultipleH2Requests, MultiplePreconnects) { | |
| 1776 // Make sure there are only one socket connect. | |
|
Bence
2017/06/09 19:17:38
s/are/is.
xunjieli
2017/06/13 15:23:11
Done.
| |
| 1777 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
| 1778 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); | |
| 1779 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
| 1780 ssl_data->next_proto = kProtoHTTP2; | |
| 1781 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
| 1782 HttpRequestInfo request_info; | |
| 1783 request_info.method = "GET"; | |
| 1784 request_info.url = GURL("https://www.example.com"); | |
| 1785 SetPreconnect(); | |
| 1786 Initialize(request_info); | |
| 1787 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); | |
| 1788 pool_peer.SetEnableSendingInitialData(false); | |
|
Bence
2017/06/09 19:17:39
Turns out these two lines are not necessary for th
xunjieli
2017/06/13 15:23:10
Done. Good catch.
| |
| 1789 | |
| 1790 // Sets server support Http/2. | |
| 1791 url::SchemeHostPort server(request_info.url); | |
| 1792 session_->http_server_properties()->SetSupportsSpdy(server, true); | |
| 1793 | |
| 1794 std::vector<std::unique_ptr<MockHttpStreamRequestDelegate>> request_delegates; | |
| 1795 std::vector<std::unique_ptr<HttpStreamRequest>> requests; | |
| 1796 for (int i = 0; i < kNumRequests; ++i) { | |
| 1797 request_delegates.emplace_back( | |
| 1798 base::MakeUnique<MockHttpStreamRequestDelegate>()); | |
| 1799 HttpStreamFactoryImpl::JobController* job_controller = | |
| 1800 new HttpStreamFactoryImpl::JobController( | |
| 1801 factory_, request_delegates[i].get(), session_.get(), &job_factory_, | |
| 1802 request_info, is_preconnect_, enable_ip_based_pooling_, | |
| 1803 enable_alternative_services_, SSLConfig(), SSLConfig()); | |
| 1804 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller); | |
| 1805 job_controller->Preconnect(1); | |
| 1806 EXPECT_TRUE(job_controller->main_job()); | |
| 1807 EXPECT_FALSE(job_controller->alternative_job()); | |
| 1808 } | |
| 1809 base::RunLoop().RunUntilIdle(); | |
| 1810 requests.clear(); | |
| 1811 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | |
| 1812 } | |
| 1813 | |
| 1585 class HttpStreamFactoryImplJobControllerMisdirectedRequestRetry | 1814 class HttpStreamFactoryImplJobControllerMisdirectedRequestRetry |
| 1586 : public HttpStreamFactoryImplJobControllerTest, | 1815 : public HttpStreamFactoryImplJobControllerTest, |
| 1587 public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {}; | 1816 public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {}; |
| 1588 | 1817 |
| 1589 INSTANTIATE_TEST_CASE_P( | 1818 INSTANTIATE_TEST_CASE_P( |
| 1590 /* no prefix */, | 1819 /* no prefix */, |
| 1591 HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, | 1820 HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, |
| 1592 ::testing::Combine(::testing::Bool(), ::testing::Bool())); | 1821 ::testing::Combine(::testing::Bool(), ::testing::Bool())); |
| 1593 | 1822 |
| 1594 TEST_P(HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, | 1823 TEST_P(HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1702 Preconnect(kNumPreconects); | 1931 Preconnect(kNumPreconects); |
| 1703 // If experiment is enabled, only 1 stream is requested. | 1932 // If experiment is enabled, only 1 stream is requested. |
| 1704 EXPECT_EQ( | 1933 EXPECT_EQ( |
| 1705 (int)actual_num_connects, | 1934 (int)actual_num_connects, |
| 1706 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1935 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 1707 base::RunLoop().RunUntilIdle(); | 1936 base::RunLoop().RunUntilIdle(); |
| 1708 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1937 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1709 } | 1938 } |
| 1710 | 1939 |
| 1711 } // namespace net | 1940 } // namespace net |
| OLD | NEW |