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_fetcher_win.h" | 5 #include "net/proxy/dhcp_proxy_script_fetcher_win.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Helper for RealFetch* tests below. | 47 // Helper for RealFetch* tests below. |
48 class RealFetchTester { | 48 class RealFetchTester { |
49 public: | 49 public: |
50 RealFetchTester() | 50 RealFetchTester() |
51 : context_(new TestURLRequestContext), | 51 : context_(new TestURLRequestContext), |
52 fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), | 52 fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), |
53 finished_(false), | 53 finished_(false), |
54 on_completion_is_error_(false) { | 54 on_completion_is_error_(false) { |
55 // Make sure the test ends. | 55 // Make sure the test ends. |
56 timeout_.Start(FROM_HERE, | 56 timeout_.Start(FROM_HERE, |
57 base::TimeDelta::FromSeconds(5), this, &RealFetchTester::OnTimeout); | 57 base::TimeDelta::FromSeconds(5), |
| 58 this, |
| 59 &RealFetchTester::OnTimeout); |
58 } | 60 } |
59 | 61 |
60 void RunTest() { | 62 void RunTest() { |
61 int result = fetcher_->Fetch( | 63 int result = fetcher_->Fetch( |
62 &pac_text_, | 64 &pac_text_, |
63 base::Bind(&RealFetchTester::OnCompletion, base::Unretained(this))); | 65 base::Bind(&RealFetchTester::OnCompletion, base::Unretained(this))); |
64 if (result != ERR_IO_PENDING) | 66 if (result != ERR_IO_PENDING) |
65 finished_ = true; | 67 finished_ = true; |
66 } | 68 } |
67 | 69 |
68 void RunTestWithCancel() { | 70 void RunTestWithCancel() { |
69 RunTest(); | 71 RunTest(); |
70 fetcher_->Cancel(); | 72 fetcher_->Cancel(); |
71 } | 73 } |
72 | 74 |
73 void RunTestWithDeferredCancel() { | 75 void RunTestWithDeferredCancel() { |
74 // Put the cancellation into the queue before even running the | 76 // Put the cancellation into the queue before even running the |
75 // test to avoid the chance of one of the adapter fetcher worker | 77 // test to avoid the chance of one of the adapter fetcher worker |
76 // threads completing before cancellation. See http://crbug.com/86756. | 78 // threads completing before cancellation. See http://crbug.com/86756. |
77 cancel_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0), | 79 cancel_timer_.Start(FROM_HERE, |
78 this, &RealFetchTester::OnCancelTimer); | 80 base::TimeDelta::FromMilliseconds(0), |
| 81 this, |
| 82 &RealFetchTester::OnCancelTimer); |
79 RunTest(); | 83 RunTest(); |
80 } | 84 } |
81 | 85 |
82 void OnCompletion(int result) { | 86 void OnCompletion(int result) { |
83 if (on_completion_is_error_) { | 87 if (on_completion_is_error_) { |
84 FAIL() << "Received completion for test in which this is error."; | 88 FAIL() << "Received completion for test in which this is error."; |
85 } | 89 } |
86 finished_ = true; | 90 finished_ = true; |
87 printf("Result code %d PAC data length %d\n", result, pac_text_.size()); | 91 printf("Result code %d PAC data length %d\n", result, pac_text_.size()); |
88 } | 92 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // | 132 // |
129 // We don't make assumptions about the environment this unit test is | 133 // We don't make assumptions about the environment this unit test is |
130 // running in, so it just exercises the code to make sure there | 134 // running in, so it just exercises the code to make sure there |
131 // is no crash and no unexpected error returned, but does not assert on | 135 // is no crash and no unexpected error returned, but does not assert on |
132 // results beyond that. | 136 // results beyond that. |
133 RealFetchTester fetcher; | 137 RealFetchTester fetcher; |
134 fetcher.RunTest(); | 138 fetcher.RunTest(); |
135 | 139 |
136 fetcher.WaitUntilDone(); | 140 fetcher.WaitUntilDone(); |
137 printf("PAC URL was %s\n", | 141 printf("PAC URL was %s\n", |
138 fetcher.fetcher_->GetPacURL().possibly_invalid_spec().c_str()); | 142 fetcher.fetcher_->GetPacURL().possibly_invalid_spec().c_str()); |
139 | 143 |
140 fetcher.FinishTestAllowCleanup(); | 144 fetcher.FinishTestAllowCleanup(); |
141 } | 145 } |
142 | 146 |
143 TEST(DhcpProxyScriptFetcherWin, RealFetchWithCancel) { | 147 TEST(DhcpProxyScriptFetcherWin, RealFetchWithCancel) { |
144 // Does a Fetch() with an immediate cancel. As before, just | 148 // Does a Fetch() with an immediate cancel. As before, just |
145 // exercises the code without stubbing out dependencies. | 149 // exercises the code without stubbing out dependencies. |
146 RealFetchTester fetcher; | 150 RealFetchTester fetcher; |
147 fetcher.RunTestWithCancel(); | 151 fetcher.RunTestWithCancel(); |
148 base::MessageLoop::current()->RunUntilIdle(); | 152 base::MessageLoop::current()->RunUntilIdle(); |
149 | 153 |
150 // Attempt to avoid Valgrind leak reports in case worker thread is | 154 // Attempt to avoid Valgrind leak reports in case worker thread is |
151 // still running. | 155 // still running. |
152 fetcher.FinishTestAllowCleanup(); | 156 fetcher.FinishTestAllowCleanup(); |
153 } | 157 } |
154 | 158 |
155 // For RealFetchWithDeferredCancel, below. | 159 // For RealFetchWithDeferredCancel, below. |
156 class DelayingDhcpProxyScriptAdapterFetcher | 160 class DelayingDhcpProxyScriptAdapterFetcher |
157 : public DhcpProxyScriptAdapterFetcher { | 161 : public DhcpProxyScriptAdapterFetcher { |
158 public: | 162 public: |
159 DelayingDhcpProxyScriptAdapterFetcher( | 163 DelayingDhcpProxyScriptAdapterFetcher( |
160 URLRequestContext* url_request_context, | 164 URLRequestContext* url_request_context, |
161 scoped_refptr<base::TaskRunner> task_runner) | 165 scoped_refptr<base::TaskRunner> task_runner) |
162 : DhcpProxyScriptAdapterFetcher(url_request_context, task_runner) { | 166 : DhcpProxyScriptAdapterFetcher(url_request_context, task_runner) {} |
163 } | |
164 | 167 |
165 class DelayingDhcpQuery : public DhcpQuery { | 168 class DelayingDhcpQuery : public DhcpQuery { |
166 public: | 169 public: |
167 explicit DelayingDhcpQuery() | 170 explicit DelayingDhcpQuery() : DhcpQuery() {} |
168 : DhcpQuery() { | |
169 } | |
170 | 171 |
171 std::string ImplGetPacURLFromDhcp( | 172 std::string ImplGetPacURLFromDhcp( |
172 const std::string& adapter_name) OVERRIDE { | 173 const std::string& adapter_name) OVERRIDE { |
173 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | 174 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
174 return DhcpQuery::ImplGetPacURLFromDhcp(adapter_name); | 175 return DhcpQuery::ImplGetPacURLFromDhcp(adapter_name); |
175 } | 176 } |
176 }; | 177 }; |
177 | 178 |
178 DhcpQuery* ImplCreateDhcpQuery() OVERRIDE { | 179 DhcpQuery* ImplCreateDhcpQuery() OVERRIDE { return new DelayingDhcpQuery(); } |
179 return new DelayingDhcpQuery(); | |
180 } | |
181 }; | 180 }; |
182 | 181 |
183 // For RealFetchWithDeferredCancel, below. | 182 // For RealFetchWithDeferredCancel, below. |
184 class DelayingDhcpProxyScriptFetcherWin | 183 class DelayingDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
185 : public DhcpProxyScriptFetcherWin { | |
186 public: | 184 public: |
187 explicit DelayingDhcpProxyScriptFetcherWin( | 185 explicit DelayingDhcpProxyScriptFetcherWin(URLRequestContext* context) |
188 URLRequestContext* context) | 186 : DhcpProxyScriptFetcherWin(context) {} |
189 : DhcpProxyScriptFetcherWin(context) { | |
190 } | |
191 | 187 |
192 DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher() OVERRIDE { | 188 DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher() OVERRIDE { |
193 return new DelayingDhcpProxyScriptAdapterFetcher(url_request_context(), | 189 return new DelayingDhcpProxyScriptAdapterFetcher(url_request_context(), |
194 GetTaskRunner()); | 190 GetTaskRunner()); |
195 } | 191 } |
196 }; | 192 }; |
197 | 193 |
198 TEST(DhcpProxyScriptFetcherWin, RealFetchWithDeferredCancel) { | 194 TEST(DhcpProxyScriptFetcherWin, RealFetchWithDeferredCancel) { |
199 // Does a Fetch() with a slightly delayed cancel. As before, just | 195 // Does a Fetch() with a slightly delayed cancel. As before, just |
200 // exercises the code without stubbing out dependencies, but | 196 // exercises the code without stubbing out dependencies, but |
(...skipping 12 matching lines...) Expand all Loading... |
213 | 209 |
214 class DummyDhcpProxyScriptAdapterFetcher | 210 class DummyDhcpProxyScriptAdapterFetcher |
215 : public DhcpProxyScriptAdapterFetcher { | 211 : public DhcpProxyScriptAdapterFetcher { |
216 public: | 212 public: |
217 DummyDhcpProxyScriptAdapterFetcher(URLRequestContext* context, | 213 DummyDhcpProxyScriptAdapterFetcher(URLRequestContext* context, |
218 scoped_refptr<base::TaskRunner> runner) | 214 scoped_refptr<base::TaskRunner> runner) |
219 : DhcpProxyScriptAdapterFetcher(context, runner), | 215 : DhcpProxyScriptAdapterFetcher(context, runner), |
220 did_finish_(false), | 216 did_finish_(false), |
221 result_(OK), | 217 result_(OK), |
222 pac_script_(L"bingo"), | 218 pac_script_(L"bingo"), |
223 fetch_delay_ms_(1) { | 219 fetch_delay_ms_(1) {} |
224 } | |
225 | 220 |
226 void Fetch(const std::string& adapter_name, | 221 void Fetch(const std::string& adapter_name, |
227 const CompletionCallback& callback) OVERRIDE { | 222 const CompletionCallback& callback) OVERRIDE { |
228 callback_ = callback; | 223 callback_ = callback; |
229 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(fetch_delay_ms_), | 224 timer_.Start(FROM_HERE, |
230 this, &DummyDhcpProxyScriptAdapterFetcher::OnTimer); | 225 base::TimeDelta::FromMilliseconds(fetch_delay_ms_), |
| 226 this, |
| 227 &DummyDhcpProxyScriptAdapterFetcher::OnTimer); |
231 } | 228 } |
232 | 229 |
233 void Cancel() OVERRIDE { | 230 void Cancel() OVERRIDE { timer_.Stop(); } |
234 timer_.Stop(); | |
235 } | |
236 | 231 |
237 bool DidFinish() const OVERRIDE { | 232 bool DidFinish() const OVERRIDE { return did_finish_; } |
238 return did_finish_; | |
239 } | |
240 | 233 |
241 int GetResult() const OVERRIDE { | 234 int GetResult() const OVERRIDE { return result_; } |
242 return result_; | |
243 } | |
244 | 235 |
245 base::string16 GetPacScript() const OVERRIDE { | 236 base::string16 GetPacScript() const OVERRIDE { return pac_script_; } |
246 return pac_script_; | |
247 } | |
248 | 237 |
249 void OnTimer() { | 238 void OnTimer() { callback_.Run(result_); } |
250 callback_.Run(result_); | |
251 } | |
252 | 239 |
253 void Configure(bool did_finish, | 240 void Configure(bool did_finish, |
254 int result, | 241 int result, |
255 base::string16 pac_script, | 242 base::string16 pac_script, |
256 int fetch_delay_ms) { | 243 int fetch_delay_ms) { |
257 did_finish_ = did_finish; | 244 did_finish_ = did_finish; |
258 result_ = result; | 245 result_ = result; |
259 pac_script_ = pac_script; | 246 pac_script_ = pac_script; |
260 fetch_delay_ms_ = fetch_delay_ms; | 247 fetch_delay_ms_ = fetch_delay_ms; |
261 } | 248 } |
262 | 249 |
263 private: | 250 private: |
264 bool did_finish_; | 251 bool did_finish_; |
265 int result_; | 252 int result_; |
266 base::string16 pac_script_; | 253 base::string16 pac_script_; |
267 int fetch_delay_ms_; | 254 int fetch_delay_ms_; |
268 CompletionCallback callback_; | 255 CompletionCallback callback_; |
269 base::OneShotTimer<DummyDhcpProxyScriptAdapterFetcher> timer_; | 256 base::OneShotTimer<DummyDhcpProxyScriptAdapterFetcher> timer_; |
270 }; | 257 }; |
271 | 258 |
272 class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { | 259 class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
273 public: | 260 public: |
274 class MockAdapterQuery : public AdapterQuery { | 261 class MockAdapterQuery : public AdapterQuery { |
275 public: | 262 public: |
276 MockAdapterQuery() { | 263 MockAdapterQuery() {} |
277 } | |
278 | 264 |
279 virtual ~MockAdapterQuery() { | 265 virtual ~MockAdapterQuery() {} |
280 } | |
281 | 266 |
282 virtual bool ImplGetCandidateAdapterNames( | 267 virtual bool ImplGetCandidateAdapterNames( |
283 std::set<std::string>* adapter_names) OVERRIDE { | 268 std::set<std::string>* adapter_names) OVERRIDE { |
284 adapter_names->insert( | 269 adapter_names->insert(mock_adapter_names_.begin(), |
285 mock_adapter_names_.begin(), mock_adapter_names_.end()); | 270 mock_adapter_names_.end()); |
286 return true; | 271 return true; |
287 } | 272 } |
288 | 273 |
289 std::vector<std::string> mock_adapter_names_; | 274 std::vector<std::string> mock_adapter_names_; |
290 }; | 275 }; |
291 | 276 |
292 MockDhcpProxyScriptFetcherWin(URLRequestContext* context) | 277 MockDhcpProxyScriptFetcherWin(URLRequestContext* context) |
293 : DhcpProxyScriptFetcherWin(context), | 278 : DhcpProxyScriptFetcherWin(context), |
294 num_fetchers_created_(0), | 279 num_fetchers_created_(0), |
295 worker_finished_event_(true, false) { | 280 worker_finished_event_(true, false) { |
296 ResetTestState(); | 281 ResetTestState(); |
297 } | 282 } |
298 | 283 |
299 virtual ~MockDhcpProxyScriptFetcherWin() { | 284 virtual ~MockDhcpProxyScriptFetcherWin() { ResetTestState(); } |
300 ResetTestState(); | |
301 } | |
302 | 285 |
303 using DhcpProxyScriptFetcherWin::GetTaskRunner; | 286 using DhcpProxyScriptFetcherWin::GetTaskRunner; |
304 | 287 |
305 // Adds a fetcher object to the queue of fetchers used by | 288 // Adds a fetcher object to the queue of fetchers used by |
306 // |ImplCreateAdapterFetcher()|, and its name to the list of adapters | 289 // |ImplCreateAdapterFetcher()|, and its name to the list of adapters |
307 // returned by ImplGetCandidateAdapterNames. | 290 // returned by ImplGetCandidateAdapterNames. |
308 void PushBackAdapter(const std::string& adapter_name, | 291 void PushBackAdapter(const std::string& adapter_name, |
309 DhcpProxyScriptAdapterFetcher* fetcher) { | 292 DhcpProxyScriptAdapterFetcher* fetcher) { |
310 adapter_query_->mock_adapter_names_.push_back(adapter_name); | 293 adapter_query_->mock_adapter_names_.push_back(adapter_name); |
311 adapter_fetchers_.push_back(fetcher); | 294 adapter_fetchers_.push_back(fetcher); |
(...skipping 15 matching lines...) Expand all Loading... |
327 DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher() OVERRIDE { | 310 DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher() OVERRIDE { |
328 ++num_fetchers_created_; | 311 ++num_fetchers_created_; |
329 return adapter_fetchers_[next_adapter_fetcher_index_++]; | 312 return adapter_fetchers_[next_adapter_fetcher_index_++]; |
330 } | 313 } |
331 | 314 |
332 virtual AdapterQuery* ImplCreateAdapterQuery() OVERRIDE { | 315 virtual AdapterQuery* ImplCreateAdapterQuery() OVERRIDE { |
333 DCHECK(adapter_query_); | 316 DCHECK(adapter_query_); |
334 return adapter_query_.get(); | 317 return adapter_query_.get(); |
335 } | 318 } |
336 | 319 |
337 base::TimeDelta ImplGetMaxWait() OVERRIDE { | 320 base::TimeDelta ImplGetMaxWait() OVERRIDE { return max_wait_; } |
338 return max_wait_; | |
339 } | |
340 | 321 |
341 void ImplOnGetCandidateAdapterNamesDone() OVERRIDE { | 322 void ImplOnGetCandidateAdapterNamesDone() OVERRIDE { |
342 worker_finished_event_.Signal(); | 323 worker_finished_event_.Signal(); |
343 } | 324 } |
344 | 325 |
345 void ResetTestState() { | 326 void ResetTestState() { |
346 // Delete any adapter fetcher objects we didn't hand out. | 327 // Delete any adapter fetcher objects we didn't hand out. |
347 std::vector<DhcpProxyScriptAdapterFetcher*>::const_iterator it | 328 std::vector<DhcpProxyScriptAdapterFetcher*>::const_iterator it = |
348 = adapter_fetchers_.begin(); | 329 adapter_fetchers_.begin(); |
349 for (; it != adapter_fetchers_.end(); ++it) { | 330 for (; it != adapter_fetchers_.end(); ++it) { |
350 if (num_fetchers_created_-- <= 0) { | 331 if (num_fetchers_created_-- <= 0) { |
351 delete (*it); | 332 delete (*it); |
352 } | 333 } |
353 } | 334 } |
354 | 335 |
355 next_adapter_fetcher_index_ = 0; | 336 next_adapter_fetcher_index_ = 0; |
356 num_fetchers_created_ = 0; | 337 num_fetchers_created_ = 0; |
357 adapter_fetchers_.clear(); | 338 adapter_fetchers_.clear(); |
358 adapter_query_ = new MockAdapterQuery(); | 339 adapter_query_ = new MockAdapterQuery(); |
359 max_wait_ = TestTimeouts::tiny_timeout(); | 340 max_wait_ = TestTimeouts::tiny_timeout(); |
360 } | 341 } |
361 | 342 |
362 bool HasPendingFetchers() { | 343 bool HasPendingFetchers() { return num_pending_fetchers() > 0; } |
363 return num_pending_fetchers() > 0; | |
364 } | |
365 | 344 |
366 int next_adapter_fetcher_index_; | 345 int next_adapter_fetcher_index_; |
367 | 346 |
368 // Ownership gets transferred to the implementation class via | 347 // Ownership gets transferred to the implementation class via |
369 // ImplCreateAdapterFetcher, but any objects not handed out are | 348 // ImplCreateAdapterFetcher, but any objects not handed out are |
370 // deleted on destruction. | 349 // deleted on destruction. |
371 std::vector<DhcpProxyScriptAdapterFetcher*> adapter_fetchers_; | 350 std::vector<DhcpProxyScriptAdapterFetcher*> adapter_fetchers_; |
372 | 351 |
373 scoped_refptr<MockAdapterQuery> adapter_query_; | 352 scoped_refptr<MockAdapterQuery> adapter_query_; |
374 | 353 |
375 base::TimeDelta max_wait_; | 354 base::TimeDelta max_wait_; |
376 int num_fetchers_created_; | 355 int num_fetchers_created_; |
377 base::WaitableEvent worker_finished_event_; | 356 base::WaitableEvent worker_finished_event_; |
378 }; | 357 }; |
379 | 358 |
380 class FetcherClient { | 359 class FetcherClient { |
381 public: | 360 public: |
382 FetcherClient() | 361 FetcherClient() |
383 : context_(new TestURLRequestContext), | 362 : context_(new TestURLRequestContext), |
384 fetcher_(context_.get()), | 363 fetcher_(context_.get()), |
385 finished_(false), | 364 finished_(false), |
386 result_(ERR_UNEXPECTED) { | 365 result_(ERR_UNEXPECTED) {} |
387 } | |
388 | 366 |
389 void RunTest() { | 367 void RunTest() { |
390 int result = fetcher_.Fetch( | 368 int result = fetcher_.Fetch( |
391 &pac_text_, | 369 &pac_text_, |
392 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this))); | 370 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this))); |
393 ASSERT_EQ(ERR_IO_PENDING, result); | 371 ASSERT_EQ(ERR_IO_PENDING, result); |
394 } | 372 } |
395 | 373 |
396 void RunMessageLoopUntilComplete() { | 374 void RunMessageLoopUntilComplete() { |
397 while (!finished_) { | 375 while (!finished_) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 ASSERT_EQ(L"bingo", client->pac_text_); | 424 ASSERT_EQ(L"bingo", client->pac_text_); |
447 } | 425 } |
448 | 426 |
449 TEST(DhcpProxyScriptFetcherWin, NormalCaseURLConfiguredOneAdapter) { | 427 TEST(DhcpProxyScriptFetcherWin, NormalCaseURLConfiguredOneAdapter) { |
450 FetcherClient client; | 428 FetcherClient client; |
451 TestNormalCaseURLConfiguredOneAdapter(&client); | 429 TestNormalCaseURLConfiguredOneAdapter(&client); |
452 } | 430 } |
453 | 431 |
454 void TestNormalCaseURLConfiguredMultipleAdapters(FetcherClient* client) { | 432 void TestNormalCaseURLConfiguredMultipleAdapters(FetcherClient* client) { |
455 client->fetcher_.ConfigureAndPushBackAdapter( | 433 client->fetcher_.ConfigureAndPushBackAdapter( |
456 "most_preferred", true, ERR_PAC_NOT_IN_DHCP, L"", | 434 "most_preferred", |
| 435 true, |
| 436 ERR_PAC_NOT_IN_DHCP, |
| 437 L"", |
457 base::TimeDelta::FromMilliseconds(1)); | 438 base::TimeDelta::FromMilliseconds(1)); |
458 client->fetcher_.ConfigureAndPushBackAdapter( | 439 client->fetcher_.ConfigureAndPushBackAdapter( |
459 "second", true, OK, L"bingo", base::TimeDelta::FromMilliseconds(50)); | 440 "second", true, OK, L"bingo", base::TimeDelta::FromMilliseconds(50)); |
460 client->fetcher_.ConfigureAndPushBackAdapter( | 441 client->fetcher_.ConfigureAndPushBackAdapter( |
461 "third", true, OK, L"rocko", base::TimeDelta::FromMilliseconds(1)); | 442 "third", true, OK, L"rocko", base::TimeDelta::FromMilliseconds(1)); |
462 client->RunTest(); | 443 client->RunTest(); |
463 client->RunMessageLoopUntilComplete(); | 444 client->RunMessageLoopUntilComplete(); |
464 ASSERT_EQ(OK, client->result_); | 445 ASSERT_EQ(OK, client->result_); |
465 ASSERT_EQ(L"bingo", client->pac_text_); | 446 ASSERT_EQ(L"bingo", client->pac_text_); |
466 } | 447 } |
467 | 448 |
468 TEST(DhcpProxyScriptFetcherWin, NormalCaseURLConfiguredMultipleAdapters) { | 449 TEST(DhcpProxyScriptFetcherWin, NormalCaseURLConfiguredMultipleAdapters) { |
469 FetcherClient client; | 450 FetcherClient client; |
470 TestNormalCaseURLConfiguredMultipleAdapters(&client); | 451 TestNormalCaseURLConfiguredMultipleAdapters(&client); |
471 } | 452 } |
472 | 453 |
473 void TestNormalCaseURLConfiguredMultipleAdaptersWithTimeout( | 454 void TestNormalCaseURLConfiguredMultipleAdaptersWithTimeout( |
474 FetcherClient* client) { | 455 FetcherClient* client) { |
475 client->fetcher_.ConfigureAndPushBackAdapter( | 456 client->fetcher_.ConfigureAndPushBackAdapter( |
476 "most_preferred", true, ERR_PAC_NOT_IN_DHCP, L"", | 457 "most_preferred", |
| 458 true, |
| 459 ERR_PAC_NOT_IN_DHCP, |
| 460 L"", |
477 base::TimeDelta::FromMilliseconds(1)); | 461 base::TimeDelta::FromMilliseconds(1)); |
478 // This will time out. | 462 // This will time out. |
479 client->fetcher_.ConfigureAndPushBackAdapter( | 463 client->fetcher_.ConfigureAndPushBackAdapter("second", |
480 "second", false, ERR_IO_PENDING, L"bingo", | 464 false, |
481 TestTimeouts::action_timeout()); | 465 ERR_IO_PENDING, |
| 466 L"bingo", |
| 467 TestTimeouts::action_timeout()); |
482 client->fetcher_.ConfigureAndPushBackAdapter( | 468 client->fetcher_.ConfigureAndPushBackAdapter( |
483 "third", true, OK, L"rocko", base::TimeDelta::FromMilliseconds(1)); | 469 "third", true, OK, L"rocko", base::TimeDelta::FromMilliseconds(1)); |
484 client->RunTest(); | 470 client->RunTest(); |
485 client->RunMessageLoopUntilComplete(); | 471 client->RunMessageLoopUntilComplete(); |
486 ASSERT_EQ(OK, client->result_); | 472 ASSERT_EQ(OK, client->result_); |
487 ASSERT_EQ(L"rocko", client->pac_text_); | 473 ASSERT_EQ(L"rocko", client->pac_text_); |
488 } | 474 } |
489 | 475 |
490 TEST(DhcpProxyScriptFetcherWin, | 476 TEST(DhcpProxyScriptFetcherWin, |
491 NormalCaseURLConfiguredMultipleAdaptersWithTimeout) { | 477 NormalCaseURLConfiguredMultipleAdaptersWithTimeout) { |
492 FetcherClient client; | 478 FetcherClient client; |
493 TestNormalCaseURLConfiguredMultipleAdaptersWithTimeout(&client); | 479 TestNormalCaseURLConfiguredMultipleAdaptersWithTimeout(&client); |
494 } | 480 } |
495 | 481 |
496 void TestFailureCaseURLConfiguredMultipleAdaptersWithTimeout( | 482 void TestFailureCaseURLConfiguredMultipleAdaptersWithTimeout( |
497 FetcherClient* client) { | 483 FetcherClient* client) { |
498 client->fetcher_.ConfigureAndPushBackAdapter( | 484 client->fetcher_.ConfigureAndPushBackAdapter( |
499 "most_preferred", true, ERR_PAC_NOT_IN_DHCP, L"", | 485 "most_preferred", |
| 486 true, |
| 487 ERR_PAC_NOT_IN_DHCP, |
| 488 L"", |
500 base::TimeDelta::FromMilliseconds(1)); | 489 base::TimeDelta::FromMilliseconds(1)); |
501 // This will time out. | 490 // This will time out. |
502 client->fetcher_.ConfigureAndPushBackAdapter( | 491 client->fetcher_.ConfigureAndPushBackAdapter("second", |
503 "second", false, ERR_IO_PENDING, L"bingo", | 492 false, |
504 TestTimeouts::action_timeout()); | 493 ERR_IO_PENDING, |
| 494 L"bingo", |
| 495 TestTimeouts::action_timeout()); |
505 // This is the first non-ERR_PAC_NOT_IN_DHCP error and as such | 496 // This is the first non-ERR_PAC_NOT_IN_DHCP error and as such |
506 // should be chosen. | 497 // should be chosen. |
507 client->fetcher_.ConfigureAndPushBackAdapter( | 498 client->fetcher_.ConfigureAndPushBackAdapter( |
508 "third", true, ERR_PAC_STATUS_NOT_OK, L"", | 499 "third", |
| 500 true, |
| 501 ERR_PAC_STATUS_NOT_OK, |
| 502 L"", |
509 base::TimeDelta::FromMilliseconds(1)); | 503 base::TimeDelta::FromMilliseconds(1)); |
510 client->fetcher_.ConfigureAndPushBackAdapter( | 504 client->fetcher_.ConfigureAndPushBackAdapter( |
511 "fourth", true, ERR_NOT_IMPLEMENTED, L"", | 505 "fourth", |
| 506 true, |
| 507 ERR_NOT_IMPLEMENTED, |
| 508 L"", |
512 base::TimeDelta::FromMilliseconds(1)); | 509 base::TimeDelta::FromMilliseconds(1)); |
513 client->RunTest(); | 510 client->RunTest(); |
514 client->RunMessageLoopUntilComplete(); | 511 client->RunMessageLoopUntilComplete(); |
515 ASSERT_EQ(ERR_PAC_STATUS_NOT_OK, client->result_); | 512 ASSERT_EQ(ERR_PAC_STATUS_NOT_OK, client->result_); |
516 ASSERT_EQ(L"", client->pac_text_); | 513 ASSERT_EQ(L"", client->pac_text_); |
517 } | 514 } |
518 | 515 |
519 TEST(DhcpProxyScriptFetcherWin, | 516 TEST(DhcpProxyScriptFetcherWin, |
520 FailureCaseURLConfiguredMultipleAdaptersWithTimeout) { | 517 FailureCaseURLConfiguredMultipleAdaptersWithTimeout) { |
521 FetcherClient client; | 518 FetcherClient client; |
522 TestFailureCaseURLConfiguredMultipleAdaptersWithTimeout(&client); | 519 TestFailureCaseURLConfiguredMultipleAdaptersWithTimeout(&client); |
523 } | 520 } |
524 | 521 |
525 void TestFailureCaseNoURLConfigured(FetcherClient* client) { | 522 void TestFailureCaseNoURLConfigured(FetcherClient* client) { |
526 client->fetcher_.ConfigureAndPushBackAdapter( | 523 client->fetcher_.ConfigureAndPushBackAdapter( |
527 "most_preferred", true, ERR_PAC_NOT_IN_DHCP, L"", | 524 "most_preferred", |
| 525 true, |
| 526 ERR_PAC_NOT_IN_DHCP, |
| 527 L"", |
528 base::TimeDelta::FromMilliseconds(1)); | 528 base::TimeDelta::FromMilliseconds(1)); |
529 // This will time out. | 529 // This will time out. |
530 client->fetcher_.ConfigureAndPushBackAdapter( | 530 client->fetcher_.ConfigureAndPushBackAdapter("second", |
531 "second", false, ERR_IO_PENDING, L"bingo", | 531 false, |
532 TestTimeouts::action_timeout()); | 532 ERR_IO_PENDING, |
| 533 L"bingo", |
| 534 TestTimeouts::action_timeout()); |
533 // This is the first non-ERR_PAC_NOT_IN_DHCP error and as such | 535 // This is the first non-ERR_PAC_NOT_IN_DHCP error and as such |
534 // should be chosen. | 536 // should be chosen. |
535 client->fetcher_.ConfigureAndPushBackAdapter( | 537 client->fetcher_.ConfigureAndPushBackAdapter( |
536 "third", true, ERR_PAC_NOT_IN_DHCP, L"", | 538 "third", |
| 539 true, |
| 540 ERR_PAC_NOT_IN_DHCP, |
| 541 L"", |
537 base::TimeDelta::FromMilliseconds(1)); | 542 base::TimeDelta::FromMilliseconds(1)); |
538 client->RunTest(); | 543 client->RunTest(); |
539 client->RunMessageLoopUntilComplete(); | 544 client->RunMessageLoopUntilComplete(); |
540 ASSERT_EQ(ERR_PAC_NOT_IN_DHCP, client->result_); | 545 ASSERT_EQ(ERR_PAC_NOT_IN_DHCP, client->result_); |
541 ASSERT_EQ(L"", client->pac_text_); | 546 ASSERT_EQ(L"", client->pac_text_); |
542 } | 547 } |
543 | 548 |
544 TEST(DhcpProxyScriptFetcherWin, FailureCaseNoURLConfigured) { | 549 TEST(DhcpProxyScriptFetcherWin, FailureCaseNoURLConfigured) { |
545 FetcherClient client; | 550 FetcherClient client; |
546 TestFailureCaseNoURLConfigured(&client); | 551 TestFailureCaseNoURLConfigured(&client); |
(...skipping 11 matching lines...) Expand all Loading... |
558 FetcherClient client; | 563 FetcherClient client; |
559 TestFailureCaseNoDhcpAdapters(&client); | 564 TestFailureCaseNoDhcpAdapters(&client); |
560 } | 565 } |
561 | 566 |
562 void TestShortCircuitLessPreferredAdapters(FetcherClient* client) { | 567 void TestShortCircuitLessPreferredAdapters(FetcherClient* client) { |
563 // Here we have a bunch of adapters; the first reports no PAC in DHCP, | 568 // Here we have a bunch of adapters; the first reports no PAC in DHCP, |
564 // the second responds quickly with a PAC file, the rest take a long | 569 // the second responds quickly with a PAC file, the rest take a long |
565 // time. Verify that we complete quickly and do not wait for the slow | 570 // time. Verify that we complete quickly and do not wait for the slow |
566 // adapters, i.e. we finish before timeout. | 571 // adapters, i.e. we finish before timeout. |
567 client->fetcher_.ConfigureAndPushBackAdapter( | 572 client->fetcher_.ConfigureAndPushBackAdapter( |
568 "1", true, ERR_PAC_NOT_IN_DHCP, L"", | 573 "1", |
| 574 true, |
| 575 ERR_PAC_NOT_IN_DHCP, |
| 576 L"", |
569 base::TimeDelta::FromMilliseconds(1)); | 577 base::TimeDelta::FromMilliseconds(1)); |
570 client->fetcher_.ConfigureAndPushBackAdapter( | 578 client->fetcher_.ConfigureAndPushBackAdapter( |
571 "2", true, OK, L"bingo", | 579 "2", true, OK, L"bingo", base::TimeDelta::FromMilliseconds(1)); |
572 base::TimeDelta::FromMilliseconds(1)); | |
573 client->fetcher_.ConfigureAndPushBackAdapter( | 580 client->fetcher_.ConfigureAndPushBackAdapter( |
574 "3", true, OK, L"wrongo", TestTimeouts::action_max_timeout()); | 581 "3", true, OK, L"wrongo", TestTimeouts::action_max_timeout()); |
575 | 582 |
576 // Increase the timeout to ensure the short circuit mechanism has | 583 // Increase the timeout to ensure the short circuit mechanism has |
577 // time to kick in before the timeout waiting for more adapters kicks in. | 584 // time to kick in before the timeout waiting for more adapters kicks in. |
578 client->fetcher_.max_wait_ = TestTimeouts::action_timeout(); | 585 client->fetcher_.max_wait_ = TestTimeouts::action_timeout(); |
579 | 586 |
580 base::ElapsedTimer timer; | 587 base::ElapsedTimer timer; |
581 client->RunTest(); | 588 client->RunTest(); |
582 client->RunMessageLoopUntilComplete(); | 589 client->RunMessageLoopUntilComplete(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 test_functions.push_back(TestNormalCaseURLConfiguredMultipleAdapters); | 636 test_functions.push_back(TestNormalCaseURLConfiguredMultipleAdapters); |
630 test_functions.push_back( | 637 test_functions.push_back( |
631 TestNormalCaseURLConfiguredMultipleAdaptersWithTimeout); | 638 TestNormalCaseURLConfiguredMultipleAdaptersWithTimeout); |
632 test_functions.push_back( | 639 test_functions.push_back( |
633 TestFailureCaseURLConfiguredMultipleAdaptersWithTimeout); | 640 TestFailureCaseURLConfiguredMultipleAdaptersWithTimeout); |
634 test_functions.push_back(TestFailureCaseNoURLConfigured); | 641 test_functions.push_back(TestFailureCaseNoURLConfigured); |
635 test_functions.push_back(TestFailureCaseNoDhcpAdapters); | 642 test_functions.push_back(TestFailureCaseNoDhcpAdapters); |
636 test_functions.push_back(TestShortCircuitLessPreferredAdapters); | 643 test_functions.push_back(TestShortCircuitLessPreferredAdapters); |
637 test_functions.push_back(TestImmediateCancel); | 644 test_functions.push_back(TestImmediateCancel); |
638 | 645 |
639 std::random_shuffle(test_functions.begin(), | 646 std::random_shuffle( |
640 test_functions.end(), | 647 test_functions.begin(), test_functions.end(), base::RandGenerator); |
641 base::RandGenerator); | |
642 for (TestVector::const_iterator it = test_functions.begin(); | 648 for (TestVector::const_iterator it = test_functions.begin(); |
643 it != test_functions.end(); | 649 it != test_functions.end(); |
644 ++it) { | 650 ++it) { |
645 (*it)(&client); | 651 (*it)(&client); |
646 client.ResetTestState(); | 652 client.ResetTestState(); |
647 } | 653 } |
648 | 654 |
649 // Re-do the first test to make sure the last test that was run did | 655 // Re-do the first test to make sure the last test that was run did |
650 // not leave things in a bad state. | 656 // not leave things in a bad state. |
651 (*test_functions.begin())(&client); | 657 (*test_functions.begin())(&client); |
652 } | 658 } |
653 | 659 |
654 } // namespace | 660 } // namespace |
655 | 661 |
656 } // namespace net | 662 } // namespace net |
OLD | NEW |