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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc

Issue 390533003: Bypassed Bytes UMAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te st_utils.h" 13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te st_utils.h"
14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h"
14 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
15 #include "net/base/host_port_pair.h" 16 #include "net/base/host_port_pair.h"
16 #include "net/base/network_delegate.h" 17 #include "net/base/network_delegate.h"
17 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
18 #include "net/http/http_transaction_test_util.h" 19 #include "net/http/http_transaction_test_util.h"
19 #include "net/socket/socket_test_util.h" 20 #include "net/socket/socket_test_util.h"
20 #include "net/url_request/static_http_user_agent_settings.h" 21 #include "net/url_request/static_http_user_agent_settings.h"
21 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
22 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
23 #include "net/url_request/url_request_test_util.h" 24 #include "net/url_request/url_request_test_util.h"
(...skipping 18 matching lines...) Expand all
42 std::replace(headers->begin(), headers->end(), '\n', '\0'); 43 std::replace(headers->begin(), headers->end(), '\n', '\0');
43 if (!headers->empty()) 44 if (!headers->empty())
44 *headers += '\0'; 45 *headers += '\0';
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 50
50 namespace data_reduction_proxy { 51 namespace data_reduction_proxy {
51 52
53 // A test DataReductionUsageStats
54 class TestDataReductionProxyUsageStats : public DataReductionProxyUsageStats {
55 public:
56 TestDataReductionProxyUsageStats() : DataReductionProxyUsageStats(NULL,
bengr 2014/07/12 00:11:59 Can all the params fit on the same line as the fir
bengr 2014/07/14 22:04:29 Done.
57 NULL,
58 NULL) {}
59 virtual void SetBypassType(
60 net::ProxyService::DataReductionProxyBypassType type) OVERRIDE {}
bengr 2014/07/14 17:44:02 I'd add a variable, e.g., set_bypass_type_called_c
megjablon 2014/07/14 19:06:41 With moving the SetBypassType outside of MaybeBypa
61 };
62
52 // A test network delegate that exercises the bypass logic of the data 63 // A test network delegate that exercises the bypass logic of the data
53 // reduction proxy. 64 // reduction proxy.
54 class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate { 65 class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate {
55 public: 66 public:
56 TestDataReductionProxyNetworkDelegate( 67 TestDataReductionProxyNetworkDelegate(
57 TestDataReductionProxyParams* test_params) 68 TestDataReductionProxyParams* test_params,
58 : net::NetworkDelegate(), test_data_reduction_proxy_params_(test_params) { 69 TestDataReductionProxyUsageStats* usage_stats)
70 : net::NetworkDelegate(), test_data_reduction_proxy_params_(test_params),
71 test_data_reduction_proxy_usage_stats_(usage_stats) {
59 } 72 }
60 73
61 virtual int OnHeadersReceived( 74 virtual int OnHeadersReceived(
62 URLRequest* request, 75 URLRequest* request,
63 const net::CompletionCallback& callback, 76 const net::CompletionCallback& callback,
64 const HttpResponseHeaders* original_response_headers, 77 const HttpResponseHeaders* original_response_headers,
65 scoped_refptr<HttpResponseHeaders>* override_response_headers, 78 scoped_refptr<HttpResponseHeaders>* override_response_headers,
66 GURL* allowed_unsafe_redirect_url) OVERRIDE { 79 GURL* allowed_unsafe_redirect_url) OVERRIDE {
67 data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry( 80 data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
68 test_data_reduction_proxy_params_, 81 test_data_reduction_proxy_params_,
82 test_data_reduction_proxy_usage_stats_,
69 request, 83 request,
70 original_response_headers, 84 original_response_headers,
71 override_response_headers); 85 override_response_headers);
72 return net::OK; 86 return net::OK;
73 } 87 }
74 88
75 TestDataReductionProxyParams* test_data_reduction_proxy_params_; 89 TestDataReductionProxyParams* test_data_reduction_proxy_params_;
90 DataReductionProxyUsageStats* test_data_reduction_proxy_usage_stats_;
76 }; 91 };
77 92
78 // Constructs a |TestURLRequestContext| that uses a |MockSocketFactory| to 93 // Constructs a |TestURLRequestContext| that uses a |MockSocketFactory| to
79 // simulate requests and responses. 94 // simulate requests and responses.
80 class DataReductionProxyProtocolTest : public testing::Test { 95 class DataReductionProxyProtocolTest : public testing::Test {
81 public: 96 public:
82 DataReductionProxyProtocolTest() : http_user_agent_settings_("", "") { 97 DataReductionProxyProtocolTest() : http_user_agent_settings_("", "") {
83 proxy_params_.reset( 98 proxy_params_.reset(
84 new TestDataReductionProxyParams( 99 new TestDataReductionProxyParams(
85 DataReductionProxyParams::kAllowed | 100 DataReductionProxyParams::kAllowed |
86 DataReductionProxyParams::kFallbackAllowed | 101 DataReductionProxyParams::kFallbackAllowed |
87 DataReductionProxyParams::kPromoAllowed, 102 DataReductionProxyParams::kPromoAllowed,
88 TestDataReductionProxyParams::HAS_EVERYTHING & 103 TestDataReductionProxyParams::HAS_EVERYTHING &
89 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); 104 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN));
105 usage_stats_.reset(new TestDataReductionProxyUsageStats());
90 } 106 }
91 107
92 // Sets up the |TestURLRequestContext| with the provided |ProxyService|. 108 // Sets up the |TestURLRequestContext| with the provided |ProxyService|.
93 void ConfigureTestDependencies(ProxyService* proxy_service) { 109 void ConfigureTestDependencies(ProxyService* proxy_service) {
94 // Create a context with delayed initialization. 110 // Create a context with delayed initialization.
95 context_.reset(new TestURLRequestContext(true)); 111 context_.reset(new TestURLRequestContext(true));
96 112
97 proxy_service_.reset(proxy_service); 113 proxy_service_.reset(proxy_service);
98 network_delegate_.reset(new TestDataReductionProxyNetworkDelegate( 114 network_delegate_.reset(new TestDataReductionProxyNetworkDelegate(
99 proxy_params_.get())); 115 proxy_params_.get(), usage_stats_.get()));
100 116
101 context_->set_client_socket_factory(&mock_socket_factory_); 117 context_->set_client_socket_factory(&mock_socket_factory_);
102 context_->set_proxy_service(proxy_service_.get()); 118 context_->set_proxy_service(proxy_service_.get());
103 context_->set_network_delegate(network_delegate_.get()); 119 context_->set_network_delegate(network_delegate_.get());
104 // This is needed to prevent the test context from adding language headers 120 // This is needed to prevent the test context from adding language headers
105 // to requests. 121 // to requests.
106 context_->set_http_user_agent_settings(&http_user_agent_settings_); 122 context_->set_http_user_agent_settings(&http_user_agent_settings_);
107 123
108 context_->Init(); 124 context_->Init();
109 } 125 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 EXPECT_TRUE((*i).second.current_delay <= expected_max_duration); 273 EXPECT_TRUE((*i).second.current_delay <= expected_max_duration);
258 } 274 }
259 } 275 }
260 276
261 protected: 277 protected:
262 base::MessageLoopForIO loop_; 278 base::MessageLoopForIO loop_;
263 279
264 net::MockClientSocketFactory mock_socket_factory_; 280 net::MockClientSocketFactory mock_socket_factory_;
265 scoped_ptr<ProxyService> proxy_service_; 281 scoped_ptr<ProxyService> proxy_service_;
266 scoped_ptr<TestDataReductionProxyParams> proxy_params_; 282 scoped_ptr<TestDataReductionProxyParams> proxy_params_;
283 scoped_ptr<TestDataReductionProxyUsageStats> usage_stats_;
267 scoped_ptr<TestDataReductionProxyNetworkDelegate> network_delegate_; 284 scoped_ptr<TestDataReductionProxyNetworkDelegate> network_delegate_;
268 net::StaticHttpUserAgentSettings http_user_agent_settings_; 285 net::StaticHttpUserAgentSettings http_user_agent_settings_;
269 286
270 scoped_ptr<TestURLRequestContext> context_; 287 scoped_ptr<TestURLRequestContext> context_;
271 }; 288 };
272 289
273 // Tests that request are deemed idempotent or not according to the method used. 290 // Tests that request are deemed idempotent or not according to the method used.
274 TEST_F(DataReductionProxyProtocolTest, TestIdempotency) { 291 TEST_F(DataReductionProxyProtocolTest, TestIdempotency) {
275 net::TestURLRequestContext context; 292 net::TestURLRequestContext context;
276 const struct { 293 const struct {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); 622 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status());
606 EXPECT_EQ(net::OK, r.status().error()); 623 EXPECT_EQ(net::OK, r.status().error());
607 624
608 EXPECT_EQ("Bypass message", d.data_received()); 625 EXPECT_EQ("Bypass message", d.data_received());
609 626
610 // We should have no entries in our bad proxy list. 627 // We should have no entries in our bad proxy list.
611 TestBadProxies(0, -1, "", ""); 628 TestBadProxies(0, -1, "", "");
612 } 629 }
613 630
614 } // namespace data_reduction_proxy 631 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698