| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/cronet/url_request_context_config.h" | 5 #include "components/cronet/url_request_context_config.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/test/scoped_task_environment.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "net/cert/cert_verifier.h" | 10 #include "net/cert/cert_verifier.h" |
| 11 #include "net/http/http_network_session.h" | 11 #include "net/http/http_network_session.h" |
| 12 #include "net/log/net_log.h" | 12 #include "net/log/net_log.h" |
| 13 #include "net/log/net_log_with_source.h" | 13 #include "net/log/net_log_with_source.h" |
| 14 #include "net/proxy/proxy_config.h" | 14 #include "net/proxy/proxy_config.h" |
| 15 #include "net/proxy/proxy_config_service_fixed.h" | 15 #include "net/proxy/proxy_config_service_fixed.h" |
| 16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
| 17 #include "net/url_request/url_request_context_builder.h" | 17 #include "net/url_request/url_request_context_builder.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace cronet { | 20 namespace cronet { |
| 21 | 21 |
| 22 TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { | 22 TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { |
| 23 base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 24 base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 25 |
| 23 URLRequestContextConfig config( | 26 URLRequestContextConfig config( |
| 24 // Enable QUIC. | 27 // Enable QUIC. |
| 25 true, | 28 true, |
| 26 // QUIC User Agent ID. | 29 // QUIC User Agent ID. |
| 27 "Default QUIC User Agent ID", | 30 "Default QUIC User Agent ID", |
| 28 // Enable SPDY. | 31 // Enable SPDY. |
| 29 true, | 32 true, |
| 30 // Enable SDCH. | 33 // Enable SDCH. |
| 31 false, | 34 false, |
| 32 // Enable Brotli. | 35 // Enable Brotli. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 "\"disable_ipv6_on_wifi\":true}", | 60 "\"disable_ipv6_on_wifi\":true}", |
| 58 // MockCertVerifier to use for testing purposes. | 61 // MockCertVerifier to use for testing purposes. |
| 59 std::unique_ptr<net::CertVerifier>(), | 62 std::unique_ptr<net::CertVerifier>(), |
| 60 // Enable network quality estimator. | 63 // Enable network quality estimator. |
| 61 false, | 64 false, |
| 62 // Enable Public Key Pinning bypass for local trust anchors. | 65 // Enable Public Key Pinning bypass for local trust anchors. |
| 63 true, | 66 true, |
| 64 // Certificate verifier cache data. | 67 // Certificate verifier cache data. |
| 65 ""); | 68 ""); |
| 66 | 69 |
| 67 base::MessageLoop message_loop; | |
| 68 net::URLRequestContextBuilder builder; | 70 net::URLRequestContextBuilder builder; |
| 69 net::NetLog net_log; | 71 net::NetLog net_log; |
| 70 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr); | 72 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr); |
| 71 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption")); | 73 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption")); |
| 72 // Set a ProxyConfigService to avoid DCHECK failure when building. | 74 // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 73 builder.set_proxy_config_service( | 75 builder.set_proxy_config_service( |
| 74 base::MakeUnique<net::ProxyConfigServiceFixed>( | 76 base::MakeUnique<net::ProxyConfigServiceFixed>( |
| 75 net::ProxyConfig::CreateDirect())); | 77 net::ProxyConfig::CreateDirect())); |
| 76 std::unique_ptr<net::URLRequestContext> context(builder.Build()); | 78 std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 77 const net::HttpNetworkSession::Params* params = | 79 const net::HttpNetworkSession::Params* params = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 // Check IPv6 is disabled when on wifi. | 106 // Check IPv6 is disabled when on wifi. |
| 105 EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi()); | 107 EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi()); |
| 106 | 108 |
| 107 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80)); | 109 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80)); |
| 108 net::AddressList addresses; | 110 net::AddressList addresses; |
| 109 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache( | 111 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache( |
| 110 info, &addresses, net::NetLogWithSource())); | 112 info, &addresses, net::NetLogWithSource())); |
| 111 } | 113 } |
| 112 | 114 |
| 113 TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) { | 115 TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) { |
| 116 base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 117 base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 118 |
| 114 URLRequestContextConfig config( | 119 URLRequestContextConfig config( |
| 115 // Enable QUIC. | 120 // Enable QUIC. |
| 116 true, | 121 true, |
| 117 // QUIC User Agent ID. | 122 // QUIC User Agent ID. |
| 118 "Default QUIC User Agent ID", | 123 "Default QUIC User Agent ID", |
| 119 // Enable SPDY. | 124 // Enable SPDY. |
| 120 true, | 125 true, |
| 121 // Enable SDCH. | 126 // Enable SDCH. |
| 122 false, | 127 false, |
| 123 // Enable Brotli. | 128 // Enable Brotli. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 "\"migrate_sessions_early\":true}}", | 143 "\"migrate_sessions_early\":true}}", |
| 139 // MockCertVerifier to use for testing purposes. | 144 // MockCertVerifier to use for testing purposes. |
| 140 std::unique_ptr<net::CertVerifier>(), | 145 std::unique_ptr<net::CertVerifier>(), |
| 141 // Enable network quality estimator. | 146 // Enable network quality estimator. |
| 142 false, | 147 false, |
| 143 // Enable Public Key Pinning bypass for local trust anchors. | 148 // Enable Public Key Pinning bypass for local trust anchors. |
| 144 true, | 149 true, |
| 145 // Certificate verifier cache data. | 150 // Certificate verifier cache data. |
| 146 ""); | 151 ""); |
| 147 | 152 |
| 148 base::MessageLoop message_loop; | |
| 149 net::URLRequestContextBuilder builder; | 153 net::URLRequestContextBuilder builder; |
| 150 net::NetLog net_log; | 154 net::NetLog net_log; |
| 151 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr); | 155 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr); |
| 152 // Set a ProxyConfigService to avoid DCHECK failure when building. | 156 // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 153 builder.set_proxy_config_service( | 157 builder.set_proxy_config_service( |
| 154 base::MakeUnique<net::ProxyConfigServiceFixed>( | 158 base::MakeUnique<net::ProxyConfigServiceFixed>( |
| 155 net::ProxyConfig::CreateDirect())); | 159 net::ProxyConfig::CreateDirect())); |
| 156 std::unique_ptr<net::URLRequestContext> context(builder.Build()); | 160 std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 157 const net::HttpNetworkSession::Params* params = | 161 const net::HttpNetworkSession::Params* params = |
| 158 context->GetNetworkSessionParams(); | 162 context->GetNetworkSessionParams(); |
| 159 | 163 |
| 160 EXPECT_FALSE(params->quic_close_sessions_on_ip_change); | 164 EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
| 161 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change); | 165 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change); |
| 162 EXPECT_TRUE(params->quic_migrate_sessions_early); | 166 EXPECT_TRUE(params->quic_migrate_sessions_early); |
| 163 } | 167 } |
| 164 | 168 |
| 165 // See stale_host_resolver_unittest.cc for test of StaleDNS options. | 169 // See stale_host_resolver_unittest.cc for test of StaleDNS options. |
| 166 | 170 |
| 167 } // namespace cronet | 171 } // namespace cronet |
| OLD | NEW |