| 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 18 matching lines...) Expand all Loading... |
| 29 // We don't make assumptions about the environment this unit test is | 29 // We don't make assumptions about the environment this unit test is |
| 30 // running in, so it just exercises the code to make sure there | 30 // running in, so it just exercises the code to make sure there |
| 31 // is no crash and no error returned, but does not assert on the number | 31 // is no crash and no error returned, but does not assert on the number |
| 32 // of interfaces or the information returned via DHCP. | 32 // of interfaces or the information returned via DHCP. |
| 33 std::set<std::string> adapter_names; | 33 std::set<std::string> adapter_names; |
| 34 DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(&adapter_names); | 34 DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(&adapter_names); |
| 35 for (std::set<std::string>::const_iterator it = adapter_names.begin(); | 35 for (std::set<std::string>::const_iterator it = adapter_names.begin(); |
| 36 it != adapter_names.end(); | 36 it != adapter_names.end(); |
| 37 ++it) { | 37 ++it) { |
| 38 const std::string& adapter_name = *it; | 38 const std::string& adapter_name = *it; |
| 39 std::string pac_url = | 39 DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(adapter_name); |
| 40 DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(adapter_name); | |
| 41 printf("Adapter '%s' has PAC URL '%s' configured in DHCP.\n", | |
| 42 adapter_name.c_str(), | |
| 43 pac_url.c_str()); | |
| 44 } | 40 } |
| 45 } | 41 } |
| 46 | 42 |
| 47 // Helper for RealFetch* tests below. | 43 // Helper for RealFetch* tests below. |
| 48 class RealFetchTester { | 44 class RealFetchTester { |
| 49 public: | 45 public: |
| 50 RealFetchTester() | 46 RealFetchTester() |
| 51 : context_(new TestURLRequestContext), | 47 : context_(new TestURLRequestContext), |
| 52 fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), | 48 fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), |
| 53 finished_(false), | 49 finished_(false), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 cancel_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0), | 73 cancel_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0), |
| 78 this, &RealFetchTester::OnCancelTimer); | 74 this, &RealFetchTester::OnCancelTimer); |
| 79 RunTest(); | 75 RunTest(); |
| 80 } | 76 } |
| 81 | 77 |
| 82 void OnCompletion(int result) { | 78 void OnCompletion(int result) { |
| 83 if (on_completion_is_error_) { | 79 if (on_completion_is_error_) { |
| 84 FAIL() << "Received completion for test in which this is error."; | 80 FAIL() << "Received completion for test in which this is error."; |
| 85 } | 81 } |
| 86 finished_ = true; | 82 finished_ = true; |
| 87 printf("Result code %d PAC data length %d\n", result, pac_text_.size()); | |
| 88 } | 83 } |
| 89 | 84 |
| 90 void OnTimeout() { | 85 void OnTimeout() { |
| 91 printf("Timeout!"); | |
| 92 OnCompletion(0); | 86 OnCompletion(0); |
| 93 } | 87 } |
| 94 | 88 |
| 95 void OnCancelTimer() { | 89 void OnCancelTimer() { |
| 96 fetcher_->Cancel(); | 90 fetcher_->Cancel(); |
| 97 finished_ = true; | 91 finished_ = true; |
| 98 } | 92 } |
| 99 | 93 |
| 100 void WaitUntilDone() { | 94 void WaitUntilDone() { |
| 101 while (!finished_) { | 95 while (!finished_) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 127 // This tests a call to Fetch() with no stubbing out of dependencies. | 121 // This tests a call to Fetch() with no stubbing out of dependencies. |
| 128 // | 122 // |
| 129 // We don't make assumptions about the environment this unit test is | 123 // 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 | 124 // 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 | 125 // is no crash and no unexpected error returned, but does not assert on |
| 132 // results beyond that. | 126 // results beyond that. |
| 133 RealFetchTester fetcher; | 127 RealFetchTester fetcher; |
| 134 fetcher.RunTest(); | 128 fetcher.RunTest(); |
| 135 | 129 |
| 136 fetcher.WaitUntilDone(); | 130 fetcher.WaitUntilDone(); |
| 137 printf("PAC URL was %s\n", | 131 fetcher.fetcher_->GetPacURL().possibly_invalid_spec(); |
| 138 fetcher.fetcher_->GetPacURL().possibly_invalid_spec().c_str()); | |
| 139 | 132 |
| 140 fetcher.FinishTestAllowCleanup(); | 133 fetcher.FinishTestAllowCleanup(); |
| 141 } | 134 } |
| 142 | 135 |
| 143 TEST(DhcpProxyScriptFetcherWin, RealFetchWithCancel) { | 136 TEST(DhcpProxyScriptFetcherWin, RealFetchWithCancel) { |
| 144 // Does a Fetch() with an immediate cancel. As before, just | 137 // Does a Fetch() with an immediate cancel. As before, just |
| 145 // exercises the code without stubbing out dependencies. | 138 // exercises the code without stubbing out dependencies. |
| 146 RealFetchTester fetcher; | 139 RealFetchTester fetcher; |
| 147 fetcher.RunTestWithCancel(); | 140 fetcher.RunTestWithCancel(); |
| 148 base::MessageLoop::current()->RunUntilIdle(); | 141 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } | 640 } |
| 648 | 641 |
| 649 // Re-do the first test to make sure the last test that was run did | 642 // Re-do the first test to make sure the last test that was run did |
| 650 // not leave things in a bad state. | 643 // not leave things in a bad state. |
| 651 (*test_functions.begin())(&client); | 644 (*test_functions.begin())(&client); |
| 652 } | 645 } |
| 653 | 646 |
| 654 } // namespace | 647 } // namespace |
| 655 | 648 |
| 656 } // namespace net | 649 } // namespace net |
| OLD | NEW |