Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: chrome/browser/net/predictor_unittest.cc

Issue 545633002: Don't preresolve DNS if a fixed proxy configuration is in place. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <time.h> 5 #include <time.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/net/predictor.h" 16 #include "chrome/browser/net/predictor.h"
17 #include "chrome/browser/net/spdyproxy/proxy_advisor.h" 17 #include "chrome/browser/net/spdyproxy/proxy_advisor.h"
18 #include "chrome/browser/net/url_info.h" 18 #include "chrome/browser/net/url_info.h"
19 #include "chrome/common/net/predictor_common.h" 19 #include "chrome/common/net/predictor_common.h"
20 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
21 #include "net/base/address_list.h" 21 #include "net/base/address_list.h"
22 #include "net/base/load_flags.h"
23 #include "net/base/net_errors.h"
22 #include "net/base/winsock_init.h" 24 #include "net/base/winsock_init.h"
23 #include "net/dns/mock_host_resolver.h" 25 #include "net/dns/mock_host_resolver.h"
24 #include "net/http/transport_security_state.h" 26 #include "net/http/transport_security_state.h"
27 #include "net/proxy/proxy_config_service_fixed.h"
28 #include "net/proxy/proxy_service.h"
25 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
27 31
28 using base::Time; 32 using base::Time;
29 using base::TimeDelta; 33 using base::TimeDelta;
30 using content::BrowserThread; 34 using content::BrowserThread;
31 35
32 namespace chrome_browser_net { 36 namespace chrome_browser_net {
33 37
34 class WaitForResolutionHelper; 38 class WaitForResolutionHelper;
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 testing_master.PreconnectUrl(goog, goog, UrlInfo::OMNIBOX_MOTIVATED, 2); 862 testing_master.PreconnectUrl(goog, goog, UrlInfo::OMNIBOX_MOTIVATED, 2);
859 863
860 EXPECT_EQ(advisor->would_proxy_count_, 0); 864 EXPECT_EQ(advisor->would_proxy_count_, 0);
861 EXPECT_EQ(advisor->advise_count_, 1); 865 EXPECT_EQ(advisor->advise_count_, 1);
862 866
863 testing_master.Shutdown(); 867 testing_master.Shutdown();
864 } 868 }
865 869
866 #endif // defined(OS_ANDROID) || defined(OS_IOS) 870 #endif // defined(OS_ANDROID) || defined(OS_IOS)
867 871
872 net::ProxyService::PacRequest* FAKE_PAC_REQUEST_ADDRESS =
873 reinterpret_cast<net::ProxyService::PacRequest*>(123454321);
874
875 class TestProxyService : public net::ProxyService {
876 public:
877 TestProxyService(int resolve_code, const net::ProxyInfo& proxy_info)
878 : ProxyService(new net::ProxyConfigServiceFixed(net::ProxyConfig()),
879 NULL, NULL),
880 resolve_code_(resolve_code),
881 proxy_info_(proxy_info),
882 pac_request_is_outstanding_(false) {
883 }
884
885 virtual ~TestProxyService() {
886 EXPECT_FALSE(pac_request_is_outstanding_);
887 }
888
889 virtual int ResolveProxy(const GURL& url,
890 int load_flags,
891 net::ProxyInfo* result,
892 const net::CompletionCallback& callback,
893 PacRequest** pac_request,
894 net::NetworkDelegate* network_delegate,
895 const net::BoundNetLog& net_log) OVERRIDE {
896 *pac_request = FAKE_PAC_REQUEST_ADDRESS;
897 if (resolve_code_ == net::LOAD_NORMAL) {
898 *result = proxy_info_;
899 callback.Run(resolve_code_);
900 } else {
901 pac_request_is_outstanding_ = true;
902 }
903
904 return resolve_code_;
905 }
906
907 virtual void CancelPacRequest(PacRequest* req) OVERRIDE {
908 DCHECK_EQ(FAKE_PAC_REQUEST_ADDRESS, req);
909 DCHECK(pac_request_is_outstanding_);
910 pac_request_is_outstanding_ = false;
911 }
912
913 int resolve_code_;
914 const net::ProxyInfo& proxy_info_;
915 bool pac_request_is_outstanding_;
916 };
917
918 TEST_F(PredictorTest, NoProxyService) {
919 // Don't actually try to resolve names.
920 Predictor::set_max_parallel_resolves(0);
921
922 Predictor testing_master(true, true);
923
924 GURL goog("http://www.google.com:80");
925 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
926 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
927
928 testing_master.Shutdown();
929 }
930
931 TEST_F(PredictorTest, ProxyDefinitelyEnabled) {
932 // Don't actually try to resolve names.
933 Predictor::set_max_parallel_resolves(0);
934
935 Predictor testing_master(true, true);
936 net::ProxyInfo info;
937 info.UseNamedProxy("socks://localhost:12345");
938 testing_master.proxy_service_ = new TestProxyService(net::LOAD_NORMAL, info);
939
940 GURL goog("http://www.google.com:80");
941 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
942 EXPECT_TRUE(testing_master.work_queue_.IsEmpty());
943
944 delete testing_master.proxy_service_;
945 testing_master.Shutdown();
946 }
947
948 TEST_F(PredictorTest, ProxyDefinitelyNotEnabled) {
949 // Don't actually try to resolve names.
950 Predictor::set_max_parallel_resolves(0);
951
952 Predictor testing_master(true, true);
953 net::ProxyInfo info;
954 info.UseDirect();
955 testing_master.proxy_service_ = new TestProxyService(net::LOAD_NORMAL, info);
956
957 GURL goog("http://www.google.com:80");
958 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
959 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
960
961 delete testing_master.proxy_service_;
962 testing_master.Shutdown();
963 }
964
965 TEST_F(PredictorTest, ProxyMaybeEnabled) {
966 // Don't actually try to resolve names.
967 Predictor::set_max_parallel_resolves(0);
968
969 Predictor testing_master(true, true);
970 net::ProxyInfo info;
971 testing_master.proxy_service_ =
972 new TestProxyService(net::ERR_IO_PENDING, info);
973
974 GURL goog("http://www.google.com:80");
975 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
976 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
977
978 delete testing_master.proxy_service_;
979 testing_master.Shutdown();
980 }
981
868 } // namespace chrome_browser_net 982 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698