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

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: Undo no-longer-needed virtual marking 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 }
883
884 virtual int ResolveProxy(const GURL& url,
885 int load_flags,
886 net::ProxyInfo* result,
887 const net::CompletionCallback& callback,
888 PacRequest** pac_request,
889 net::NetworkDelegate* network_delegate,
890 const net::BoundNetLog& net_log) OVERRIDE {
891 EXPECT_TRUE(callback.is_null());
892 if (resolve_code_ == net::OK) {
893 *result = proxy_info_;
894 }
895
896 return resolve_code_;
897 }
898
899 int resolve_code_;
900 const net::ProxyInfo& proxy_info_;
901 };
902
903 TEST_F(PredictorTest, NoProxyService) {
904 // Don't actually try to resolve names.
905 Predictor::set_max_parallel_resolves(0);
906
907 Predictor testing_master(true, true);
908
909 GURL goog("http://www.google.com:80");
910 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
911 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
912
913 testing_master.Shutdown();
914 }
915
916 TEST_F(PredictorTest, ProxyDefinitelyEnabled) {
917 // Don't actually try to resolve names.
918 Predictor::set_max_parallel_resolves(0);
919
920 Predictor testing_master(true, true);
921 net::ProxyInfo info;
922 info.UseNamedProxy("socks://localhost:12345");
923 testing_master.proxy_service_ = new TestProxyService(net::OK, info);
924
925 GURL goog("http://www.google.com:80");
926 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
927 EXPECT_TRUE(testing_master.work_queue_.IsEmpty());
928
929 delete testing_master.proxy_service_;
930 testing_master.Shutdown();
931 }
932
933 TEST_F(PredictorTest, ProxyDefinitelyNotEnabled) {
934 // Don't actually try to resolve names.
935 Predictor::set_max_parallel_resolves(0);
936
937 Predictor testing_master(true, true);
938 net::ProxyInfo info;
939 info.UseDirect();
940 testing_master.proxy_service_ = new TestProxyService(net::OK, info);
941
942 GURL goog("http://www.google.com:80");
943 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
944 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
945
946 delete testing_master.proxy_service_;
947 testing_master.Shutdown();
948 }
949
950 TEST_F(PredictorTest, ProxyMaybeEnabled) {
951 // Don't actually try to resolve names.
952 Predictor::set_max_parallel_resolves(0);
953
954 Predictor testing_master(true, true);
955 net::ProxyInfo info;
956 testing_master.proxy_service_ =
957 new TestProxyService(net::ERR_IO_PENDING, info);
958
959 GURL goog("http://www.google.com:80");
960 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
961 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
962
963 delete testing_master.proxy_service_;
964 testing_master.Shutdown();
965 }
966
868 } // namespace chrome_browser_net 967 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698