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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 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
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 <utility> 5 #include <utility>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/test/perf_time_logger.h" 14 #include "base/test/perf_time_logger.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/dns/mock_host_resolver.h" 16 #include "net/dns/mock_host_resolver.h"
17 #include "net/proxy/proxy_info.h" 17 #include "net/proxy/proxy_info.h"
18 #include "net/proxy/proxy_resolver.h" 18 #include "net/proxy/proxy_resolver.h"
19 #include "net/proxy/proxy_resolver_factory.h" 19 #include "net/proxy/proxy_resolver_factory.h"
20 #include "net/proxy/proxy_resolver_v8.h" 20 #include "net/proxy/proxy_resolver_v8.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
22 #include "net/test/gtest_util.h"
23 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 #if defined(OS_WIN) 26 #if defined(OS_WIN)
25 #include "net/proxy/proxy_resolver_winhttp.h" 27 #include "net/proxy/proxy_resolver_winhttp.h"
26 #elif defined(OS_MACOSX) 28 #elif defined(OS_MACOSX)
27 #include "net/proxy/proxy_resolver_mac.h" 29 #include "net/proxy/proxy_resolver_mac.h"
28 #endif 30 #endif
29 31
32 using net::test::IsOk;
33
30 namespace net { 34 namespace net {
31 35
32 namespace { 36 namespace {
33 37
34 // This class holds the URL to use for resolving, and the expected result. 38 // This class holds the URL to use for resolving, and the expected result.
35 // We track the expected result in order to make sure the performance 39 // We track the expected result in order to make sure the performance
36 // test is actually resolving URLs properly, otherwise the perf numbers 40 // test is actually resolving URLs properly, otherwise the perf numbers
37 // are meaningless :-) 41 // are meaningless :-)
38 struct PacQuery { 42 struct PacQuery {
39 const char* query_url; 43 const char* query_url;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 private: 115 private:
112 void RunTest(const std::string& script_name, 116 void RunTest(const std::string& script_name,
113 const PacQuery* queries, 117 const PacQuery* queries,
114 int queries_len) { 118 int queries_len) {
115 std::unique_ptr<ProxyResolver> resolver; 119 std::unique_ptr<ProxyResolver> resolver;
116 if (!factory_->expects_pac_bytes()) { 120 if (!factory_->expects_pac_bytes()) {
117 GURL pac_url = test_server_.GetURL(std::string("/") + script_name); 121 GURL pac_url = test_server_.GetURL(std::string("/") + script_name);
118 int rv = factory_->CreateProxyResolver( 122 int rv = factory_->CreateProxyResolver(
119 ProxyResolverScriptData::FromURL(pac_url), &resolver, 123 ProxyResolverScriptData::FromURL(pac_url), &resolver,
120 CompletionCallback(), nullptr); 124 CompletionCallback(), nullptr);
121 EXPECT_EQ(OK, rv); 125 EXPECT_THAT(rv, IsOk());
122 } else { 126 } else {
123 resolver = LoadPacScriptAndCreateResolver(script_name); 127 resolver = LoadPacScriptAndCreateResolver(script_name);
124 } 128 }
125 ASSERT_TRUE(resolver); 129 ASSERT_TRUE(resolver);
126 130
127 // Do a query to warm things up. In the case of internal-fetch proxy 131 // Do a query to warm things up. In the case of internal-fetch proxy
128 // resolvers, the first resolve will be slow since it has to download 132 // resolvers, the first resolve will be slow since it has to download
129 // the PAC script. 133 // the PAC script.
130 { 134 {
131 ProxyInfo proxy_info; 135 ProxyInfo proxy_info;
132 int result = 136 int result =
133 resolver->GetProxyForURL(GURL("http://www.warmup.com"), &proxy_info, 137 resolver->GetProxyForURL(GURL("http://www.warmup.com"), &proxy_info,
134 CompletionCallback(), NULL, BoundNetLog()); 138 CompletionCallback(), NULL, BoundNetLog());
135 ASSERT_EQ(OK, result); 139 ASSERT_THAT(result, IsOk());
136 } 140 }
137 141
138 // Start the perf timer. 142 // Start the perf timer.
139 std::string perf_test_name = resolver_name_ + "_" + script_name; 143 std::string perf_test_name = resolver_name_ + "_" + script_name;
140 base::PerfTimeLogger timer(perf_test_name.c_str()); 144 base::PerfTimeLogger timer(perf_test_name.c_str());
141 145
142 for (int i = 0; i < kNumIterations; ++i) { 146 for (int i = 0; i < kNumIterations; ++i) {
143 // Round-robin between URLs to resolve. 147 // Round-robin between URLs to resolve.
144 const PacQuery& query = queries[i % queries_len]; 148 const PacQuery& query = queries[i % queries_len];
145 149
146 // Resolve. 150 // Resolve.
147 ProxyInfo proxy_info; 151 ProxyInfo proxy_info;
148 int result = 152 int result =
149 resolver->GetProxyForURL(GURL(query.query_url), &proxy_info, 153 resolver->GetProxyForURL(GURL(query.query_url), &proxy_info,
150 CompletionCallback(), NULL, BoundNetLog()); 154 CompletionCallback(), NULL, BoundNetLog());
151 155
152 // Check that the result was correct. Note that ToPacString() and 156 // Check that the result was correct. Note that ToPacString() and
153 // ASSERT_EQ() are fast, so they won't skew the results. 157 // ASSERT_EQ() are fast, so they won't skew the results.
154 ASSERT_EQ(OK, result); 158 ASSERT_THAT(result, IsOk());
155 ASSERT_EQ(query.expected_result, proxy_info.ToPacString()); 159 ASSERT_EQ(query.expected_result, proxy_info.ToPacString());
156 } 160 }
157 161
158 // Print how long the test ran for. 162 // Print how long the test ran for.
159 timer.Done(); 163 timer.Done();
160 } 164 }
161 165
162 // Read the PAC script from disk and initialize the proxy resolver with it. 166 // Read the PAC script from disk and initialize the proxy resolver with it.
163 std::unique_ptr<ProxyResolver> LoadPacScriptAndCreateResolver( 167 std::unique_ptr<ProxyResolver> LoadPacScriptAndCreateResolver(
164 const std::string& script_name) { 168 const std::string& script_name) {
(...skipping 11 matching lines...) Expand all
176 // If we can't load the file from disk, something is misconfigured. 180 // If we can't load the file from disk, something is misconfigured.
177 LOG_IF(ERROR, !ok) << "Failed to read file: " << path.value(); 181 LOG_IF(ERROR, !ok) << "Failed to read file: " << path.value();
178 if (!ok) 182 if (!ok)
179 return nullptr; 183 return nullptr;
180 184
181 // Load the PAC script into the ProxyResolver. 185 // Load the PAC script into the ProxyResolver.
182 std::unique_ptr<ProxyResolver> resolver; 186 std::unique_ptr<ProxyResolver> resolver;
183 int rv = factory_->CreateProxyResolver( 187 int rv = factory_->CreateProxyResolver(
184 ProxyResolverScriptData::FromUTF8(file_contents), &resolver, 188 ProxyResolverScriptData::FromUTF8(file_contents), &resolver,
185 CompletionCallback(), nullptr); 189 CompletionCallback(), nullptr);
186 EXPECT_EQ(OK, rv); 190 EXPECT_THAT(rv, IsOk());
187 return resolver; 191 return resolver;
188 } 192 }
189 193
190 ProxyResolverFactory* factory_; 194 ProxyResolverFactory* factory_;
191 std::string resolver_name_; 195 std::string resolver_name_;
192 EmbeddedTestServer test_server_; 196 EmbeddedTestServer test_server_;
193 }; 197 };
194 198
195 #if defined(OS_WIN) 199 #if defined(OS_WIN)
196 TEST(ProxyResolverPerfTest, ProxyResolverWinHttp) { 200 TEST(ProxyResolverPerfTest, ProxyResolverWinHttp) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 TEST(ProxyResolverPerfTest, ProxyResolverV8) { 283 TEST(ProxyResolverPerfTest, ProxyResolverV8) {
280 base::MessageLoop message_loop; 284 base::MessageLoop message_loop;
281 ProxyResolverV8Factory factory; 285 ProxyResolverV8Factory factory;
282 PacPerfSuiteRunner runner(&factory, "ProxyResolverV8"); 286 PacPerfSuiteRunner runner(&factory, "ProxyResolverV8");
283 runner.RunAllTests(); 287 runner.RunAllTests();
284 } 288 }
285 289
286 } // namespace 290 } // namespace
287 291
288 } // namespace net 292 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_factory_mojo_unittest.cc ('k') | net/proxy/proxy_resolver_v8_tracing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698