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

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: Remote superfluous net:: prefix Created 6 years, 2 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
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | net/proxy/proxy_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 TEST_F(PredictorTest, NoProxyService) {
873 // Don't actually try to resolve names.
874 Predictor::set_max_parallel_resolves(0);
875
876 Predictor testing_master(true, true);
877
878 GURL goog("http://www.google.com:80");
879 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
880 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
881
882 testing_master.Shutdown();
883 }
884
885 TEST_F(PredictorTest, ProxyDefinitelyEnabled) {
886 // Don't actually try to resolve names.
887 Predictor::set_max_parallel_resolves(0);
888
889 Predictor testing_master(true, true);
890
891 net::ProxyConfig config;
892 config.proxy_rules().ParseFromString("http=socks://localhost:12345");
893 testing_master.proxy_service_ = net::ProxyService::CreateFixed(config);
894
895 GURL goog("http://www.google.com:80");
896 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
897
898 // Proxy is definitely in use, so there is no need to pre-resolve the domain.
899 EXPECT_TRUE(testing_master.work_queue_.IsEmpty());
900
901 delete testing_master.proxy_service_;
902 testing_master.Shutdown();
903 }
904
905 TEST_F(PredictorTest, ProxyDefinitelyNotEnabled) {
906 // Don't actually try to resolve names.
907 Predictor::set_max_parallel_resolves(0);
908
909 Predictor testing_master(true, true);
910 net::ProxyConfig config = net::ProxyConfig::CreateDirect();
911 testing_master.proxy_service_ = net::ProxyService::CreateFixed(config);
912
913 GURL goog("http://www.google.com:80");
914 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
915
916 // Proxy is not in use, so the name has been registered for pre-resolve.
917 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
918
919 delete testing_master.proxy_service_;
920 testing_master.Shutdown();
921 }
922
923 TEST_F(PredictorTest, ProxyMaybeEnabled) {
924 // Don't actually try to resolve names.
925 Predictor::set_max_parallel_resolves(0);
926
927 Predictor testing_master(true, true);
928 net::ProxyConfig config = net::ProxyConfig::CreateFromCustomPacURL(GURL(
929 "http://foopy/proxy.pac"));
930 testing_master.proxy_service_ = net::ProxyService::CreateFixed(config);
931
932 GURL goog("http://www.google.com:80");
933 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED);
934
935 // Proxy may not be in use (the PAC script has not yet been evaluated), so the
936 // name has been registered for pre-resolve.
937 EXPECT_FALSE(testing_master.work_queue_.IsEmpty());
938
939 delete testing_master.proxy_service_;
940 testing_master.Shutdown();
941 }
942
868 } // namespace chrome_browser_net 943 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | net/proxy/proxy_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698