| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 30 matching lines...) Expand all Loading... |
| 41 ProxyConfig config; | 41 ProxyConfig config; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 // A mock ProxyScriptFetcher. No result will be returned to the fetch client | 46 // A mock ProxyScriptFetcher. No result will be returned to the fetch client |
| 47 // until we call NotifyFetchCompletion() to set the results. | 47 // until we call NotifyFetchCompletion() to set the results. |
| 48 class MockProxyScriptFetcher : public ProxyScriptFetcher { | 48 class MockProxyScriptFetcher : public ProxyScriptFetcher { |
| 49 public: | 49 public: |
| 50 MockProxyScriptFetcher() | 50 MockProxyScriptFetcher() |
| 51 : pending_request_callback_(NULL), pending_request_bytes_(NULL) { | 51 : pending_request_callback_(NULL), pending_request_text_(NULL) { |
| 52 } | 52 } |
| 53 | 53 |
| 54 // ProxyScriptFetcher implementation. | 54 // ProxyScriptFetcher implementation. |
| 55 virtual int Fetch(const GURL& url, | 55 virtual int Fetch(const GURL& url, |
| 56 std::string* bytes, | 56 string16* text, |
| 57 CompletionCallback* callback) { | 57 CompletionCallback* callback) { |
| 58 DCHECK(!has_pending_request()); | 58 DCHECK(!has_pending_request()); |
| 59 | 59 |
| 60 // Save the caller's information, and have them wait. | 60 // Save the caller's information, and have them wait. |
| 61 pending_request_url_ = url; | 61 pending_request_url_ = url; |
| 62 pending_request_callback_ = callback; | 62 pending_request_callback_ = callback; |
| 63 pending_request_bytes_ = bytes; | 63 pending_request_text_ = text; |
| 64 return ERR_IO_PENDING; | 64 return ERR_IO_PENDING; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void NotifyFetchCompletion(int result, const std::string& bytes) { | 67 void NotifyFetchCompletion(int result, const std::string& ascii_text) { |
| 68 DCHECK(has_pending_request()); | 68 DCHECK(has_pending_request()); |
| 69 *pending_request_bytes_ = bytes; | 69 *pending_request_text_ = ASCIIToUTF16(ascii_text); |
| 70 CompletionCallback* callback = pending_request_callback_; | 70 CompletionCallback* callback = pending_request_callback_; |
| 71 pending_request_callback_ = NULL; | 71 pending_request_callback_ = NULL; |
| 72 callback->Run(result); | 72 callback->Run(result); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void Cancel() {} | 75 virtual void Cancel() {} |
| 76 | 76 |
| 77 const GURL& pending_request_url() const { | 77 const GURL& pending_request_url() const { |
| 78 return pending_request_url_; | 78 return pending_request_url_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool has_pending_request() const { | 81 bool has_pending_request() const { |
| 82 return pending_request_callback_ != NULL; | 82 return pending_request_callback_ != NULL; |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 GURL pending_request_url_; | 86 GURL pending_request_url_; |
| 87 CompletionCallback* pending_request_callback_; | 87 CompletionCallback* pending_request_callback_; |
| 88 std::string* pending_request_bytes_; | 88 string16* pending_request_text_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 TEST(ProxyServiceTest, Direct) { | 91 TEST(ProxyServiceTest, Direct) { |
| 92 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 92 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 93 scoped_refptr<ProxyService> service( | 93 scoped_refptr<ProxyService> service( |
| 94 new ProxyService(new MockProxyConfigService, resolver, NULL)); | 94 new ProxyService(new MockProxyConfigService, resolver, NULL)); |
| 95 | 95 |
| 96 GURL url("http://www.google.com/"); | 96 GURL url("http://www.google.com/"); |
| 97 | 97 |
| 98 ProxyInfo info; | 98 ProxyInfo info; |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 // Nothing has been sent to the resolver yet. | 950 // Nothing has been sent to the resolver yet. |
| 951 EXPECT_TRUE(resolver->pending_requests().empty()); | 951 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 952 | 952 |
| 953 // At this point the ProxyService should be waiting for the | 953 // At this point the ProxyService should be waiting for the |
| 954 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 954 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 955 // PAC script download completion. | 955 // PAC script download completion. |
| 956 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 956 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| 957 | 957 |
| 958 // Now that the PAC script is downloaded, it will have been sent to the proxy | 958 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 959 // resolver. | 959 // resolver. |
| 960 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes()); | 960 EXPECT_EQ(ASCIIToUTF16("pac-v1"), |
| 961 resolver->pending_set_pac_script_request()->pac_script()); |
| 961 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 962 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 962 | 963 |
| 963 ASSERT_EQ(3u, resolver->pending_requests().size()); | 964 ASSERT_EQ(3u, resolver->pending_requests().size()); |
| 964 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 965 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 965 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 966 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 966 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 967 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
| 967 | 968 |
| 968 // Complete all the requests (in some order). | 969 // Complete all the requests (in some order). |
| 969 // Note that as we complete requests, they shift up in |pending_requests()|. | 970 // Note that as we complete requests, they shift up in |pending_requests()|. |
| 970 | 971 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 fetcher = new MockProxyScriptFetcher; | 1031 fetcher = new MockProxyScriptFetcher; |
| 1031 service->SetProxyScriptFetcher(fetcher); | 1032 service->SetProxyScriptFetcher(fetcher); |
| 1032 | 1033 |
| 1033 // Nothing has been sent to the resolver yet. | 1034 // Nothing has been sent to the resolver yet. |
| 1034 EXPECT_TRUE(resolver->pending_requests().empty()); | 1035 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1035 | 1036 |
| 1036 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1037 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| 1037 | 1038 |
| 1038 // Now that the PAC script is downloaded, it will have been sent to the proxy | 1039 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 1039 // resolver. | 1040 // resolver. |
| 1040 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes()); | 1041 EXPECT_EQ(ASCIIToUTF16("pac-v1"), |
| 1042 resolver->pending_set_pac_script_request()->pac_script()); |
| 1041 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1043 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1042 | 1044 |
| 1043 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1045 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1044 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1046 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1045 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1047 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1046 } | 1048 } |
| 1047 | 1049 |
| 1048 // Test cancellation of a request, while the PAC script is being fetched. | 1050 // Test cancellation of a request, while the PAC script is being fetched. |
| 1049 TEST(ProxyServiceTest, CancelWhilePACFetching) { | 1051 TEST(ProxyServiceTest, CancelWhilePACFetching) { |
| 1050 MockProxyConfigService* config_service = | 1052 MockProxyConfigService* config_service = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 service->CancelPacRequest(request1); | 1094 service->CancelPacRequest(request1); |
| 1093 service->CancelPacRequest(request2); | 1095 service->CancelPacRequest(request2); |
| 1094 | 1096 |
| 1095 // At this point the ProxyService should be waiting for the | 1097 // At this point the ProxyService should be waiting for the |
| 1096 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1098 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1097 // PAC script download completion. | 1099 // PAC script download completion. |
| 1098 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1100 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| 1099 | 1101 |
| 1100 // Now that the PAC script is downloaded, it will have been sent to the | 1102 // Now that the PAC script is downloaded, it will have been sent to the |
| 1101 // proxy resolver. | 1103 // proxy resolver. |
| 1102 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes()); | 1104 EXPECT_EQ(ASCIIToUTF16("pac-v1"), |
| 1105 resolver->pending_set_pac_script_request()->pac_script()); |
| 1103 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1106 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1104 | 1107 |
| 1105 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1108 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1106 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[0]->url()); | 1109 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[0]->url()); |
| 1107 | 1110 |
| 1108 // Complete all the requests. | 1111 // Complete all the requests. |
| 1109 resolver->pending_requests()[0]->results()->UseNamedProxy("request3:80"); | 1112 resolver->pending_requests()[0]->results()->UseNamedProxy("request3:80"); |
| 1110 resolver->pending_requests()[0]->CompleteNow(OK); | 1113 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1111 | 1114 |
| 1112 EXPECT_EQ(OK, callback3.WaitForResult()); | 1115 EXPECT_EQ(OK, callback3.WaitForResult()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 // the script download. | 1172 // the script download. |
| 1170 EXPECT_TRUE(fetcher->has_pending_request()); | 1173 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1171 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1174 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1172 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1175 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
| 1173 | 1176 |
| 1174 // Next it should be trying the custom PAC url. | 1177 // Next it should be trying the custom PAC url. |
| 1175 EXPECT_TRUE(fetcher->has_pending_request()); | 1178 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1176 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1179 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1177 fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); | 1180 fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); |
| 1178 | 1181 |
| 1179 EXPECT_EQ("custom-pac-script", | 1182 EXPECT_EQ(ASCIIToUTF16("custom-pac-script"), |
| 1180 resolver->pending_set_pac_script_request()->pac_bytes()); | 1183 resolver->pending_set_pac_script_request()->pac_script()); |
| 1181 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1184 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1182 | 1185 |
| 1183 // Now finally, the pending requests should have been sent to the resolver | 1186 // Now finally, the pending requests should have been sent to the resolver |
| 1184 // (which was initialized with custom PAC script). | 1187 // (which was initialized with custom PAC script). |
| 1185 | 1188 |
| 1186 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1189 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1187 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1190 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1188 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1191 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1189 | 1192 |
| 1190 // Complete the pending requests. | 1193 // Complete the pending requests. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 | 1238 |
| 1236 // Check that nothing has been sent to the proxy resolver yet. | 1239 // Check that nothing has been sent to the proxy resolver yet. |
| 1237 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1240 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1238 | 1241 |
| 1239 // It should be trying to auto-detect first -- succeed the download. | 1242 // It should be trying to auto-detect first -- succeed the download. |
| 1240 EXPECT_TRUE(fetcher->has_pending_request()); | 1243 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1241 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1244 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1242 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1245 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 1243 | 1246 |
| 1244 // Simulate a parse error. | 1247 // Simulate a parse error. |
| 1245 EXPECT_EQ("invalid-script-contents", | 1248 EXPECT_EQ(ASCIIToUTF16("invalid-script-contents"), |
| 1246 resolver->pending_set_pac_script_request()->pac_bytes()); | 1249 resolver->pending_set_pac_script_request()->pac_script()); |
| 1247 resolver->pending_set_pac_script_request()->CompleteNow( | 1250 resolver->pending_set_pac_script_request()->CompleteNow( |
| 1248 ERR_PAC_SCRIPT_FAILED); | 1251 ERR_PAC_SCRIPT_FAILED); |
| 1249 | 1252 |
| 1250 // Next it should be trying the custom PAC url. | 1253 // Next it should be trying the custom PAC url. |
| 1251 EXPECT_TRUE(fetcher->has_pending_request()); | 1254 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1252 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1255 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1253 fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); | 1256 fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); |
| 1254 | 1257 |
| 1255 EXPECT_EQ("custom-pac-script", | 1258 EXPECT_EQ(ASCIIToUTF16("custom-pac-script"), |
| 1256 resolver->pending_set_pac_script_request()->pac_bytes()); | 1259 resolver->pending_set_pac_script_request()->pac_script()); |
| 1257 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1260 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1258 | 1261 |
| 1259 // Now finally, the pending requests should have been sent to the resolver | 1262 // Now finally, the pending requests should have been sent to the resolver |
| 1260 // (which was initialized with custom PAC script). | 1263 // (which was initialized with custom PAC script). |
| 1261 | 1264 |
| 1262 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1265 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1263 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1266 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1264 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1267 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1265 | 1268 |
| 1266 // Complete the pending requests. | 1269 // Complete the pending requests. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 EXPECT_EQ(ERR_IO_PENDING, rv); | 1364 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1362 | 1365 |
| 1363 // Check that nothing has been sent to the proxy resolver yet. | 1366 // Check that nothing has been sent to the proxy resolver yet. |
| 1364 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1367 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1365 | 1368 |
| 1366 // It should be trying to auto-detect first -- succeed the download. | 1369 // It should be trying to auto-detect first -- succeed the download. |
| 1367 EXPECT_TRUE(fetcher->has_pending_request()); | 1370 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1368 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1371 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1369 fetcher->NotifyFetchCompletion(OK, "auto-detect"); | 1372 fetcher->NotifyFetchCompletion(OK, "auto-detect"); |
| 1370 | 1373 |
| 1371 EXPECT_EQ("auto-detect", | 1374 EXPECT_EQ(ASCIIToUTF16("auto-detect"), |
| 1372 resolver->pending_set_pac_script_request()->pac_bytes()); | 1375 resolver->pending_set_pac_script_request()->pac_script()); |
| 1373 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1376 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1374 | 1377 |
| 1375 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1378 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1376 EXPECT_EQ(GURL("http://www.google.com"), | 1379 EXPECT_EQ(GURL("http://www.google.com"), |
| 1377 resolver->pending_requests()[0]->url()); | 1380 resolver->pending_requests()[0]->url()); |
| 1378 | 1381 |
| 1379 // Complete the pending request. | 1382 // Complete the pending request. |
| 1380 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1383 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 1381 resolver->pending_requests()[0]->CompleteNow(OK); | 1384 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1382 | 1385 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 // Nothing has been sent to the resolver yet. | 1627 // Nothing has been sent to the resolver yet. |
| 1625 EXPECT_TRUE(resolver->pending_requests().empty()); | 1628 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1626 | 1629 |
| 1627 // At this point the ProxyService should be waiting for the | 1630 // At this point the ProxyService should be waiting for the |
| 1628 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1631 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1629 // PAC script download completion. | 1632 // PAC script download completion. |
| 1630 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1633 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| 1631 | 1634 |
| 1632 // Now that the PAC script is downloaded, the request will have been sent to | 1635 // Now that the PAC script is downloaded, the request will have been sent to |
| 1633 // the proxy resolver. | 1636 // the proxy resolver. |
| 1634 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes()); | 1637 EXPECT_EQ(ASCIIToUTF16("pac-v1"), |
| 1638 resolver->pending_set_pac_script_request()->pac_script()); |
| 1635 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1639 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1636 | 1640 |
| 1637 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1641 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1638 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1642 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1639 | 1643 |
| 1640 // Complete the pending request. | 1644 // Complete the pending request. |
| 1641 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1645 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 1642 resolver->pending_requests()[0]->CompleteNow(OK); | 1646 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1643 | 1647 |
| 1644 // Wait for completion callback, and verify that the request ran as expected. | 1648 // Wait for completion callback, and verify that the request ran as expected. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1665 | 1669 |
| 1666 // Nothing has been sent to the resolver yet. | 1670 // Nothing has been sent to the resolver yet. |
| 1667 EXPECT_TRUE(resolver->pending_requests().empty()); | 1671 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1668 | 1672 |
| 1669 // Simulate the PAC script fetch as having completed (this time with | 1673 // Simulate the PAC script fetch as having completed (this time with |
| 1670 // different data). | 1674 // different data). |
| 1671 fetcher->NotifyFetchCompletion(OK, "pac-v2"); | 1675 fetcher->NotifyFetchCompletion(OK, "pac-v2"); |
| 1672 | 1676 |
| 1673 // Now that the PAC script is downloaded, the second request will have been | 1677 // Now that the PAC script is downloaded, the second request will have been |
| 1674 // sent to the proxy resolver. | 1678 // sent to the proxy resolver. |
| 1675 EXPECT_EQ("pac-v2", resolver->pending_set_pac_script_request()->pac_bytes()); | 1679 EXPECT_EQ(ASCIIToUTF16("pac-v2"), |
| 1680 resolver->pending_set_pac_script_request()->pac_script()); |
| 1676 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1681 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1677 | 1682 |
| 1678 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1683 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1679 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 1684 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
| 1680 | 1685 |
| 1681 // Complete the pending second request. | 1686 // Complete the pending second request. |
| 1682 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1687 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 1683 resolver->pending_requests()[0]->CompleteNow(OK); | 1688 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1684 | 1689 |
| 1685 // Wait for completion callback, and verify that the request ran as expected. | 1690 // Wait for completion callback, and verify that the request ran as expected. |
| 1686 EXPECT_EQ(OK, callback2.WaitForResult()); | 1691 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1687 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1692 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1688 } | 1693 } |
| 1689 | 1694 |
| 1690 } // namespace net | 1695 } // namespace net |
| OLD | NEW |