| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 16 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
| 17 #include "net/log/captured_net_log_entry.h" |
| 17 #include "net/log/net_log.h" | 18 #include "net/log/net_log.h" |
| 18 #include "net/log/net_log_unittest.h" | 19 #include "net/log/net_log_unittest.h" |
| 20 #include "net/log/test_net_log.h" |
| 19 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 21 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 20 #include "net/proxy/mock_proxy_script_fetcher.h" | 22 #include "net/proxy/mock_proxy_script_fetcher.h" |
| 21 #include "net/proxy/proxy_config.h" | 23 #include "net/proxy/proxy_config.h" |
| 22 #include "net/proxy/proxy_resolver.h" | 24 #include "net/proxy/proxy_resolver.h" |
| 23 #include "net/proxy/proxy_script_decider.h" | 25 #include "net/proxy/proxy_script_decider.h" |
| 24 #include "net/proxy/proxy_script_fetcher.h" | 26 #include "net/proxy/proxy_script_fetcher.h" |
| 25 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 29 |
| 28 namespace net { | 30 namespace net { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 190 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 189 | 191 |
| 190 TestCompletionCallback callback; | 192 TestCompletionCallback callback; |
| 191 TestNetLog log; | 193 TestNetLog log; |
| 192 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 194 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 193 EXPECT_EQ(OK, decider.Start( | 195 EXPECT_EQ(OK, decider.Start( |
| 194 config, base::TimeDelta(), true, callback.callback())); | 196 config, base::TimeDelta(), true, callback.callback())); |
| 195 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); | 197 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); |
| 196 | 198 |
| 197 // Check the NetLog was filled correctly. | 199 // Check the NetLog was filled correctly. |
| 198 TestNetLog::CapturedEntryList entries; | 200 CapturedNetLogEntry::List entries; |
| 199 log.GetEntries(&entries); | 201 log.GetEntries(&entries); |
| 200 | 202 |
| 201 EXPECT_EQ(4u, entries.size()); | 203 EXPECT_EQ(4u, entries.size()); |
| 202 EXPECT_TRUE(LogContainsBeginEvent( | 204 EXPECT_TRUE(LogContainsBeginEvent( |
| 203 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 205 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 204 EXPECT_TRUE(LogContainsBeginEvent( | 206 EXPECT_TRUE(LogContainsBeginEvent( |
| 205 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 207 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 206 EXPECT_TRUE(LogContainsEndEvent( | 208 EXPECT_TRUE(LogContainsEndEvent( |
| 207 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 209 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 208 EXPECT_TRUE(LogContainsEndEvent( | 210 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 225 | 227 |
| 226 TestCompletionCallback callback; | 228 TestCompletionCallback callback; |
| 227 TestNetLog log; | 229 TestNetLog log; |
| 228 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 230 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 229 EXPECT_EQ(kFailedDownloading, | 231 EXPECT_EQ(kFailedDownloading, |
| 230 decider.Start(config, base::TimeDelta(), true, | 232 decider.Start(config, base::TimeDelta(), true, |
| 231 callback.callback())); | 233 callback.callback())); |
| 232 EXPECT_EQ(NULL, decider.script_data()); | 234 EXPECT_EQ(NULL, decider.script_data()); |
| 233 | 235 |
| 234 // Check the NetLog was filled correctly. | 236 // Check the NetLog was filled correctly. |
| 235 TestNetLog::CapturedEntryList entries; | 237 CapturedNetLogEntry::List entries; |
| 236 log.GetEntries(&entries); | 238 log.GetEntries(&entries); |
| 237 | 239 |
| 238 EXPECT_EQ(4u, entries.size()); | 240 EXPECT_EQ(4u, entries.size()); |
| 239 EXPECT_TRUE(LogContainsBeginEvent( | 241 EXPECT_TRUE(LogContainsBeginEvent( |
| 240 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 242 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 241 EXPECT_TRUE(LogContainsBeginEvent( | 243 EXPECT_TRUE(LogContainsBeginEvent( |
| 242 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 244 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 243 EXPECT_TRUE(LogContainsEndEvent( | 245 EXPECT_TRUE(LogContainsEndEvent( |
| 244 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 246 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 245 EXPECT_TRUE(LogContainsEndEvent( | 247 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); | 487 EXPECT_EQ(rule.text(), decider.script_data()->utf16()); |
| 486 | 488 |
| 487 // Verify that the effective configuration no longer contains auto detect or | 489 // Verify that the effective configuration no longer contains auto detect or |
| 488 // any of the manual settings. | 490 // any of the manual settings. |
| 489 EXPECT_TRUE(decider.effective_config().Equals( | 491 EXPECT_TRUE(decider.effective_config().Equals( |
| 490 ProxyConfig::CreateFromCustomPacURL(GURL("http://custom/proxy.pac")))); | 492 ProxyConfig::CreateFromCustomPacURL(GURL("http://custom/proxy.pac")))); |
| 491 | 493 |
| 492 // Check the NetLog was filled correctly. | 494 // Check the NetLog was filled correctly. |
| 493 // (Note that various states are repeated since both WPAD and custom | 495 // (Note that various states are repeated since both WPAD and custom |
| 494 // PAC scripts are tried). | 496 // PAC scripts are tried). |
| 495 TestNetLog::CapturedEntryList entries; | 497 CapturedNetLogEntry::List entries; |
| 496 log.GetEntries(&entries); | 498 log.GetEntries(&entries); |
| 497 | 499 |
| 498 EXPECT_EQ(10u, entries.size()); | 500 EXPECT_EQ(10u, entries.size()); |
| 499 EXPECT_TRUE(LogContainsBeginEvent( | 501 EXPECT_TRUE(LogContainsBeginEvent( |
| 500 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 502 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 501 // This is the DHCP phase, which fails fetching rather than parsing, so | 503 // This is the DHCP phase, which fails fetching rather than parsing, so |
| 502 // there is no pair of SET_PAC_SCRIPT events. | 504 // there is no pair of SET_PAC_SCRIPT events. |
| 503 EXPECT_TRUE(LogContainsBeginEvent( | 505 EXPECT_TRUE(LogContainsBeginEvent( |
| 504 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 506 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 505 EXPECT_TRUE(LogContainsEndEvent( | 507 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 TestNetLog log; | 587 TestNetLog log; |
| 586 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 588 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 587 EXPECT_EQ(ERR_IO_PENDING, | 589 EXPECT_EQ(ERR_IO_PENDING, |
| 588 decider.Start(config, base::TimeDelta::FromMilliseconds(1), | 590 decider.Start(config, base::TimeDelta::FromMilliseconds(1), |
| 589 true, callback.callback())); | 591 true, callback.callback())); |
| 590 | 592 |
| 591 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); | 593 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); |
| 592 EXPECT_EQ(NULL, decider.script_data()); | 594 EXPECT_EQ(NULL, decider.script_data()); |
| 593 | 595 |
| 594 // Check the NetLog was filled correctly. | 596 // Check the NetLog was filled correctly. |
| 595 TestNetLog::CapturedEntryList entries; | 597 CapturedNetLogEntry::List entries; |
| 596 log.GetEntries(&entries); | 598 log.GetEntries(&entries); |
| 597 | 599 |
| 598 EXPECT_EQ(6u, entries.size()); | 600 EXPECT_EQ(6u, entries.size()); |
| 599 EXPECT_TRUE(LogContainsBeginEvent( | 601 EXPECT_TRUE(LogContainsBeginEvent( |
| 600 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 602 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 601 EXPECT_TRUE(LogContainsBeginEvent( | 603 EXPECT_TRUE(LogContainsBeginEvent( |
| 602 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); | 604 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); |
| 603 EXPECT_TRUE(LogContainsEndEvent( | 605 EXPECT_TRUE(LogContainsEndEvent( |
| 604 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); | 606 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); |
| 605 EXPECT_TRUE(LogContainsBeginEvent( | 607 EXPECT_TRUE(LogContainsBeginEvent( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 625 | 627 |
| 626 TestCompletionCallback callback; | 628 TestCompletionCallback callback; |
| 627 TestNetLog log; | 629 TestNetLog log; |
| 628 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 630 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 629 EXPECT_EQ(kFailedDownloading, | 631 EXPECT_EQ(kFailedDownloading, |
| 630 decider.Start(config, base::TimeDelta::FromSeconds(-5), | 632 decider.Start(config, base::TimeDelta::FromSeconds(-5), |
| 631 true, callback.callback())); | 633 true, callback.callback())); |
| 632 EXPECT_EQ(NULL, decider.script_data()); | 634 EXPECT_EQ(NULL, decider.script_data()); |
| 633 | 635 |
| 634 // Check the NetLog was filled correctly. | 636 // Check the NetLog was filled correctly. |
| 635 TestNetLog::CapturedEntryList entries; | 637 CapturedNetLogEntry::List entries; |
| 636 log.GetEntries(&entries); | 638 log.GetEntries(&entries); |
| 637 | 639 |
| 638 EXPECT_EQ(4u, entries.size()); | 640 EXPECT_EQ(4u, entries.size()); |
| 639 EXPECT_TRUE(LogContainsBeginEvent( | 641 EXPECT_TRUE(LogContainsBeginEvent( |
| 640 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 642 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 641 EXPECT_TRUE(LogContainsBeginEvent( | 643 EXPECT_TRUE(LogContainsBeginEvent( |
| 642 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 644 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 643 EXPECT_TRUE(LogContainsEndEvent( | 645 EXPECT_TRUE(LogContainsEndEvent( |
| 644 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 646 entries, 2, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| 645 EXPECT_TRUE(LogContainsEndEvent( | 647 EXPECT_TRUE(LogContainsEndEvent( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 780 |
| 779 // Run the message loop to let the DHCP fetch complete and post the results | 781 // 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 | 782 // back. Before the fix linked to above, this would try to invoke on |
| 781 // the callback object provided by ProxyScriptDecider after it was | 783 // the callback object provided by ProxyScriptDecider after it was |
| 782 // no longer valid. | 784 // no longer valid. |
| 783 base::MessageLoop::current()->RunUntilIdle(); | 785 base::MessageLoop::current()->RunUntilIdle(); |
| 784 } | 786 } |
| 785 | 787 |
| 786 } // namespace | 788 } // namespace |
| 787 } // namespace net | 789 } // namespace net |
| OLD | NEW |