OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/proxy/dhcp_proxy_script_adapter_fetcher_win.h" | 5 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" |
6 | 6 |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 base::WaitableEvent test_finished_event_; | 80 base::WaitableEvent test_finished_event_; |
81 base::TimeDelta dhcp_delay_; | 81 base::TimeDelta dhcp_delay_; |
82 std::string configured_url_; | 82 std::string configured_url_; |
83 }; | 83 }; |
84 | 84 |
85 virtual DhcpQuery* ImplCreateDhcpQuery() override { | 85 virtual DhcpQuery* ImplCreateDhcpQuery() override { |
86 dhcp_query_ = new DelayingDhcpQuery(); | 86 dhcp_query_ = new DelayingDhcpQuery(); |
87 dhcp_query_->dhcp_delay_ = dhcp_delay_; | 87 dhcp_query_->dhcp_delay_ = dhcp_delay_; |
88 dhcp_query_->configured_url_ = configured_url_; | 88 dhcp_query_->configured_url_ = configured_url_; |
89 return dhcp_query_; | 89 return dhcp_query_.get(); |
90 } | 90 } |
91 | 91 |
92 // Use a shorter timeout so tests can finish more quickly. | 92 // Use a shorter timeout so tests can finish more quickly. |
93 virtual base::TimeDelta ImplGetTimeout() const override { | 93 virtual base::TimeDelta ImplGetTimeout() const override { |
94 return timeout_; | 94 return timeout_; |
95 } | 95 } |
96 | 96 |
97 void OnFetcherTimer() { | 97 void OnFetcherTimer() { |
98 // Note that there is an assumption by this mock implementation that | 98 // Note that there is an assumption by this mock implementation that |
99 // DhcpProxyScriptAdapterFetcher::Fetch will call ImplCreateScriptFetcher | 99 // DhcpProxyScriptAdapterFetcher::Fetch will call ImplCreateScriptFetcher |
100 // and call Fetch on the fetcher before the message loop is re-entered. | 100 // and call Fetch on the fetcher before the message loop is re-entered. |
101 // This holds true today, but if you hit this DCHECK the problem can | 101 // This holds true today, but if you hit this DCHECK the problem can |
102 // possibly be resolved by having a separate subclass of | 102 // possibly be resolved by having a separate subclass of |
103 // MockProxyScriptFetcher that adds the delay internally (instead of | 103 // MockProxyScriptFetcher that adds the delay internally (instead of |
104 // the simple approach currently used in ImplCreateScriptFetcher above). | 104 // the simple approach currently used in ImplCreateScriptFetcher above). |
105 DCHECK(fetcher_ && fetcher_->has_pending_request()); | 105 DCHECK(fetcher_ && fetcher_->has_pending_request()); |
106 fetcher_->NotifyFetchCompletion(fetcher_result_, pac_script_); | 106 fetcher_->NotifyFetchCompletion(fetcher_result_, pac_script_); |
107 fetcher_ = NULL; | 107 fetcher_ = NULL; |
108 } | 108 } |
109 | 109 |
110 bool IsWaitingForFetcher() const { | 110 bool IsWaitingForFetcher() const { |
111 return state() == STATE_WAIT_URL; | 111 return state() == STATE_WAIT_URL; |
112 } | 112 } |
113 | 113 |
114 bool WasCancelled() const { | 114 bool WasCancelled() const { |
115 return state() == STATE_CANCEL; | 115 return state() == STATE_CANCEL; |
116 } | 116 } |
117 | 117 |
118 void FinishTest() { | 118 void FinishTest() { |
119 DCHECK(dhcp_query_); | 119 DCHECK(dhcp_query_.get()); |
120 dhcp_query_->test_finished_event_.Signal(); | 120 dhcp_query_->test_finished_event_.Signal(); |
121 } | 121 } |
122 | 122 |
123 base::TimeDelta dhcp_delay_; | 123 base::TimeDelta dhcp_delay_; |
124 base::TimeDelta timeout_; | 124 base::TimeDelta timeout_; |
125 std::string configured_url_; | 125 std::string configured_url_; |
126 int fetcher_delay_ms_; | 126 int fetcher_delay_ms_; |
127 int fetcher_result_; | 127 int fetcher_result_; |
128 std::string pac_script_; | 128 std::string pac_script_; |
129 MockProxyScriptFetcher* fetcher_; | 129 MockProxyScriptFetcher* fetcher_; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 EXPECT_EQ(BASE_URL, | 329 EXPECT_EQ(BASE_URL, |
330 DhcpProxyScriptAdapterFetcher::SanitizeDhcpApiString( | 330 DhcpProxyScriptAdapterFetcher::SanitizeDhcpApiString( |
331 BASE_URL "\0foo\0blat", kBaseUrlLen + 9)); | 331 BASE_URL "\0foo\0blat", kBaseUrlLen + 9)); |
332 } | 332 } |
333 | 333 |
334 #undef BASE_URL | 334 #undef BASE_URL |
335 | 335 |
336 } // namespace | 336 } // namespace |
337 | 337 |
338 } // namespace net | 338 } // namespace net |
OLD | NEW |