Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc

Issue 2053133002: Remove MessageLoop::current()->RunUntilIdle() in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/message_loop/message_loop.h"
12 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/run_loop.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 #include "base/timer/elapsed_timer.h" 15 #include "base/timer/elapsed_timer.h"
16 #include "net/base/completion_callback.h" 16 #include "net/base/completion_callback.h"
17 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" 17 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"
18 #include "net/url_request/url_request_test_util.h" 18 #include "net/url_request/url_request_test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace net { 21 namespace net {
22 22
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 OnCompletion(0); 86 OnCompletion(0);
87 } 87 }
88 88
89 void OnCancelTimer() { 89 void OnCancelTimer() {
90 fetcher_->Cancel(); 90 fetcher_->Cancel();
91 finished_ = true; 91 finished_ = true;
92 } 92 }
93 93
94 void WaitUntilDone() { 94 void WaitUntilDone() {
95 while (!finished_) { 95 while (!finished_) {
96 base::MessageLoop::current()->RunUntilIdle(); 96 base::RunLoop().RunUntilIdle();
97 } 97 }
98 base::MessageLoop::current()->RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
99 } 99 }
100 100
101 // Attempts to give worker threads time to finish. This is currently 101 // Attempts to give worker threads time to finish. This is currently
102 // very simplistic as completion (via completion callback or cancellation) 102 // very simplistic as completion (via completion callback or cancellation)
103 // immediately "detaches" any worker threads, so the best we can do is give 103 // immediately "detaches" any worker threads, so the best we can do is give
104 // them a little time. If we start running into Valgrind leaks, we can 104 // them a little time. If we start running into Valgrind leaks, we can
105 // do something a bit more clever to track worker threads even when the 105 // do something a bit more clever to track worker threads even when the
106 // DhcpProxyScriptFetcherWin state machine has finished. 106 // DhcpProxyScriptFetcherWin state machine has finished.
107 void FinishTestAllowCleanup() { 107 void FinishTestAllowCleanup() {
108 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); 108 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30));
(...skipping 22 matching lines...) Expand all
131 fetcher.fetcher_->GetPacURL().possibly_invalid_spec(); 131 fetcher.fetcher_->GetPacURL().possibly_invalid_spec();
132 132
133 fetcher.FinishTestAllowCleanup(); 133 fetcher.FinishTestAllowCleanup();
134 } 134 }
135 135
136 TEST(DhcpProxyScriptFetcherWin, RealFetchWithCancel) { 136 TEST(DhcpProxyScriptFetcherWin, RealFetchWithCancel) {
137 // Does a Fetch() with an immediate cancel. As before, just 137 // Does a Fetch() with an immediate cancel. As before, just
138 // exercises the code without stubbing out dependencies. 138 // exercises the code without stubbing out dependencies.
139 RealFetchTester fetcher; 139 RealFetchTester fetcher;
140 fetcher.RunTestWithCancel(); 140 fetcher.RunTestWithCancel();
141 base::MessageLoop::current()->RunUntilIdle(); 141 base::RunLoop().RunUntilIdle();
142 142
143 // Attempt to avoid Valgrind leak reports in case worker thread is 143 // Attempt to avoid Valgrind leak reports in case worker thread is
144 // still running. 144 // still running.
145 fetcher.FinishTestAllowCleanup(); 145 fetcher.FinishTestAllowCleanup();
146 } 146 }
147 147
148 // For RealFetchWithDeferredCancel, below. 148 // For RealFetchWithDeferredCancel, below.
149 class DelayingDhcpProxyScriptAdapterFetcher 149 class DelayingDhcpProxyScriptAdapterFetcher
150 : public DhcpProxyScriptAdapterFetcher { 150 : public DhcpProxyScriptAdapterFetcher {
151 public: 151 public:
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 382
383 void RunTest() { 383 void RunTest() {
384 int result = fetcher_.Fetch( 384 int result = fetcher_.Fetch(
385 &pac_text_, 385 &pac_text_,
386 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this))); 386 base::Bind(&FetcherClient::OnCompletion, base::Unretained(this)));
387 ASSERT_EQ(ERR_IO_PENDING, result); 387 ASSERT_EQ(ERR_IO_PENDING, result);
388 } 388 }
389 389
390 void RunMessageLoopUntilComplete() { 390 void RunMessageLoopUntilComplete() {
391 while (!finished_) { 391 while (!finished_) {
392 base::MessageLoop::current()->RunUntilIdle(); 392 base::RunLoop().RunUntilIdle();
393 } 393 }
394 base::MessageLoop::current()->RunUntilIdle(); 394 base::RunLoop().RunUntilIdle();
395 } 395 }
396 396
397 void RunMessageLoopUntilWorkerDone() { 397 void RunMessageLoopUntilWorkerDone() {
398 DCHECK(fetcher_.adapter_query_.get()); 398 DCHECK(fetcher_.adapter_query_.get());
399 while (!fetcher_.worker_finished_event_.TimedWait( 399 while (!fetcher_.worker_finished_event_.TimedWait(
400 base::TimeDelta::FromMilliseconds(10))) { 400 base::TimeDelta::FromMilliseconds(10))) {
401 base::MessageLoop::current()->RunUntilIdle(); 401 base::RunLoop().RunUntilIdle();
402 } 402 }
403 } 403 }
404 404
405 void OnCompletion(int result) { 405 void OnCompletion(int result) {
406 finished_ = true; 406 finished_ = true;
407 result_ = result; 407 result_ = result;
408 } 408 }
409 409
410 void ResetTestState() { 410 void ResetTestState() {
411 finished_ = false; 411 finished_ = false;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 641 }
642 642
643 // Re-do the first test to make sure the last test that was run did 643 // Re-do the first test to make sure the last test that was run did
644 // not leave things in a bad state. 644 // not leave things in a bad state.
645 (*test_functions.begin())(&client); 645 (*test_functions.begin())(&client);
646 } 646 }
647 647
648 } // namespace 648 } // namespace
649 649
650 } // namespace net 650 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc ('k') | net/proxy/multi_threaded_proxy_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698