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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 result_(ERR_UNEXPECTED) { | 385 result_(ERR_UNEXPECTED) { |
386 } | 386 } |
387 | 387 |
388 void RunTest() { | 388 void RunTest() { |
389 int result = fetcher_.Fetch( | 389 int result = fetcher_.Fetch( |
390 &pac_text_, | 390 &pac_text_, |
391 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this))); | 391 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this))); |
392 ASSERT_THAT(result, IsError(ERR_IO_PENDING)); | 392 ASSERT_THAT(result, IsError(ERR_IO_PENDING)); |
393 } | 393 } |
394 | 394 |
| 395 int RunTestThatMayFailSync() { |
| 396 int result = fetcher_.Fetch( |
| 397 &pac_text_, |
| 398 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this))); |
| 399 if (result != ERR_IO_PENDING) |
| 400 result_ = result; |
| 401 return result; |
| 402 } |
| 403 |
395 void RunMessageLoopUntilComplete() { | 404 void RunMessageLoopUntilComplete() { |
396 while (!finished_) { | 405 while (!finished_) { |
397 base::RunLoop().RunUntilIdle(); | 406 base::RunLoop().RunUntilIdle(); |
398 } | 407 } |
399 base::RunLoop().RunUntilIdle(); | 408 base::RunLoop().RunUntilIdle(); |
400 } | 409 } |
401 | 410 |
402 void RunMessageLoopUntilWorkerDone() { | 411 void RunMessageLoopUntilWorkerDone() { |
403 DCHECK(fetcher_.adapter_query_.get()); | 412 DCHECK(fetcher_.adapter_query_.get()); |
404 while (!fetcher_.worker_finished_event_.TimedWait( | 413 while (!fetcher_.worker_finished_event_.TimedWait( |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 ++it) { | 652 ++it) { |
644 (*it)(&client); | 653 (*it)(&client); |
645 client.ResetTestState(); | 654 client.ResetTestState(); |
646 } | 655 } |
647 | 656 |
648 // Re-do the first test to make sure the last test that was run did | 657 // Re-do the first test to make sure the last test that was run did |
649 // not leave things in a bad state. | 658 // not leave things in a bad state. |
650 (*test_functions.begin())(&client); | 659 (*test_functions.begin())(&client); |
651 } | 660 } |
652 | 661 |
| 662 TEST(DhcpProxyScriptFetcherWin, OnShutdown) { |
| 663 FetcherClient client; |
| 664 TestURLRequestContext context; |
| 665 std::unique_ptr<DummyDhcpProxyScriptAdapterFetcher> adapter_fetcher( |
| 666 new DummyDhcpProxyScriptAdapterFetcher(&context, client.GetTaskRunner())); |
| 667 adapter_fetcher->Configure(true, OK, L"bingo", 1); |
| 668 client.fetcher_.PushBackAdapter("a", adapter_fetcher.release()); |
| 669 client.RunTest(); |
| 670 |
| 671 client.fetcher_.OnShutdown(); |
| 672 EXPECT_TRUE(client.finished_); |
| 673 EXPECT_THAT(client.result_, IsError(ERR_CONTEXT_SHUT_DOWN)); |
| 674 |
| 675 client.ResetTestState(); |
| 676 EXPECT_THAT(client.RunTestThatMayFailSync(), IsError(ERR_CONTEXT_SHUT_DOWN)); |
| 677 EXPECT_EQ(0u, context.url_requests().size()); |
| 678 } |
| 679 |
653 } // namespace | 680 } // namespace |
654 | 681 |
655 } // namespace net | 682 } // namespace net |
OLD | NEW |