| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class RealFetchTester { | 46 class RealFetchTester { |
| 47 public: | 47 public: |
| 48 RealFetchTester() | 48 RealFetchTester() |
| 49 : context_((new TestURLRequestContext())), | 49 : context_((new TestURLRequestContext())), |
| 50 fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), | 50 fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), |
| 51 finished_(false), | 51 finished_(false), |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST( | 52 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 53 completion_callback_(this, &RealFetchTester::OnCompletion)), | 53 completion_callback_(this, &RealFetchTester::OnCompletion)), |
| 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( |
| 57 base::TimeDelta::FromSeconds(5), this, &RealFetchTester::OnTimeout); | 57 base::TimeDelta::FromSeconds(5), this, &RealFetchTester::OnTimeout); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void RunTest() { | 60 void RunTest() { |
| 61 int result = fetcher_->Fetch(&pac_text_, &completion_callback_); | 61 int result = fetcher_->Fetch(&pac_text_, &completion_callback_); |
| 62 if (result != ERR_IO_PENDING) | 62 if (result != ERR_IO_PENDING) |
| 63 finished_ = true; | 63 finished_ = true; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void RunTestWithCancel() { | 66 void RunTestWithCancel() { |
| 67 RunTest(); | 67 RunTest(); |
| 68 fetcher_->Cancel(); | 68 fetcher_->Cancel(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RunTestWithDeferredCancel() { | 71 void RunTestWithDeferredCancel() { |
| 72 // Put the cancellation into the queue before even running the | 72 // Put the cancellation into the queue before even running the |
| 73 // test to avoid the chance of one of the adapter fetcher worker | 73 // test to avoid the chance of one of the adapter fetcher worker |
| 74 // threads completing before cancellation. See http://crbug.com/86756. | 74 // threads completing before cancellation. See http://crbug.com/86756. |
| 75 cancel_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0), | 75 cancel_timer_.Start(base::TimeDelta::FromMilliseconds(0), |
| 76 this, &RealFetchTester::OnCancelTimer); | 76 this, &RealFetchTester::OnCancelTimer); |
| 77 RunTest(); | 77 RunTest(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void OnCompletion(int result) { | 80 void OnCompletion(int result) { |
| 81 if (on_completion_is_error_) { | 81 if (on_completion_is_error_) { |
| 82 FAIL() << "Received completion for test in which this is error."; | 82 FAIL() << "Received completion for test in which this is error."; |
| 83 } | 83 } |
| 84 finished_ = true; | 84 finished_ = true; |
| 85 printf("Result code %d PAC data length %d\n", result, pac_text_.size()); | 85 printf("Result code %d PAC data length %d\n", result, pac_text_.size()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 did_finish_(false), | 218 did_finish_(false), |
| 219 result_(OK), | 219 result_(OK), |
| 220 pac_script_(L"bingo"), | 220 pac_script_(L"bingo"), |
| 221 fetch_delay_ms_(1), | 221 fetch_delay_ms_(1), |
| 222 client_callback_(NULL) { | 222 client_callback_(NULL) { |
| 223 } | 223 } |
| 224 | 224 |
| 225 void Fetch(const std::string& adapter_name, | 225 void Fetch(const std::string& adapter_name, |
| 226 CompletionCallback* callback) OVERRIDE { | 226 CompletionCallback* callback) OVERRIDE { |
| 227 client_callback_ = callback; | 227 client_callback_ = callback; |
| 228 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(fetch_delay_ms_), | 228 timer_.Start(base::TimeDelta::FromMilliseconds(fetch_delay_ms_), |
| 229 this, &DummyDhcpProxyScriptAdapterFetcher::OnTimer); | 229 this, &DummyDhcpProxyScriptAdapterFetcher::OnTimer); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void Cancel() OVERRIDE { | 232 void Cancel() OVERRIDE { |
| 233 timer_.Stop(); | 233 timer_.Stop(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool DidFinish() const OVERRIDE { | 236 bool DidFinish() const OVERRIDE { |
| 237 return did_finish_; | 237 return did_finish_; |
| 238 } | 238 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 } | 628 } |
| 629 | 629 |
| 630 // Re-do the first test to make sure the last test that was run did | 630 // Re-do the first test to make sure the last test that was run did |
| 631 // not leave things in a bad state. | 631 // not leave things in a bad state. |
| 632 (*test_functions.begin())(&client); | 632 (*test_functions.begin())(&client); |
| 633 } | 633 } |
| 634 | 634 |
| 635 } // namespace | 635 } // namespace |
| 636 | 636 |
| 637 } // namespace net | 637 } // namespace net |
| OLD | NEW |