| Index: chrome/browser/net/predictor_unittest.cc
|
| diff --git a/chrome/browser/net/predictor_unittest.cc b/chrome/browser/net/predictor_unittest.cc
|
| index 4bdb21d710c4c082b9d1dab71f771e718f9f501a..4dbe029885710062e9974ae1434fac073cfff4da 100644
|
| --- a/chrome/browser/net/predictor_unittest.cc
|
| +++ b/chrome/browser/net/predictor_unittest.cc
|
| @@ -19,9 +19,13 @@
|
| #include "chrome/common/net/predictor_common.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| #include "net/base/address_list.h"
|
| +#include "net/base/load_flags.h"
|
| +#include "net/base/net_errors.h"
|
| #include "net/base/winsock_init.h"
|
| #include "net/dns/mock_host_resolver.h"
|
| #include "net/http/transport_security_state.h"
|
| +#include "net/proxy/proxy_config_service_fixed.h"
|
| +#include "net/proxy/proxy_service.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -865,4 +869,114 @@ TEST_F(PredictorTest, TestSimplePreconnectAdvisor) {
|
|
|
| #endif // defined(OS_ANDROID) || defined(OS_IOS)
|
|
|
| +net::ProxyService::PacRequest* FAKE_PAC_REQUEST_ADDRESS =
|
| + reinterpret_cast<net::ProxyService::PacRequest*>(123454321);
|
| +
|
| +class TestProxyService : public net::ProxyService {
|
| + public:
|
| + TestProxyService(int resolve_code, const net::ProxyInfo& proxy_info)
|
| + : ProxyService(new net::ProxyConfigServiceFixed(net::ProxyConfig()),
|
| + NULL, NULL),
|
| + resolve_code_(resolve_code),
|
| + proxy_info_(proxy_info),
|
| + pac_request_is_outstanding_(false) {
|
| + }
|
| +
|
| + virtual ~TestProxyService() {
|
| + EXPECT_FALSE(pac_request_is_outstanding_);
|
| + }
|
| +
|
| + virtual int ResolveProxy(const GURL& url,
|
| + int load_flags,
|
| + net::ProxyInfo* result,
|
| + const net::CompletionCallback& callback,
|
| + PacRequest** pac_request,
|
| + net::NetworkDelegate* network_delegate,
|
| + const net::BoundNetLog& net_log) OVERRIDE {
|
| + *pac_request = FAKE_PAC_REQUEST_ADDRESS;
|
| + if (resolve_code_ == net::LOAD_NORMAL) {
|
| + *result = proxy_info_;
|
| + callback.Run(resolve_code_);
|
| + } else {
|
| + pac_request_is_outstanding_ = true;
|
| + }
|
| +
|
| + return resolve_code_;
|
| + }
|
| +
|
| + virtual void CancelPacRequest(PacRequest* req) OVERRIDE {
|
| + DCHECK_EQ(FAKE_PAC_REQUEST_ADDRESS, req);
|
| + DCHECK(pac_request_is_outstanding_);
|
| + pac_request_is_outstanding_ = false;
|
| + }
|
| +
|
| + int resolve_code_;
|
| + const net::ProxyInfo& proxy_info_;
|
| + bool pac_request_is_outstanding_;
|
| +};
|
| +
|
| +TEST_F(PredictorTest, NoProxyService) {
|
| + // Don't actually try to resolve names.
|
| + Predictor::set_max_parallel_resolves(0);
|
| +
|
| + Predictor testing_master(true, true);
|
| +
|
| + GURL goog("http://www.google.com:80");
|
| + testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
|
| + EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
|
| +
|
| + testing_master.Shutdown();
|
| +}
|
| +
|
| +TEST_F(PredictorTest, ProxyDefinitelyEnabled) {
|
| + // Don't actually try to resolve names.
|
| + Predictor::set_max_parallel_resolves(0);
|
| +
|
| + Predictor testing_master(true, true);
|
| + net::ProxyInfo info;
|
| + info.UseNamedProxy("socks://localhost:12345");
|
| + testing_master.proxy_service_ = new TestProxyService(net::LOAD_NORMAL, info);
|
| +
|
| + GURL goog("http://www.google.com:80");
|
| + testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
|
| + EXPECT_TRUE(testing_master.work_queue_.IsEmpty());
|
| +
|
| + delete testing_master.proxy_service_;
|
| + testing_master.Shutdown();
|
| +}
|
| +
|
| +TEST_F(PredictorTest, ProxyDefinitelyNotEnabled) {
|
| + // Don't actually try to resolve names.
|
| + Predictor::set_max_parallel_resolves(0);
|
| +
|
| + Predictor testing_master(true, true);
|
| + net::ProxyInfo info;
|
| + info.UseDirect();
|
| + testing_master.proxy_service_ = new TestProxyService(net::LOAD_NORMAL, info);
|
| +
|
| + GURL goog("http://www.google.com:80");
|
| + testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
|
| + EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
|
| +
|
| + delete testing_master.proxy_service_;
|
| + testing_master.Shutdown();
|
| +}
|
| +
|
| +TEST_F(PredictorTest, ProxyMaybeEnabled) {
|
| + // Don't actually try to resolve names.
|
| + Predictor::set_max_parallel_resolves(0);
|
| +
|
| + Predictor testing_master(true, true);
|
| + net::ProxyInfo info;
|
| + testing_master.proxy_service_ =
|
| + new TestProxyService(net::ERR_IO_PENDING, info);
|
| +
|
| + GURL goog("http://www.google.com:80");
|
| + testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
|
| + EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
|
| +
|
| + delete testing_master.proxy_service_;
|
| + testing_master.Shutdown();
|
| +}
|
| +
|
| } // namespace chrome_browser_net
|
|
|