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

Side by Side Diff: net/proxy/proxy_service_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/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <cstdarg> 7 #include <cstdarg>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/run_loop.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/base/proxy_delegate.h" 20 #include "net/base/proxy_delegate.h"
20 #include "net/base/test_completion_callback.h" 21 #include "net/base/test_completion_callback.h"
21 #include "net/log/net_log.h" 22 #include "net/log/net_log.h"
22 #include "net/log/test_net_log.h" 23 #include "net/log/test_net_log.h"
23 #include "net/log/test_net_log_entry.h" 24 #include "net/log/test_net_log_entry.h"
24 #include "net/log/test_net_log_util.h" 25 #include "net/log/test_net_log_util.h"
(...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2772 resolver.pending_requests()[0]->CompleteNow(OK); 2773 resolver.pending_requests()[0]->CompleteNow(OK);
2773 2774
2774 // Wait for completion callback, and verify that the request ran as expected. 2775 // Wait for completion callback, and verify that the request ran as expected.
2775 EXPECT_EQ(OK, callback1.WaitForResult()); 2776 EXPECT_EQ(OK, callback1.WaitForResult());
2776 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2777 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
2777 2778
2778 // Now simluate a change in the network. The ProxyConfigService is still 2779 // Now simluate a change in the network. The ProxyConfigService is still
2779 // going to return the same PAC URL as before, but this URL needs to be 2780 // going to return the same PAC URL as before, but this URL needs to be
2780 // refetched on the new network. 2781 // refetched on the new network.
2781 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 2782 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
2782 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. 2783 base::RunLoop().RunUntilIdle(); // Notification happens async.
2783 2784
2784 // Start a second request. 2785 // Start a second request.
2785 ProxyInfo info2; 2786 ProxyInfo info2;
2786 TestCompletionCallback callback2; 2787 TestCompletionCallback callback2;
2787 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, 2788 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL,
2788 &info2, callback2.callback(), nullptr, nullptr, 2789 &info2, callback2.callback(), nullptr, nullptr,
2789 BoundNetLog()); 2790 BoundNetLog());
2790 EXPECT_EQ(ERR_IO_PENDING, rv); 2791 EXPECT_EQ(ERR_IO_PENDING, rv);
2791 2792
2792 // This second request should have triggered the re-download of the PAC 2793 // This second request should have triggered the re-download of the PAC
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 2898
2898 ASSERT_TRUE(factory->pending_requests().empty()); 2899 ASSERT_TRUE(factory->pending_requests().empty());
2899 2900
2900 // Make sure that our background checker is trying to download the expected 2901 // Make sure that our background checker is trying to download the expected
2901 // PAC script (same one as before). This time we will simulate a successful 2902 // PAC script (same one as before). This time we will simulate a successful
2902 // download of the script. 2903 // download of the script.
2903 EXPECT_TRUE(fetcher->has_pending_request()); 2904 EXPECT_TRUE(fetcher->has_pending_request());
2904 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2905 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2905 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2906 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2906 2907
2907 base::MessageLoop::current()->RunUntilIdle(); 2908 base::RunLoop().RunUntilIdle();
2908 2909
2909 // Now that the PAC script is downloaded, it should be used to initialize the 2910 // Now that the PAC script is downloaded, it should be used to initialize the
2910 // ProxyResolver. Simulate a successful parse. 2911 // ProxyResolver. Simulate a successful parse.
2911 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2912 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2912 factory->pending_requests()[0]->script_data()->utf16()); 2913 factory->pending_requests()[0]->script_data()->utf16());
2913 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); 2914 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2914 2915
2915 // At this point the ProxyService should have re-configured itself to use the 2916 // At this point the ProxyService should have re-configured itself to use the
2916 // PAC script (thereby recovering from the initial fetch failure). We will 2917 // PAC script (thereby recovering from the initial fetch failure). We will
2917 // verify that the next Resolve request uses the resolver rather than 2918 // verify that the next Resolve request uses the resolver rather than
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 ASSERT_TRUE(factory->pending_requests().empty()); 3013 ASSERT_TRUE(factory->pending_requests().empty());
3013 ASSERT_TRUE(resolver.pending_requests().empty()); 3014 ASSERT_TRUE(resolver.pending_requests().empty());
3014 3015
3015 // Make sure that our background checker is trying to download the expected 3016 // Make sure that our background checker is trying to download the expected
3016 // PAC script (same one as before). This time we will simulate a successful 3017 // PAC script (same one as before). This time we will simulate a successful
3017 // download of a DIFFERENT script. 3018 // download of a DIFFERENT script.
3018 EXPECT_TRUE(fetcher->has_pending_request()); 3019 EXPECT_TRUE(fetcher->has_pending_request());
3019 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 3020 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
3020 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); 3021 fetcher->NotifyFetchCompletion(OK, kValidPacScript2);
3021 3022
3022 base::MessageLoop::current()->RunUntilIdle(); 3023 base::RunLoop().RunUntilIdle();
3023 3024
3024 // Now that the PAC script is downloaded, it should be used to initialize the 3025 // Now that the PAC script is downloaded, it should be used to initialize the
3025 // ProxyResolver. Simulate a successful parse. 3026 // ProxyResolver. Simulate a successful parse.
3026 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), 3027 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2),
3027 factory->pending_requests()[0]->script_data()->utf16()); 3028 factory->pending_requests()[0]->script_data()->utf16());
3028 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); 3029 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
3029 3030
3030 // At this point the ProxyService should have re-configured itself to use the 3031 // At this point the ProxyService should have re-configured itself to use the
3031 // new PAC script. 3032 // new PAC script.
3032 3033
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3125 ASSERT_TRUE(factory->pending_requests().empty()); 3126 ASSERT_TRUE(factory->pending_requests().empty());
3126 ASSERT_TRUE(resolver.pending_requests().empty()); 3127 ASSERT_TRUE(resolver.pending_requests().empty());
3127 3128
3128 // Make sure that our background checker is trying to download the expected 3129 // Make sure that our background checker is trying to download the expected
3129 // PAC script (same one as before). We will simulate the same response as 3130 // PAC script (same one as before). We will simulate the same response as
3130 // last time (i.e. the script is unchanged). 3131 // last time (i.e. the script is unchanged).
3131 EXPECT_TRUE(fetcher->has_pending_request()); 3132 EXPECT_TRUE(fetcher->has_pending_request());
3132 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 3133 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
3133 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 3134 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
3134 3135
3135 base::MessageLoop::current()->RunUntilIdle(); 3136 base::RunLoop().RunUntilIdle();
3136 3137
3137 ASSERT_TRUE(factory->pending_requests().empty()); 3138 ASSERT_TRUE(factory->pending_requests().empty());
3138 ASSERT_TRUE(resolver.pending_requests().empty()); 3139 ASSERT_TRUE(resolver.pending_requests().empty());
3139 3140
3140 // At this point the ProxyService is still running the same PAC script as 3141 // At this point the ProxyService is still running the same PAC script as
3141 // before. 3142 // before.
3142 3143
3143 // Start a second request. 3144 // Start a second request.
3144 ProxyInfo info2; 3145 ProxyInfo info2;
3145 TestCompletionCallback callback2; 3146 TestCompletionCallback callback2;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 ASSERT_TRUE(factory->pending_requests().empty()); 3236 ASSERT_TRUE(factory->pending_requests().empty());
3236 ASSERT_TRUE(resolver.pending_requests().empty()); 3237 ASSERT_TRUE(resolver.pending_requests().empty());
3237 3238
3238 // Make sure that our background checker is trying to download the expected 3239 // Make sure that our background checker is trying to download the expected
3239 // PAC script (same one as before). This time we will simulate a failure 3240 // PAC script (same one as before). This time we will simulate a failure
3240 // to download the script. 3241 // to download the script.
3241 EXPECT_TRUE(fetcher->has_pending_request()); 3242 EXPECT_TRUE(fetcher->has_pending_request());
3242 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 3243 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
3243 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 3244 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
3244 3245
3245 base::MessageLoop::current()->RunUntilIdle(); 3246 base::RunLoop().RunUntilIdle();
3246 3247
3247 // At this point the ProxyService should have re-configured itself to use 3248 // At this point the ProxyService should have re-configured itself to use
3248 // DIRECT connections rather than the given proxy resolver. 3249 // DIRECT connections rather than the given proxy resolver.
3249 3250
3250 // Start a second request. 3251 // Start a second request.
3251 ProxyInfo info2; 3252 ProxyInfo info2;
3252 TestCompletionCallback callback2; 3253 TestCompletionCallback callback2;
3253 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, 3254 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL,
3254 &info2, callback2.callback(), nullptr, nullptr, 3255 &info2, callback2.callback(), nullptr, nullptr,
3255 BoundNetLog()); 3256 BoundNetLog());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3407 // started the next poll, and made it as far as to request the download. 3408 // started the next poll, and made it as far as to request the download.
3408 3409
3409 EXPECT_TRUE(fetcher->has_pending_request()); 3410 EXPECT_TRUE(fetcher->has_pending_request());
3410 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 3411 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
3411 3412
3412 // This time we will fail the download, to simulate a PAC script change. 3413 // This time we will fail the download, to simulate a PAC script change.
3413 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 3414 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
3414 3415
3415 // Drain the message loop, so ProxyService is notified of the change 3416 // Drain the message loop, so ProxyService is notified of the change
3416 // and has a chance to re-configure itself. 3417 // and has a chance to re-configure itself.
3417 base::MessageLoop::current()->RunUntilIdle(); 3418 base::RunLoop().RunUntilIdle();
3418 3419
3419 // Start a third request -- this time we expect to get a direct connection 3420 // Start a third request -- this time we expect to get a direct connection
3420 // since the PAC script poller experienced a failure. 3421 // since the PAC script poller experienced a failure.
3421 ProxyInfo info3; 3422 ProxyInfo info3;
3422 TestCompletionCallback callback3; 3423 TestCompletionCallback callback3;
3423 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, 3424 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL,
3424 &info3, callback3.callback(), nullptr, nullptr, 3425 &info3, callback3.callback(), nullptr, nullptr,
3425 BoundNetLog()); 3426 BoundNetLog());
3426 EXPECT_EQ(OK, rv); 3427 EXPECT_EQ(OK, rv);
3427 EXPECT_TRUE(info3.is_direct()); 3428 EXPECT_TRUE(info3.is_direct());
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
3694 GURL(test.sanitized_url_unstripped), 3695 GURL(test.sanitized_url_unstripped),
3695 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); 3696 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE));
3696 3697
3697 EXPECT_EQ( 3698 EXPECT_EQ(
3698 GURL(test.sanitized_url), 3699 GURL(test.sanitized_url),
3699 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); 3700 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE));
3700 } 3701 }
3701 } 3702 }
3702 3703
3703 } // namespace net 3704 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_decider_unittest.cc ('k') | net/quic/bidirectional_stream_quic_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698