| 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/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 10 matching lines...) Expand all Loading... |
| 21 #include "net/proxy/proxy_config_service.h" | 21 #include "net/proxy/proxy_config_service.h" |
| 22 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" |
| 23 #include "net/proxy/proxy_script_fetcher.h" | 23 #include "net/proxy/proxy_script_fetcher.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 // TODO(eroman): Write a test which exercises | 26 // TODO(eroman): Write a test which exercises |
| 27 // ProxyService::SuspendAllPendingRequests(). | 27 // ProxyService::SuspendAllPendingRequests(). |
| 28 namespace net { | 28 namespace net { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; |
| 32 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; |
| 33 |
| 31 class MockProxyConfigService: public ProxyConfigService { | 34 class MockProxyConfigService: public ProxyConfigService { |
| 32 public: | 35 public: |
| 33 explicit MockProxyConfigService(const ProxyConfig& config) | 36 explicit MockProxyConfigService(const ProxyConfig& config) |
| 34 : availability_(CONFIG_VALID), | 37 : availability_(CONFIG_VALID), |
| 35 config_(config) { | 38 config_(config) { |
| 36 } | 39 } |
| 37 | 40 |
| 38 explicit MockProxyConfigService(const std::string& pac_url) | 41 explicit MockProxyConfigService(const std::string& pac_url) |
| 39 : availability_(CONFIG_VALID), | 42 : availability_(CONFIG_VALID), |
| 40 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { | 43 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 EXPECT_EQ(ERR_IO_PENDING, rv); | 419 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 417 | 420 |
| 418 // Check that nothing has been sent to the proxy resolver yet. | 421 // Check that nothing has been sent to the proxy resolver yet. |
| 419 ASSERT_EQ(0u, resolver->pending_requests().size()); | 422 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 420 | 423 |
| 421 // Downloading the PAC script succeeds. | 424 // Downloading the PAC script succeeds. |
| 422 EXPECT_TRUE(fetcher->has_pending_request()); | 425 EXPECT_TRUE(fetcher->has_pending_request()); |
| 423 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 426 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 424 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 427 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 425 | 428 |
| 426 // Simulate a parse error. | |
| 427 EXPECT_EQ(ASCIIToUTF16("invalid-script-contents"), | |
| 428 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 429 resolver->pending_set_pac_script_request()->CompleteNow( | |
| 430 ERR_PAC_SCRIPT_FAILED); | |
| 431 | |
| 432 EXPECT_FALSE(fetcher->has_pending_request()); | 429 EXPECT_FALSE(fetcher->has_pending_request()); |
| 433 ASSERT_EQ(0u, resolver->pending_requests().size()); | 430 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 434 | 431 |
| 435 // As the proxy resolver failed the request and is configured for a mandatory | 432 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was |
| 436 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 433 // mandatory for this configuration, the ProxyService must not implicitly |
| 434 // fall-back to DIRECT. |
| 437 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 435 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 438 callback.WaitForResult()); | 436 callback.WaitForResult()); |
| 439 EXPECT_FALSE(info.is_direct()); | 437 EXPECT_FALSE(info.is_direct()); |
| 440 } | 438 } |
| 441 | 439 |
| 442 TEST(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { | 440 TEST(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { |
| 443 // Test what happens when the ProxyResolver fails that is configured to use a | 441 // Test what happens when the ProxyResolver fails that is configured to use a |
| 444 // mandatory PAC script. The download and setting of the PAC script have | 442 // mandatory PAC script. The download and setting of the PAC script have |
| 445 // already succeeded, so this corresponds with a javascript runtime error | 443 // already succeeded, so this corresponds with a javascript runtime error |
| 446 // while calling FindProxyForURL(). | 444 // while calling FindProxyForURL(). |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 rv = service.ResolveProxy( | 1186 rv = service.ResolveProxy( |
| 1189 GURL("http://request3"), &info3, &callback3, NULL, BoundNetLog()); | 1187 GURL("http://request3"), &info3, &callback3, NULL, BoundNetLog()); |
| 1190 EXPECT_EQ(ERR_IO_PENDING, rv); | 1188 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1191 | 1189 |
| 1192 // Nothing has been sent to the resolver yet. | 1190 // Nothing has been sent to the resolver yet. |
| 1193 EXPECT_TRUE(resolver->pending_requests().empty()); | 1191 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1194 | 1192 |
| 1195 // At this point the ProxyService should be waiting for the | 1193 // At this point the ProxyService should be waiting for the |
| 1196 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1194 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1197 // PAC script download completion. | 1195 // PAC script download completion. |
| 1198 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1196 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1199 | 1197 |
| 1200 // Now that the PAC script is downloaded, it will have been sent to the proxy | 1198 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 1201 // resolver. | 1199 // resolver. |
| 1202 EXPECT_EQ(ASCIIToUTF16("pac-v1"), | 1200 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1203 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1201 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1204 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1202 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1205 | 1203 |
| 1206 ASSERT_EQ(3u, resolver->pending_requests().size()); | 1204 ASSERT_EQ(3u, resolver->pending_requests().size()); |
| 1207 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1205 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1208 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1206 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1209 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 1207 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
| 1210 | 1208 |
| 1211 // Complete all the requests (in some order). | 1209 // Complete all the requests (in some order). |
| 1212 // Note that as we complete requests, they shift up in |pending_requests()|. | 1210 // Note that as we complete requests, they shift up in |pending_requests()|. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 // We now change out the ProxyService's script fetcher. We should restart | 1268 // We now change out the ProxyService's script fetcher. We should restart |
| 1271 // the initialization with the new fetcher. | 1269 // the initialization with the new fetcher. |
| 1272 | 1270 |
| 1273 fetcher = new MockProxyScriptFetcher; | 1271 fetcher = new MockProxyScriptFetcher; |
| 1274 service.SetProxyScriptFetchers(fetcher, | 1272 service.SetProxyScriptFetchers(fetcher, |
| 1275 new DoNothingDhcpProxyScriptFetcher()); | 1273 new DoNothingDhcpProxyScriptFetcher()); |
| 1276 | 1274 |
| 1277 // Nothing has been sent to the resolver yet. | 1275 // Nothing has been sent to the resolver yet. |
| 1278 EXPECT_TRUE(resolver->pending_requests().empty()); | 1276 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1279 | 1277 |
| 1280 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1278 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1281 | 1279 |
| 1282 // Now that the PAC script is downloaded, it will have been sent to the proxy | 1280 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 1283 // resolver. | 1281 // resolver. |
| 1284 EXPECT_EQ(ASCIIToUTF16("pac-v1"), | 1282 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1285 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1283 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1286 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1284 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1287 | 1285 |
| 1288 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1286 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1289 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1287 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1290 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1288 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1291 } | 1289 } |
| 1292 | 1290 |
| 1293 // Test cancellation of a request, while the PAC script is being fetched. | 1291 // Test cancellation of a request, while the PAC script is being fetched. |
| 1294 TEST(ProxyServiceTest, CancelWhilePACFetching) { | 1292 TEST(ProxyServiceTest, CancelWhilePACFetching) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 // Nothing has been sent to the resolver yet. | 1331 // Nothing has been sent to the resolver yet. |
| 1334 EXPECT_TRUE(resolver->pending_requests().empty()); | 1332 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1335 | 1333 |
| 1336 // Cancel the first 2 requests. | 1334 // Cancel the first 2 requests. |
| 1337 service.CancelPacRequest(request1); | 1335 service.CancelPacRequest(request1); |
| 1338 service.CancelPacRequest(request2); | 1336 service.CancelPacRequest(request2); |
| 1339 | 1337 |
| 1340 // At this point the ProxyService should be waiting for the | 1338 // At this point the ProxyService should be waiting for the |
| 1341 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1339 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1342 // PAC script download completion. | 1340 // PAC script download completion. |
| 1343 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1341 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1344 | 1342 |
| 1345 // Now that the PAC script is downloaded, it will have been sent to the | 1343 // Now that the PAC script is downloaded, it will have been sent to the |
| 1346 // proxy resolver. | 1344 // proxy resolver. |
| 1347 EXPECT_EQ(ASCIIToUTF16("pac-v1"), | 1345 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1348 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1346 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1349 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1347 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1350 | 1348 |
| 1351 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1349 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1352 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[0]->url()); | 1350 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[0]->url()); |
| 1353 | 1351 |
| 1354 // Complete all the requests. | 1352 // Complete all the requests. |
| 1355 resolver->pending_requests()[0]->results()->UseNamedProxy("request3:80"); | 1353 resolver->pending_requests()[0]->results()->UseNamedProxy("request3:80"); |
| 1356 resolver->pending_requests()[0]->CompleteNow(OK); | 1354 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1357 | 1355 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 | 1414 |
| 1417 // It should be trying to auto-detect first -- FAIL the autodetect during | 1415 // It should be trying to auto-detect first -- FAIL the autodetect during |
| 1418 // the script download. | 1416 // the script download. |
| 1419 EXPECT_TRUE(fetcher->has_pending_request()); | 1417 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1420 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1418 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1421 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1419 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
| 1422 | 1420 |
| 1423 // Next it should be trying the custom PAC url. | 1421 // Next it should be trying the custom PAC url. |
| 1424 EXPECT_TRUE(fetcher->has_pending_request()); | 1422 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1425 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1423 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1426 fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); | 1424 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1427 | 1425 |
| 1428 EXPECT_EQ(ASCIIToUTF16("custom-pac-script"), | 1426 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1429 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1427 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1430 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1428 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1431 | 1429 |
| 1432 // Now finally, the pending requests should have been sent to the resolver | 1430 // Now finally, the pending requests should have been sent to the resolver |
| 1433 // (which was initialized with custom PAC script). | 1431 // (which was initialized with custom PAC script). |
| 1434 | 1432 |
| 1435 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1433 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1436 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1437 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1435 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1438 | 1436 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 EXPECT_EQ(ERR_IO_PENDING, rv); | 1481 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1484 | 1482 |
| 1485 // Check that nothing has been sent to the proxy resolver yet. | 1483 // Check that nothing has been sent to the proxy resolver yet. |
| 1486 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1484 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1487 | 1485 |
| 1488 // It should be trying to auto-detect first -- succeed the download. | 1486 // It should be trying to auto-detect first -- succeed the download. |
| 1489 EXPECT_TRUE(fetcher->has_pending_request()); | 1487 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1490 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1488 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1491 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1489 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 1492 | 1490 |
| 1493 // Simulate a parse error. | 1491 // The script contents passed failed basic verification step (since didn't |
| 1494 EXPECT_EQ(ASCIIToUTF16("invalid-script-contents"), | 1492 // contain token FindProxyForURL), so it was never passed to the resolver. |
| 1495 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 1496 resolver->pending_set_pac_script_request()->CompleteNow( | |
| 1497 ERR_PAC_SCRIPT_FAILED); | |
| 1498 | 1493 |
| 1499 // Next it should be trying the custom PAC url. | 1494 // Next it should be trying the custom PAC url. |
| 1500 EXPECT_TRUE(fetcher->has_pending_request()); | 1495 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1501 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1496 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1502 fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); | 1497 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1503 | 1498 |
| 1504 EXPECT_EQ(ASCIIToUTF16("custom-pac-script"), | 1499 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1505 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1500 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1506 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1501 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1507 | 1502 |
| 1508 // Now finally, the pending requests should have been sent to the resolver | 1503 // Now finally, the pending requests should have been sent to the resolver |
| 1509 // (which was initialized with custom PAC script). | 1504 // (which was initialized with custom PAC script). |
| 1510 | 1505 |
| 1511 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1506 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1512 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1507 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1513 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1508 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1514 | 1509 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 int rv = service.ResolveProxy( | 1603 int rv = service.ResolveProxy( |
| 1609 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); | 1604 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); |
| 1610 EXPECT_EQ(ERR_IO_PENDING, rv); | 1605 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1611 | 1606 |
| 1612 // Check that nothing has been sent to the proxy resolver yet. | 1607 // Check that nothing has been sent to the proxy resolver yet. |
| 1613 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1608 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1614 | 1609 |
| 1615 // It should be trying to auto-detect first -- succeed the download. | 1610 // It should be trying to auto-detect first -- succeed the download. |
| 1616 EXPECT_TRUE(fetcher->has_pending_request()); | 1611 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1617 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1612 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1618 fetcher->NotifyFetchCompletion(OK, "auto-detect"); | 1613 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1619 | 1614 |
| 1620 EXPECT_EQ(ASCIIToUTF16("auto-detect"), | 1615 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1621 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1616 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1622 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1617 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1623 | 1618 |
| 1624 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1619 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1625 EXPECT_EQ(GURL("http://www.google.com"), | 1620 EXPECT_EQ(GURL("http://www.google.com"), |
| 1626 resolver->pending_requests()[0]->url()); | 1621 resolver->pending_requests()[0]->url()); |
| 1627 | 1622 |
| 1628 // Complete the pending request. | 1623 // Complete the pending request. |
| 1629 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1624 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 1630 resolver->pending_requests()[0]->CompleteNow(OK); | 1625 resolver->pending_requests()[0]->CompleteNow(OK); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 // The first request should have triggered initial download of PAC script. | 1811 // The first request should have triggered initial download of PAC script. |
| 1817 EXPECT_TRUE(fetcher->has_pending_request()); | 1812 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1818 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1813 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1819 | 1814 |
| 1820 // Nothing has been sent to the resolver yet. | 1815 // Nothing has been sent to the resolver yet. |
| 1821 EXPECT_TRUE(resolver->pending_requests().empty()); | 1816 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1822 | 1817 |
| 1823 // At this point the ProxyService should be waiting for the | 1818 // At this point the ProxyService should be waiting for the |
| 1824 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1819 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1825 // PAC script download completion. | 1820 // PAC script download completion. |
| 1826 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1821 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1827 | 1822 |
| 1828 // Now that the PAC script is downloaded, the request will have been sent to | 1823 // Now that the PAC script is downloaded, the request will have been sent to |
| 1829 // the proxy resolver. | 1824 // the proxy resolver. |
| 1830 EXPECT_EQ(ASCIIToUTF16("pac-v1"), | 1825 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1831 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1826 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1832 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1827 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1833 | 1828 |
| 1834 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1829 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1835 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1830 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1836 | 1831 |
| 1837 // Complete the pending request. | 1832 // Complete the pending request. |
| 1838 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1833 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 1839 resolver->pending_requests()[0]->CompleteNow(OK); | 1834 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1840 | 1835 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1858 // This second request should have triggered the re-download of the PAC | 1853 // This second request should have triggered the re-download of the PAC |
| 1859 // script (since we marked the network as having changed). | 1854 // script (since we marked the network as having changed). |
| 1860 EXPECT_TRUE(fetcher->has_pending_request()); | 1855 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1861 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1856 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1862 | 1857 |
| 1863 // Nothing has been sent to the resolver yet. | 1858 // Nothing has been sent to the resolver yet. |
| 1864 EXPECT_TRUE(resolver->pending_requests().empty()); | 1859 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1865 | 1860 |
| 1866 // Simulate the PAC script fetch as having completed (this time with | 1861 // Simulate the PAC script fetch as having completed (this time with |
| 1867 // different data). | 1862 // different data). |
| 1868 fetcher->NotifyFetchCompletion(OK, "pac-v2"); | 1863 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
| 1869 | 1864 |
| 1870 // Now that the PAC script is downloaded, the second request will have been | 1865 // Now that the PAC script is downloaded, the second request will have been |
| 1871 // sent to the proxy resolver. | 1866 // sent to the proxy resolver. |
| 1872 EXPECT_EQ(ASCIIToUTF16("pac-v2"), | 1867 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
| 1873 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1868 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1874 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1869 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1875 | 1870 |
| 1876 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1871 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1877 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 1872 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
| 1878 | 1873 |
| 1879 // Complete the pending second request. | 1874 // Complete the pending second request. |
| 1880 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1875 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 1881 resolver->pending_requests()[0]->CompleteNow(OK); | 1876 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1882 | 1877 |
| 1883 // Wait for completion callback, and verify that the request ran as expected. | 1878 // Wait for completion callback, and verify that the request ran as expected. |
| 1884 EXPECT_EQ(OK, callback2.WaitForResult()); | 1879 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1885 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1880 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1886 | 1881 |
| 1887 // Check that the expected events were outputted to the log stream. | 1882 // Check that the expected events were outputted to the log stream. |
| 1888 // In particular, PROXY_CONFIG_CHANGED should have only been emitted once | 1883 // In particular, PROXY_CONFIG_CHANGED should have only been emitted once |
| 1889 // (for the initial setup), and NOT a second time when the IP address | 1884 // (for the initial setup), and NOT a second time when the IP address |
| 1890 // changed. | 1885 // changed. |
| 1891 CapturingNetLog::EntryList entries; | 1886 CapturingNetLog::EntryList entries; |
| 1892 log.GetEntries(&entries); | 1887 log.GetEntries(&entries); |
| 1893 | 1888 |
| 1894 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 1889 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
| 1895 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 1890 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
| 1896 ASSERT_EQ(13u, entries.size()); | 1891 ASSERT_EQ(9u, entries.size()); |
| 1897 for (size_t i = 1; i < entries.size(); ++i) | 1892 for (size_t i = 1; i < entries.size(); ++i) |
| 1898 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 1893 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
| 1899 } | 1894 } |
| 1900 | 1895 |
| 1901 } // namespace net | 1896 } // namespace net |
| OLD | NEW |