Index: net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc |
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc |
index e22915b0a6591baa6907b15b060e7637a23eb94c..a722103bf5bcabae4aec051d94158b5deb04f136 100644 |
--- a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc |
+++ b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc |
@@ -263,6 +263,25 @@ class DummyDhcpProxyScriptAdapterFetcher |
class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
public: |
+ class MockWorkerThread : public WorkerThread { |
+ public: |
+ virtual ~MockWorkerThread() { |
+ } |
+ |
+ void Init(const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) { |
+ WorkerThread::Init(owner); |
+ } |
+ |
+ virtual bool ImplGetCandidateAdapterNames( |
+ std::set<std::string>* adapter_names) OVERRIDE { |
+ adapter_names->insert( |
+ mock_adapter_names_.begin(), mock_adapter_names_.end()); |
+ return true; |
+ } |
+ |
+ std::vector<std::string> mock_adapter_names_; |
+ }; |
+ |
MockDhcpProxyScriptFetcherWin() |
: DhcpProxyScriptFetcherWin(new TestURLRequestContext()) { |
ResetTestState(); |
@@ -273,7 +292,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
// returned by ImplGetCandidateAdapterNames. |
void PushBackAdapter(const std::string& adapter_name, |
DhcpProxyScriptAdapterFetcher* fetcher) { |
- adapter_names_.push_back(adapter_name); |
+ worker_thread_->mock_adapter_names_.push_back(adapter_name); |
adapter_fetchers_.push_back(fetcher); |
} |
@@ -292,10 +311,11 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
return adapter_fetchers_[next_adapter_fetcher_index_++]; |
} |
- bool ImplGetCandidateAdapterNames( |
- std::set<std::string>* adapter_names) OVERRIDE { |
- adapter_names->insert(adapter_names_.begin(), adapter_names_.end()); |
- return true; |
+ virtual WorkerThread* ImplCreateWorkerThread( |
+ const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) OVERRIDE { |
+ DCHECK(worker_thread_); |
+ worker_thread_->Init(owner); |
+ return worker_thread_.get(); |
} |
int ImplGetMaxWaitMs() OVERRIDE { |
@@ -305,8 +325,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
void ResetTestState() { |
next_adapter_fetcher_index_ = 0; |
adapter_fetchers_.clear(); |
- // String pointers contained herein will have been freed during test. |
- adapter_names_.clear(); |
+ worker_thread_ = new MockWorkerThread(); |
max_wait_ms_ = TestTimeouts::tiny_timeout_ms(); |
} |
@@ -320,7 +339,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { |
// class via ImplCreateAdapterFetcher. |
std::vector<DhcpProxyScriptAdapterFetcher*> adapter_fetchers_; |
- std::vector<std::string> adapter_names_; |
+ scoped_refptr<MockWorkerThread> worker_thread_; |
int max_wait_ms_; |
}; |
@@ -339,11 +358,6 @@ public: |
ASSERT_EQ(ERR_IO_PENDING, result); |
} |
- void RunImmediateReturnTest() { |
- int result = fetcher_.Fetch(&pac_text_, &completion_callback_); |
- ASSERT_EQ(ERR_PAC_NOT_IN_DHCP, result); |
- } |
- |
void RunMessageLoopUntilComplete() { |
while (!finished_) { |
MessageLoop::current()->RunAllPending(); |
@@ -477,10 +491,10 @@ TEST(DhcpProxyScriptFetcherWin, FailureCaseNoURLConfigured) { |
} |
void TestFailureCaseNoDhcpAdapters(FetcherClient* client) { |
- client->RunImmediateReturnTest(); |
- // In case there are any pending messages that get us in a bad state |
- // (there shouldn't be). |
- MessageLoop::current()->RunAllPending(); |
+ client->RunTest(); |
+ client->RunMessageLoopUntilComplete(); |
+ ASSERT_EQ(ERR_PAC_NOT_IN_DHCP, client->result_); |
+ ASSERT_EQ(L"", client->pac_text_); |
} |
TEST(DhcpProxyScriptFetcherWin, FailureCaseNoDhcpAdapters) { |