| OLD | NEW |
| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 Rules rules; | 181 Rules rules; |
| 182 RuleBasedProxyScriptFetcher fetcher(&rules); | 182 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 183 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 183 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 184 | 184 |
| 185 ProxyConfig config; | 185 ProxyConfig config; |
| 186 config.set_pac_url(GURL("http://custom/proxy.pac")); | 186 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 187 | 187 |
| 188 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 188 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 189 | 189 |
| 190 TestCompletionCallback callback; | 190 TestCompletionCallback callback; |
| 191 CapturingNetLog log; | 191 TestNetLog log; |
| 192 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 192 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 193 EXPECT_EQ(OK, decider.Start( | 193 EXPECT_EQ(OK, decider.Start( |
| 194 config, base::TimeDelta(), true, callback.callback())); | 194 config, base::TimeDelta(), true, callback.callback())); |
| 195 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); | 195 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); |
| 196 | 196 |
| 197 // Check the NetLog was filled correctly. | 197 // Check the NetLog was filled correctly. |
| 198 CapturingNetLog::CapturedEntryList entries; | 198 TestNetLog::CapturedEntryList entries; |
| 199 log.GetEntries(&entries); | 199 log.GetEntries(&entries); |
| 200 | 200 |
| 201 EXPECT_EQ(4u, entries.size()); | 201 EXPECT_EQ(4u, entries.size()); |
| 202 EXPECT_TRUE(LogContainsBeginEvent( | 202 EXPECT_TRUE(LogContainsBeginEvent( |
| 203 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 203 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 204 EXPECT_TRUE(LogContainsBeginEvent( | 204 EXPECT_TRUE(LogContainsBeginEvent( |
| 205 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 205 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 206 EXPECT_TRUE(LogContainsEndEvent( | 206 EXPECT_TRUE(LogContainsEndEvent( |
| 207 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 207 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 208 EXPECT_TRUE(LogContainsEndEvent( | 208 EXPECT_TRUE(LogContainsEndEvent( |
| 209 entries, 3, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 209 entries, 3, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 210 | 210 |
| 211 EXPECT_TRUE(decider.effective_config().has_pac_url()); | 211 EXPECT_TRUE(decider.effective_config().has_pac_url()); |
| 212 EXPECT_EQ(config.pac_url(), decider.effective_config().pac_url()); | 212 EXPECT_EQ(config.pac_url(), decider.effective_config().pac_url()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Fail downloading the custom PAC script. | 215 // Fail downloading the custom PAC script. |
| 216 TEST(ProxyScriptDeciderTest, CustomPacFails1) { | 216 TEST(ProxyScriptDeciderTest, CustomPacFails1) { |
| 217 Rules rules; | 217 Rules rules; |
| 218 RuleBasedProxyScriptFetcher fetcher(&rules); | 218 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 219 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 219 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 220 | 220 |
| 221 ProxyConfig config; | 221 ProxyConfig config; |
| 222 config.set_pac_url(GURL("http://custom/proxy.pac")); | 222 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 223 | 223 |
| 224 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 224 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 225 | 225 |
| 226 TestCompletionCallback callback; | 226 TestCompletionCallback callback; |
| 227 CapturingNetLog log; | 227 TestNetLog log; |
| 228 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 228 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 229 EXPECT_EQ(kFailedDownloading, | 229 EXPECT_EQ(kFailedDownloading, |
| 230 decider.Start(config, base::TimeDelta(), true, | 230 decider.Start(config, base::TimeDelta(), true, |
| 231 callback.callback())); | 231 callback.callback())); |
| 232 EXPECT_EQ(NULL, decider.script_data()); | 232 EXPECT_EQ(NULL, decider.script_data()); |
| 233 | 233 |
| 234 // Check the NetLog was filled correctly. | 234 // Check the NetLog was filled correctly. |
| 235 CapturingNetLog::CapturedEntryList entries; | 235 TestNetLog::CapturedEntryList entries; |
| 236 log.GetEntries(&entries); | 236 log.GetEntries(&entries); |
| 237 | 237 |
| 238 EXPECT_EQ(4u, entries.size()); | 238 EXPECT_EQ(4u, entries.size()); |
| 239 EXPECT_TRUE(LogContainsBeginEvent( | 239 EXPECT_TRUE(LogContainsBeginEvent( |
| 240 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 240 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 241 EXPECT_TRUE(LogContainsBeginEvent( | 241 EXPECT_TRUE(LogContainsBeginEvent( |
| 242 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 242 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 243 EXPECT_TRUE(LogContainsEndEvent( | 243 EXPECT_TRUE(LogContainsEndEvent( |
| 244 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 244 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 245 EXPECT_TRUE(LogContainsEndEvent( | 245 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 470 |
| 471 ProxyConfig config; | 471 ProxyConfig config; |
| 472 config.set_auto_detect(true); | 472 config.set_auto_detect(true); |
| 473 config.set_pac_url(GURL("http://custom/proxy.pac")); | 473 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 474 config.proxy_rules().ParseFromString("unused-manual-proxy:99"); | 474 config.proxy_rules().ParseFromString("unused-manual-proxy:99"); |
| 475 | 475 |
| 476 rules.AddFailParsingRule("http://wpad/wpad.dat"); | 476 rules.AddFailParsingRule("http://wpad/wpad.dat"); |
| 477 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 477 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 478 | 478 |
| 479 TestCompletionCallback callback; | 479 TestCompletionCallback callback; |
| 480 CapturingNetLog log; | 480 TestNetLog log; |
| 481 | 481 |
| 482 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 482 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 483 EXPECT_EQ(OK, decider.Start(config, base::TimeDelta(), | 483 EXPECT_EQ(OK, decider.Start(config, base::TimeDelta(), |
| 484 true, callback.callback())); | 484 true, callback.callback())); |
| 485 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); | 485 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); |
| 486 | 486 |
| 487 // Verify that the effective configuration no longer contains auto detect or | 487 // Verify that the effective configuration no longer contains auto detect or |
| 488 // any of the manual settings. | 488 // any of the manual settings. |
| 489 EXPECT_TRUE(decider.effective_config().Equals( | 489 EXPECT_TRUE(decider.effective_config().Equals( |
| 490 ProxyConfig::CreateFromCustomPacURL(GURL("http://custom/proxy.pac")))); | 490 ProxyConfig::CreateFromCustomPacURL(GURL("http://custom/proxy.pac")))); |
| 491 | 491 |
| 492 // Check the NetLog was filled correctly. | 492 // Check the NetLog was filled correctly. |
| 493 // (Note that various states are repeated since both WPAD and custom | 493 // (Note that various states are repeated since both WPAD and custom |
| 494 // PAC scripts are tried). | 494 // PAC scripts are tried). |
| 495 CapturingNetLog::CapturedEntryList entries; | 495 TestNetLog::CapturedEntryList entries; |
| 496 log.GetEntries(&entries); | 496 log.GetEntries(&entries); |
| 497 | 497 |
| 498 EXPECT_EQ(10u, entries.size()); | 498 EXPECT_EQ(10u, entries.size()); |
| 499 EXPECT_TRUE(LogContainsBeginEvent( | 499 EXPECT_TRUE(LogContainsBeginEvent( |
| 500 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 500 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 501 // This is the DHCP phase, which fails fetching rather than parsing, so | 501 // This is the DHCP phase, which fails fetching rather than parsing, so |
| 502 // there is no pair of SET_PAC_SCRIPT events. | 502 // there is no pair of SET_PAC_SCRIPT events. |
| 503 EXPECT_TRUE(LogContainsBeginEvent( | 503 EXPECT_TRUE(LogContainsBeginEvent( |
| 504 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 504 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 505 EXPECT_TRUE(LogContainsEndEvent( | 505 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 Rules rules; | 575 Rules rules; |
| 576 RuleBasedProxyScriptFetcher fetcher(&rules); | 576 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 577 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 577 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 578 | 578 |
| 579 ProxyConfig config; | 579 ProxyConfig config; |
| 580 config.set_pac_url(GURL("http://custom/proxy.pac")); | 580 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 581 | 581 |
| 582 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 582 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 583 | 583 |
| 584 TestCompletionCallback callback; | 584 TestCompletionCallback callback; |
| 585 CapturingNetLog log; | 585 TestNetLog log; |
| 586 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 586 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 587 EXPECT_EQ(ERR_IO_PENDING, | 587 EXPECT_EQ(ERR_IO_PENDING, |
| 588 decider.Start(config, base::TimeDelta::FromMilliseconds(1), | 588 decider.Start(config, base::TimeDelta::FromMilliseconds(1), |
| 589 true, callback.callback())); | 589 true, callback.callback())); |
| 590 | 590 |
| 591 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); | 591 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); |
| 592 EXPECT_EQ(NULL, decider.script_data()); | 592 EXPECT_EQ(NULL, decider.script_data()); |
| 593 | 593 |
| 594 // Check the NetLog was filled correctly. | 594 // Check the NetLog was filled correctly. |
| 595 CapturingNetLog::CapturedEntryList entries; | 595 TestNetLog::CapturedEntryList entries; |
| 596 log.GetEntries(&entries); | 596 log.GetEntries(&entries); |
| 597 | 597 |
| 598 EXPECT_EQ(6u, entries.size()); | 598 EXPECT_EQ(6u, entries.size()); |
| 599 EXPECT_TRUE(LogContainsBeginEvent( | 599 EXPECT_TRUE(LogContainsBeginEvent( |
| 600 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 600 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 601 EXPECT_TRUE(LogContainsBeginEvent( | 601 EXPECT_TRUE(LogContainsBeginEvent( |
| 602 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); | 602 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); |
| 603 EXPECT_TRUE(LogContainsEndEvent( | 603 EXPECT_TRUE(LogContainsEndEvent( |
| 604 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); | 604 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); |
| 605 EXPECT_TRUE(LogContainsBeginEvent( | 605 EXPECT_TRUE(LogContainsBeginEvent( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 617 Rules rules; | 617 Rules rules; |
| 618 RuleBasedProxyScriptFetcher fetcher(&rules); | 618 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 619 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 619 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 620 | 620 |
| 621 ProxyConfig config; | 621 ProxyConfig config; |
| 622 config.set_pac_url(GURL("http://custom/proxy.pac")); | 622 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 623 | 623 |
| 624 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 624 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 625 | 625 |
| 626 TestCompletionCallback callback; | 626 TestCompletionCallback callback; |
| 627 CapturingNetLog log; | 627 TestNetLog log; |
| 628 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 628 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 629 EXPECT_EQ(kFailedDownloading, | 629 EXPECT_EQ(kFailedDownloading, |
| 630 decider.Start(config, base::TimeDelta::FromSeconds(-5), | 630 decider.Start(config, base::TimeDelta::FromSeconds(-5), |
| 631 true, callback.callback())); | 631 true, callback.callback())); |
| 632 EXPECT_EQ(NULL, decider.script_data()); | 632 EXPECT_EQ(NULL, decider.script_data()); |
| 633 | 633 |
| 634 // Check the NetLog was filled correctly. | 634 // Check the NetLog was filled correctly. |
| 635 CapturingNetLog::CapturedEntryList entries; | 635 TestNetLog::CapturedEntryList entries; |
| 636 log.GetEntries(&entries); | 636 log.GetEntries(&entries); |
| 637 | 637 |
| 638 EXPECT_EQ(4u, entries.size()); | 638 EXPECT_EQ(4u, entries.size()); |
| 639 EXPECT_TRUE(LogContainsBeginEvent( | 639 EXPECT_TRUE(LogContainsBeginEvent( |
| 640 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 640 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 641 EXPECT_TRUE(LogContainsBeginEvent( | 641 EXPECT_TRUE(LogContainsBeginEvent( |
| 642 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 642 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 643 EXPECT_TRUE(LogContainsEndEvent( | 643 EXPECT_TRUE(LogContainsEndEvent( |
| 644 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 644 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 645 EXPECT_TRUE(LogContainsEndEvent( | 645 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 778 |
| 779 // Run the message loop to let the DHCP fetch complete and post the results | 779 // Run the message loop to let the DHCP fetch complete and post the results |
| 780 // back. Before the fix linked to above, this would try to invoke on | 780 // back. Before the fix linked to above, this would try to invoke on |
| 781 // the callback object provided by ProxyScriptDecider after it was | 781 // the callback object provided by ProxyScriptDecider after it was |
| 782 // no longer valid. | 782 // no longer valid. |
| 783 base::MessageLoop::current()->RunUntilIdle(); | 783 base::MessageLoop::current()->RunUntilIdle(); |
| 784 } | 784 } |
| 785 | 785 |
| 786 } // namespace | 786 } // namespace |
| 787 } // namespace net | 787 } // namespace net |
| OLD | NEW |