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

Side by Side Diff: net/proxy/proxy_resolver_perftest.cc

Issue 149525: Remove the concept of threading from ProxyService, and move it into the Proxy... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add missing header for mac Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_resolver_mac.cc ('k') | net/proxy/proxy_resolver_v8.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/perftimer.h" 5 #include "base/perftimer.h"
6 #include "net/base/mock_host_resolver.h" 6 #include "net/base/mock_host_resolver.h"
7 #include "net/proxy/proxy_resolver_v8.h" 7 #include "net/proxy/proxy_resolver_v8.h"
8 #include "net/url_request/url_request_unittest.h" 8 #include "net/url_request/url_request_unittest.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 RunTest(test_data.pac_name, 85 RunTest(test_data.pac_name,
86 test_data.queries, 86 test_data.queries,
87 test_data.NumQueries()); 87 test_data.NumQueries());
88 } 88 }
89 } 89 }
90 90
91 private: 91 private:
92 void RunTest(const std::string& script_name, 92 void RunTest(const std::string& script_name,
93 const PacQuery* queries, 93 const PacQuery* queries,
94 int queries_len) { 94 int queries_len) {
95 GURL pac_url; 95 if (!resolver_->expects_pac_bytes()) {
96
97 if (resolver_->does_fetch()) {
98 InitHttpServer(); 96 InitHttpServer();
99 pac_url = server_->TestServerPage(std::string("files/") + script_name); 97 GURL pac_url =
98 server_->TestServerPage(std::string("files/") + script_name);
99 resolver_->SetPacScriptByUrl(pac_url);
100 } else { 100 } else {
101 LoadPacScriptIntoResolver(script_name); 101 LoadPacScriptIntoResolver(script_name);
102 } 102 }
103 103
104 // Do a query to warm things up. In the case of internal-fetch proxy 104 // Do a query to warm things up. In the case of internal-fetch proxy
105 // resolvers, the first resolve will be slow since it has to download 105 // resolvers, the first resolve will be slow since it has to download
106 // the PAC script. 106 // the PAC script.
107 { 107 {
108 net::ProxyInfo proxy_info; 108 net::ProxyInfo proxy_info;
109 int result = resolver_->GetProxyForURL( 109 int result = resolver_->GetProxyForURL(
110 GURL("http://www.warmup.com"), pac_url, &proxy_info); 110 GURL("http://www.warmup.com"), &proxy_info, NULL, NULL);
111 ASSERT_EQ(net::OK, result); 111 ASSERT_EQ(net::OK, result);
112 } 112 }
113 113
114 // Start the perf timer. 114 // Start the perf timer.
115 std::string perf_test_name = resolver_name_ + "_" + script_name; 115 std::string perf_test_name = resolver_name_ + "_" + script_name;
116 PerfTimeLogger timer(perf_test_name.c_str()); 116 PerfTimeLogger timer(perf_test_name.c_str());
117 117
118 for (int i = 0; i < kNumIterations; ++i) { 118 for (int i = 0; i < kNumIterations; ++i) {
119 // Round-robin between URLs to resolve. 119 // Round-robin between URLs to resolve.
120 const PacQuery& query = queries[i % queries_len]; 120 const PacQuery& query = queries[i % queries_len];
121 121
122 // Resolve. 122 // Resolve.
123 net::ProxyInfo proxy_info; 123 net::ProxyInfo proxy_info;
124 int result = resolver_->GetProxyForURL(GURL(query.query_url), 124 int result = resolver_->GetProxyForURL(GURL(query.query_url),
125 pac_url, 125 &proxy_info, NULL, NULL);
126 &proxy_info);
127 126
128 // Check that the result was correct. Note that ToPacString() and 127 // Check that the result was correct. Note that ToPacString() and
129 // ASSERT_EQ() are fast, so they won't skew the results. 128 // ASSERT_EQ() are fast, so they won't skew the results.
130 ASSERT_EQ(net::OK, result); 129 ASSERT_EQ(net::OK, result);
131 ASSERT_EQ(query.expected_result, proxy_info.ToPacString()); 130 ASSERT_EQ(query.expected_result, proxy_info.ToPacString());
132 } 131 }
133 132
134 // Print how long the test ran for. 133 // Print how long the test ran for.
135 timer.Done(); 134 timer.Done();
136 } 135 }
137 136
138 // Lazily startup an HTTP server (to serve the PAC script). 137 // Lazily startup an HTTP server (to serve the PAC script).
139 void InitHttpServer() { 138 void InitHttpServer() {
140 DCHECK(resolver_->does_fetch()); 139 DCHECK(!resolver_->expects_pac_bytes());
141 if (!server_) { 140 if (!server_) {
142 server_ = HTTPTestServer::CreateServer( 141 server_ = HTTPTestServer::CreateServer(
143 L"net/data/proxy_resolver_perftest", NULL); 142 L"net/data/proxy_resolver_perftest", NULL);
144 } 143 }
145 ASSERT_TRUE(server_.get() != NULL); 144 ASSERT_TRUE(server_.get() != NULL);
146 } 145 }
147 146
148 // Read the PAC script from disk and initialize the proxy resolver with it. 147 // Read the PAC script from disk and initialize the proxy resolver with it.
149 void LoadPacScriptIntoResolver(const std::string& script_name) { 148 void LoadPacScriptIntoResolver(const std::string& script_name) {
150 FilePath path; 149 FilePath path;
151 PathService::Get(base::DIR_SOURCE_ROOT, &path); 150 PathService::Get(base::DIR_SOURCE_ROOT, &path);
152 path = path.AppendASCII("net"); 151 path = path.AppendASCII("net");
153 path = path.AppendASCII("data"); 152 path = path.AppendASCII("data");
154 path = path.AppendASCII("proxy_resolver_perftest"); 153 path = path.AppendASCII("proxy_resolver_perftest");
155 path = path.AppendASCII(script_name); 154 path = path.AppendASCII(script_name);
156 155
157 // Try to read the file from disk. 156 // Try to read the file from disk.
158 std::string file_contents; 157 std::string file_contents;
159 bool ok = file_util::ReadFileToString(path, &file_contents); 158 bool ok = file_util::ReadFileToString(path, &file_contents);
160 159
161 // If we can't load the file from disk, something is misconfigured. 160 // If we can't load the file from disk, something is misconfigured.
162 LOG_IF(ERROR, !ok) << "Failed to read file: " << path.value(); 161 LOG_IF(ERROR, !ok) << "Failed to read file: " << path.value();
163 ASSERT_TRUE(ok); 162 ASSERT_TRUE(ok);
164 163
165 // Load the PAC script into the ProxyResolver. 164 // Load the PAC script into the ProxyResolver.
166 resolver_->SetPacScript(file_contents); 165 resolver_->SetPacScriptByData(file_contents);
167 } 166 }
168 167
169 net::ProxyResolver* resolver_; 168 net::ProxyResolver* resolver_;
170 std::string resolver_name_; 169 std::string resolver_name_;
171 scoped_refptr<HTTPTestServer> server_; 170 scoped_refptr<HTTPTestServer> server_;
172 }; 171 };
173 172
174 #if defined(OS_WIN) 173 #if defined(OS_WIN)
175 TEST(ProxyResolverPerfTest, ProxyResolverWinHttp) { 174 TEST(ProxyResolverPerfTest, ProxyResolverWinHttp) {
176 net::ProxyResolverWinHttp resolver; 175 net::ProxyResolverWinHttp resolver;
(...skipping 10 matching lines...) Expand all
187 186
188 TEST(ProxyResolverPerfTest, ProxyResolverV8) { 187 TEST(ProxyResolverPerfTest, ProxyResolverV8) {
189 net::ProxyResolverV8::JSBindings* js_bindings = 188 net::ProxyResolverV8::JSBindings* js_bindings =
190 net::ProxyResolverV8::CreateDefaultBindings( 189 net::ProxyResolverV8::CreateDefaultBindings(
191 new net::MockHostResolver, NULL); 190 new net::MockHostResolver, NULL);
192 191
193 net::ProxyResolverV8 resolver(js_bindings); 192 net::ProxyResolverV8 resolver(js_bindings);
194 PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8"); 193 PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8");
195 runner.RunAllTests(); 194 runner.RunAllTests();
196 } 195 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_mac.cc ('k') | net/proxy/proxy_resolver_v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698