| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/perftimer.h" | 9 #include "base/perftimer.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 void RunTest(const std::string& script_name, | 115 void RunTest(const std::string& script_name, |
| 116 const PacQuery* queries, | 116 const PacQuery* queries, |
| 117 int queries_len) { | 117 int queries_len) { |
| 118 if (!resolver_->expects_pac_bytes()) { | 118 if (!resolver_->expects_pac_bytes()) { |
| 119 GURL pac_url = | 119 GURL pac_url = |
| 120 test_server_.GetURL(std::string("files/") + script_name); | 120 test_server_.GetURL(std::string("files/") + script_name); |
| 121 int rv = resolver_->SetPacScript( | 121 int rv = resolver_->SetPacScript( |
| 122 net::ProxyResolverScriptData::FromURL(pac_url), NULL); | 122 net::ProxyResolverScriptData::FromURL(pac_url), |
| 123 net::CompletionCallback()); |
| 123 EXPECT_EQ(net::OK, rv); | 124 EXPECT_EQ(net::OK, rv); |
| 124 } else { | 125 } else { |
| 125 LoadPacScriptIntoResolver(script_name); | 126 LoadPacScriptIntoResolver(script_name); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // Do a query to warm things up. In the case of internal-fetch proxy | 129 // Do a query to warm things up. In the case of internal-fetch proxy |
| 129 // resolvers, the first resolve will be slow since it has to download | 130 // resolvers, the first resolve will be slow since it has to download |
| 130 // the PAC script. | 131 // the PAC script. |
| 131 { | 132 { |
| 132 net::ProxyInfo proxy_info; | 133 net::ProxyInfo proxy_info; |
| 133 int result = resolver_->GetProxyForURL( | 134 int result = resolver_->GetProxyForURL( |
| 134 GURL("http://www.warmup.com"), &proxy_info, NULL, NULL, | 135 GURL("http://www.warmup.com"), &proxy_info, net::CompletionCallback(), |
| 135 net::BoundNetLog()); | 136 NULL, net::BoundNetLog()); |
| 136 ASSERT_EQ(net::OK, result); | 137 ASSERT_EQ(net::OK, result); |
| 137 } | 138 } |
| 138 | 139 |
| 139 // Start the perf timer. | 140 // Start the perf timer. |
| 140 std::string perf_test_name = resolver_name_ + "_" + script_name; | 141 std::string perf_test_name = resolver_name_ + "_" + script_name; |
| 141 PerfTimeLogger timer(perf_test_name.c_str()); | 142 PerfTimeLogger timer(perf_test_name.c_str()); |
| 142 | 143 |
| 143 for (int i = 0; i < kNumIterations; ++i) { | 144 for (int i = 0; i < kNumIterations; ++i) { |
| 144 // Round-robin between URLs to resolve. | 145 // Round-robin between URLs to resolve. |
| 145 const PacQuery& query = queries[i % queries_len]; | 146 const PacQuery& query = queries[i % queries_len]; |
| 146 | 147 |
| 147 // Resolve. | 148 // Resolve. |
| 148 net::ProxyInfo proxy_info; | 149 net::ProxyInfo proxy_info; |
| 149 int result = resolver_->GetProxyForURL(GURL(query.query_url), | 150 int result = resolver_->GetProxyForURL( |
| 150 &proxy_info, NULL, NULL, | 151 GURL(query.query_url), &proxy_info, net::CompletionCallback(), NULL, |
| 151 net::BoundNetLog()); | 152 net::BoundNetLog()); |
| 152 | 153 |
| 153 // Check that the result was correct. Note that ToPacString() and | 154 // Check that the result was correct. Note that ToPacString() and |
| 154 // ASSERT_EQ() are fast, so they won't skew the results. | 155 // ASSERT_EQ() are fast, so they won't skew the results. |
| 155 ASSERT_EQ(net::OK, result); | 156 ASSERT_EQ(net::OK, result); |
| 156 ASSERT_EQ(query.expected_result, proxy_info.ToPacString()); | 157 ASSERT_EQ(query.expected_result, proxy_info.ToPacString()); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Print how long the test ran for. | 160 // Print how long the test ran for. |
| 160 timer.Done(); | 161 timer.Done(); |
| 161 } | 162 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 // Try to read the file from disk. | 173 // Try to read the file from disk. |
| 173 std::string file_contents; | 174 std::string file_contents; |
| 174 bool ok = file_util::ReadFileToString(path, &file_contents); | 175 bool ok = file_util::ReadFileToString(path, &file_contents); |
| 175 | 176 |
| 176 // If we can't load the file from disk, something is misconfigured. | 177 // If we can't load the file from disk, something is misconfigured. |
| 177 LOG_IF(ERROR, !ok) << "Failed to read file: " << path.value(); | 178 LOG_IF(ERROR, !ok) << "Failed to read file: " << path.value(); |
| 178 ASSERT_TRUE(ok); | 179 ASSERT_TRUE(ok); |
| 179 | 180 |
| 180 // Load the PAC script into the ProxyResolver. | 181 // Load the PAC script into the ProxyResolver. |
| 181 int rv = resolver_->SetPacScript( | 182 int rv = resolver_->SetPacScript( |
| 182 net::ProxyResolverScriptData::FromUTF8(file_contents), NULL); | 183 net::ProxyResolverScriptData::FromUTF8(file_contents), |
| 184 net::CompletionCallback()); |
| 183 EXPECT_EQ(net::OK, rv); | 185 EXPECT_EQ(net::OK, rv); |
| 184 } | 186 } |
| 185 | 187 |
| 186 net::ProxyResolver* resolver_; | 188 net::ProxyResolver* resolver_; |
| 187 std::string resolver_name_; | 189 std::string resolver_name_; |
| 188 net::TestServer test_server_; | 190 net::TestServer test_server_; |
| 189 }; | 191 }; |
| 190 | 192 |
| 191 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
| 192 TEST(ProxyResolverPerfTest, ProxyResolverWinHttp) { | 194 TEST(ProxyResolverPerfTest, ProxyResolverWinHttp) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 205 TEST(ProxyResolverPerfTest, ProxyResolverV8) { | 207 TEST(ProxyResolverPerfTest, ProxyResolverV8) { |
| 206 net::ProxyResolverJSBindings* js_bindings = | 208 net::ProxyResolverJSBindings* js_bindings = |
| 207 net::ProxyResolverJSBindings::CreateDefault( | 209 net::ProxyResolverJSBindings::CreateDefault( |
| 208 new MockSyncHostResolver, NULL, NULL); | 210 new MockSyncHostResolver, NULL, NULL); |
| 209 | 211 |
| 210 net::ProxyResolverV8 resolver(js_bindings); | 212 net::ProxyResolverV8 resolver(js_bindings); |
| 211 PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8"); | 213 PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8"); |
| 212 runner.RunAllTests(); | 214 runner.RunAllTests(); |
| 213 } | 215 } |
| 214 | 216 |
| OLD | NEW |