| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/cronet/stale_host_resolver.h" | 5 #include "components/cronet/stale_host_resolver.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/scoped_task_environment.h" |
| 13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/cronet/url_request_context_config.h" | 16 #include "components/cronet/url_request_context_config.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
| 19 #include "net/cert/cert_verifier.h" | 19 #include "net/cert/cert_verifier.h" |
| 20 #include "net/dns/host_resolver_proc.h" | 20 #include "net/dns/host_resolver_proc.h" |
| 21 #include "net/http/http_network_session.h" | 21 #include "net/http/http_network_session.h" |
| 22 #include "net/log/net_log.h" | 22 #include "net/log/net_log.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return net::OK; | 75 return net::OK; |
| 76 } | 76 } |
| 77 | 77 |
| 78 protected: | 78 protected: |
| 79 ~MockHostResolverProc() override {} | 79 ~MockHostResolverProc() override {} |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 class StaleHostResolverTest : public testing::Test { | 82 class StaleHostResolverTest : public testing::Test { |
| 83 protected: | 83 protected: |
| 84 StaleHostResolverTest() | 84 StaleHostResolverTest() |
| 85 : mock_proc_(new MockHostResolverProc()), | 85 : scoped_task_environment_( |
| 86 base::test::ScopedTaskEnvironment::MainThreadType::IO), |
| 87 mock_proc_(new MockHostResolverProc()), |
| 86 resolver_(nullptr), | 88 resolver_(nullptr), |
| 87 resolve_pending_(false), | 89 resolve_pending_(false), |
| 88 resolve_complete_(false) {} | 90 resolve_complete_(false) {} |
| 89 | 91 |
| 90 ~StaleHostResolverTest() override {} | 92 ~StaleHostResolverTest() override {} |
| 91 | 93 |
| 92 void SetStaleDelay(int stale_delay_sec) { | 94 void SetStaleDelay(int stale_delay_sec) { |
| 93 DCHECK(!resolver_); | 95 DCHECK(!resolver_); |
| 94 | 96 |
| 95 options_.delay = base::TimeDelta::FromSeconds(stale_delay_sec); | 97 options_.delay = base::TimeDelta::FromSeconds(stale_delay_sec); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 252 } |
| 251 | 253 |
| 252 bool resolve_complete() const { return resolve_complete_; } | 254 bool resolve_complete() const { return resolve_complete_; } |
| 253 int resolve_error() const { return resolve_error_; } | 255 int resolve_error() const { return resolve_error_; } |
| 254 const net::AddressList& resolve_addresses() const { | 256 const net::AddressList& resolve_addresses() const { |
| 255 return resolve_addresses_; | 257 return resolve_addresses_; |
| 256 } | 258 } |
| 257 | 259 |
| 258 private: | 260 private: |
| 259 // Needed for HostResolver to run HostResolverProc callbacks. | 261 // Needed for HostResolver to run HostResolverProc callbacks. |
| 260 base::MessageLoopForIO message_loop_for_io_; | 262 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 263 |
| 261 scoped_refptr<MockHostResolverProc> mock_proc_; | 264 scoped_refptr<MockHostResolverProc> mock_proc_; |
| 262 | 265 |
| 263 net::HostResolver* resolver_; | 266 net::HostResolver* resolver_; |
| 264 StaleHostResolver::StaleOptions options_; | 267 StaleHostResolver::StaleOptions options_; |
| 265 std::unique_ptr<StaleHostResolver> stale_resolver_; | 268 std::unique_ptr<StaleHostResolver> stale_resolver_; |
| 266 | 269 |
| 267 base::TimeTicks now_; | 270 base::TimeTicks now_; |
| 268 std::unique_ptr<net::HostResolver::Request> request_; | 271 std::unique_ptr<net::HostResolver::Request> request_; |
| 269 bool resolve_pending_; | 272 bool resolve_pending_; |
| 270 bool resolve_complete_; | 273 bool resolve_complete_; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 EXPECT_EQ(1u, resolve_addresses().size()) << i; | 437 EXPECT_EQ(1u, resolve_addresses().size()) << i; |
| 435 { | 438 { |
| 436 const char* expected = test_case.usable ? kCacheAddress : kNetworkAddress; | 439 const char* expected = test_case.usable ? kCacheAddress : kNetworkAddress; |
| 437 EXPECT_EQ(expected, resolve_addresses()[0].ToStringWithoutPort()) << i; | 440 EXPECT_EQ(expected, resolve_addresses()[0].ToStringWithoutPort()) << i; |
| 438 } | 441 } |
| 439 | 442 |
| 440 DestroyResolver(); | 443 DestroyResolver(); |
| 441 } | 444 } |
| 442 } | 445 } |
| 443 | 446 |
| 444 // Test is flaky. See https://crbug.com/737326. | 447 TEST_F(StaleHostResolverTest, CreatedByContext) { |
| 445 TEST_F(StaleHostResolverTest, DISABLED_CreatedByContext) { | |
| 446 URLRequestContextConfig config( | 448 URLRequestContextConfig config( |
| 447 // Enable QUIC. | 449 // Enable QUIC. |
| 448 true, | 450 true, |
| 449 // QUIC User Agent ID. | 451 // QUIC User Agent ID. |
| 450 "Default QUIC User Agent ID", | 452 "Default QUIC User Agent ID", |
| 451 // Enable SPDY. | 453 // Enable SPDY. |
| 452 true, | 454 true, |
| 453 // Enable SDCH. | 455 // Enable SDCH. |
| 454 false, | 456 false, |
| 455 // Enable Brotli. | 457 // Enable Brotli. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 502 |
| 501 EXPECT_TRUE(resolve_complete()); | 503 EXPECT_TRUE(resolve_complete()); |
| 502 EXPECT_EQ(net::OK, resolve_error()); | 504 EXPECT_EQ(net::OK, resolve_error()); |
| 503 EXPECT_EQ(1u, resolve_addresses().size()); | 505 EXPECT_EQ(1u, resolve_addresses().size()); |
| 504 EXPECT_EQ(kCacheAddress, resolve_addresses()[0].ToStringWithoutPort()); | 506 EXPECT_EQ(kCacheAddress, resolve_addresses()[0].ToStringWithoutPort()); |
| 505 } | 507 } |
| 506 | 508 |
| 507 } // namespace | 509 } // namespace |
| 508 | 510 |
| 509 } // namespace cronet | 511 } // namespace cronet |
| OLD | NEW |