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

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

Issue 940813003: Use a utility process for the Mojo v8 proxy resolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-pac-in-process-enable
Patch Set: Address some review comments. Created 5 years, 9 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
« net/proxy/proxy_service.cc ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 3065 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 // since the PAC script poller experienced a failure. 3076 // since the PAC script poller experienced a failure.
3077 ProxyInfo info3; 3077 ProxyInfo info3;
3078 TestCompletionCallback callback3; 3078 TestCompletionCallback callback3;
3079 rv = service.ResolveProxy( 3079 rv = service.ResolveProxy(
3080 GURL("http://request3"), net::LOAD_NORMAL, &info3, callback3.callback(), 3080 GURL("http://request3"), net::LOAD_NORMAL, &info3, callback3.callback(),
3081 NULL, NULL, BoundNetLog()); 3081 NULL, NULL, BoundNetLog());
3082 EXPECT_EQ(OK, rv); 3082 EXPECT_EQ(OK, rv);
3083 EXPECT_TRUE(info3.is_direct()); 3083 EXPECT_TRUE(info3.is_direct());
3084 } 3084 }
3085 3085
3086 // This tests the re-fetching and application of the PAC script after the proxy
3087 // resolver returns with a ERR_PAC_SCRIPT_TERMINATED error. This is for
3088 // out-of-process v8 resolver which returns that error if the resolver process
3089 // crashes.
3090 TEST_F(ProxyServiceTest, PACScriptRefetchAfterTerminatedResolveProxy) {
3091 ProxyConfig config(
3092 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
3093 config.set_pac_mandatory(true);
3094 MockProxyConfigService* config_service = new MockProxyConfigService(config);
3095
3096 MockAsyncProxyResolverExpectsBytes* resolver =
3097 new MockAsyncProxyResolverExpectsBytes;
3098
3099 ProxyService service(config_service, resolver, NULL);
3100
3101 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
3102 service.SetProxyScriptFetchers(fetcher,
3103 new DoNothingDhcpProxyScriptFetcher());
3104
3105 // Start 1 request.
3106 ProxyInfo info1;
3107 TestCompletionCallback callback1;
3108 int rv =
3109 service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, &info1,
3110 callback1.callback(), NULL, NULL, BoundNetLog());
3111 EXPECT_EQ(ERR_IO_PENDING, rv);
3112
3113 // The first request should have triggered initial download of PAC script.
3114 EXPECT_TRUE(fetcher->has_pending_request());
3115 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
3116
3117 // Nothing has been sent to the resolver yet.
3118 EXPECT_TRUE(resolver->pending_requests().empty());
3119
3120 // At this point the ProxyService should be waiting for the
3121 // ProxyScriptFetcher to invoke its completion callback, notifying it of
3122 // PAC script download completion.
3123 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
3124
3125 // Now that the PAC script is downloaded, the request will have been sent to
3126 // the proxy resolver.
3127 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
3128 resolver->pending_set_pac_script_request()->script_data()->utf16());
3129 resolver->pending_set_pac_script_request()->CompleteNow(OK);
3130
3131 ASSERT_EQ(1u, resolver->pending_requests().size());
3132 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url());
3133
3134 // Complete the pending request.
3135 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80");
3136 resolver->pending_requests()[0]->CompleteNow(OK);
3137
3138 // Wait for completion callback, and verify that the request ran as expected.
3139 EXPECT_EQ(OK, callback1.WaitForResult());
3140 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
3141
3142 // At this point we have initialized the proxy service using a PAC script.
3143 // Our PAC poller is set to update ONLY in response to network activity,
3144 // (i.e. another call to ResolveProxy()).
3145
3146 ASSERT_FALSE(fetcher->has_pending_request());
3147 ASSERT_TRUE(resolver->pending_requests().empty());
3148
3149 // Start a second request and third request.
3150 ProxyInfo info2;
3151 TestCompletionCallback callback2;
3152 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2,
3153 callback2.callback(), NULL, NULL, BoundNetLog());
3154 EXPECT_EQ(ERR_IO_PENDING, rv);
3155
3156 ProxyInfo info3;
3157 TestCompletionCallback callback3;
3158 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3,
3159 callback3.callback(), NULL, NULL, BoundNetLog());
3160 EXPECT_EQ(ERR_IO_PENDING, rv);
3161
3162 // Fail request 2 with ERR_PAC_SCRIPT_TERMINATED, which indicates the PAC
3163 // script has terminated fatally and needs to be reloaded. Request 3's resolve
3164 // request should be cancelled, but ProxyService keeps it and retries it
3165 // later.
3166 ASSERT_EQ(2u, resolver->pending_requests().size());
3167 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url());
3168 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url());
3169 resolver->pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED);
3170 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
3171 callback2.WaitForResult());
3172
3173 ASSERT_EQ(0u, resolver->pending_requests().size());
3174 ASSERT_EQ(1u, resolver->cancelled_requests().size());
3175
3176 // Since there's an active request, the proxy script should automatically be
3177 // re-fetched.
3178 EXPECT_TRUE(fetcher->has_pending_request());
3179 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
3180 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
3181 resolver->pending_set_pac_script_request()->script_data()->utf16());
3182 resolver->pending_set_pac_script_request()->CompleteNow(OK);
3183 ASSERT_EQ(1u, resolver->pending_requests().size());
3184 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[0]->url());
3185 resolver->pending_requests()[0]->results()->UseNamedProxy("request3:80");
3186 resolver->pending_requests()[0]->CompleteNow(OK);
3187
3188 EXPECT_EQ(OK, callback3.WaitForResult());
3189
3190 // Do another request which fails with ERR_PAC_SCRIPT_TERMINATED. This time,
3191 // there are no pending requests, so don't re-fetch the script until the next
3192 // request comes in.
3193 ProxyInfo info4;
3194 TestCompletionCallback callback4;
3195 rv = service.ResolveProxy(GURL("http://request4"), net::LOAD_NORMAL, &info4,
3196 callback4.callback(), NULL, NULL, BoundNetLog());
3197 EXPECT_EQ(ERR_IO_PENDING, rv);
3198 ASSERT_EQ(1u, resolver->pending_requests().size());
3199 resolver->pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED);
3200
3201 // There should be no automatic fetch request this time.
3202 EXPECT_FALSE(fetcher->has_pending_request());
3203
3204 // Now, the next request should cause a fetch.
3205 ProxyInfo info5;
3206 TestCompletionCallback callback5;
3207 rv = service.ResolveProxy(GURL("http://request5"), net::LOAD_NORMAL, &info5,
3208 callback5.callback(), NULL, NULL, BoundNetLog());
3209 EXPECT_EQ(ERR_IO_PENDING, rv);
3210 // No pending requests to the resolver since a script fetch is in progress.
3211 EXPECT_TRUE(resolver->pending_requests().empty());
3212
3213 // Now there should be a PAC script fetch.
3214 EXPECT_TRUE(fetcher->has_pending_request());
3215
3216 // Finish and verify.
3217 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
3218 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
3219 resolver->pending_set_pac_script_request()->script_data()->utf16());
3220 resolver->pending_set_pac_script_request()->CompleteNow(OK);
3221 ASSERT_EQ(1u, resolver->pending_requests().size());
3222 EXPECT_EQ(GURL("http://request5"), resolver->pending_requests()[0]->url());
3223 resolver->pending_requests()[0]->results()->UseNamedProxy("request5:80");
3224 resolver->pending_requests()[0]->CompleteNow(OK);
3225 EXPECT_EQ(OK, callback5.WaitForResult());
3226 EXPECT_EQ("request5:80", info5.proxy_server().ToURI());
3227 }
3228
3086 // Test that the synchronous resolution fails when a PAC script is active. 3229 // Test that the synchronous resolution fails when a PAC script is active.
3087 TEST_F(ProxyServiceTest, SynchronousWithPAC) { 3230 TEST_F(ProxyServiceTest, SynchronousWithPAC) {
3088 MockProxyConfigService* config_service = 3231 MockProxyConfigService* config_service =
3089 new MockProxyConfigService("http://foopy/proxy.pac"); 3232 new MockProxyConfigService("http://foopy/proxy.pac");
3090 3233
3091 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver(); 3234 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver();
3092 3235
3093 ProxyService service(config_service, resolver, NULL); 3236 ProxyService service(config_service, resolver, NULL);
3094 3237
3095 GURL url("http://www.google.com/"); 3238 GURL url("http://www.google.com/");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 url, net::LOAD_NORMAL, &info, NULL, log.bound()); 3272 url, net::LOAD_NORMAL, &info, NULL, log.bound());
3130 EXPECT_TRUE(synchronous_success); 3273 EXPECT_TRUE(synchronous_success);
3131 EXPECT_FALSE(info.is_direct()); 3274 EXPECT_FALSE(info.is_direct());
3132 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); 3275 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host());
3133 3276
3134 // No request should have been queued. 3277 // No request should have been queued.
3135 EXPECT_EQ(0u, resolver->pending_requests().size()); 3278 EXPECT_EQ(0u, resolver->pending_requests().size());
3136 } 3279 }
3137 3280
3138 } // namespace net 3281 } // namespace net
OLDNEW
« net/proxy/proxy_service.cc ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698