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

Side by Side Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_event_store_unittest.cc

Issue 1406993010: Crop urls in Data Saver feedback reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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/core/common/data_reduction_proxy_event _store.h" 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h" 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator.h"
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _creator.h" 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _creator.h"
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h"
18 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/http/http_status_code.h" 21 #include "net/http/http_status_code.h"
21 #include "net/log/net_log.h" 22 #include "net/log/net_log.h"
22 #include "net/log/test_net_log.h" 23 #include "net/log/test_net_log.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 net::HostPortPair("foo.com", 80))); 223 net::HostPortPair("foo.com", 80)));
223 http_proxies.push_back(net::ProxyServer(net::ProxyServer::SCHEME_HTTPS, 224 http_proxies.push_back(net::ProxyServer(net::ProxyServer::SCHEME_HTTPS,
224 net::HostPortPair("bar.com", 443))); 225 net::HostPortPair("bar.com", 443)));
225 https_proxies.push_back(net::ProxyServer(net::ProxyServer::SCHEME_HTTP, 226 https_proxies.push_back(net::ProxyServer(net::ProxyServer::SCHEME_HTTP,
226 net::HostPortPair("baz.com", 80))); 227 net::HostPortPair("baz.com", 80)));
227 configurator.Enable(false, http_proxies, https_proxies); 228 configurator.Enable(false, http_proxies, https_proxies);
228 EXPECT_EQ("foo.com:80;https://bar.com:443", 229 EXPECT_EQ("foo.com:80;https://bar.com:443",
229 event_store()->GetHttpProxyList()); 230 event_store()->GetHttpProxyList());
230 EXPECT_EQ("baz.com:80", event_store()->GetHttpsProxyList()); 231 EXPECT_EQ("baz.com:80", event_store()->GetHttpsProxyList());
231 232
233 configurator.Disable();
234 EXPECT_EQ(std::string(), event_store()->GetHttpProxyList());
235 EXPECT_EQ(std::string(), event_store()->GetHttpsProxyList());
236 }
237
238 TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) {
239 DataReductionProxyConfigurator configurator(net_log(), event_creator());
240 std::vector<net::ProxyServer> http_proxies;
241 std::vector<net::ProxyServer> https_proxies;
242 configurator.Enable(false, http_proxies, https_proxies);
243
232 scoped_ptr<base::DictionaryValue> bypass_event(new base::DictionaryValue()); 244 scoped_ptr<base::DictionaryValue> bypass_event(new base::DictionaryValue());
233 scoped_ptr<base::DictionaryValue> bypass_params(new base::DictionaryValue()); 245 scoped_ptr<base::DictionaryValue> bypass_params(new base::DictionaryValue());
234 scoped_ptr<base::DictionaryValue> sanitized_event( 246 scoped_ptr<base::DictionaryValue> sanitized_event(
235 new base::DictionaryValue()); 247 new base::DictionaryValue());
236 248
237 bypass_event->SetString("time", "12/31/2014 23:58"); 249 std::string time = net::NetLog::TickCountToString(base::TimeTicks::Now());
238 sanitized_event->SetString("bypass_time", "12/31/2014 23:58"); 250 bypass_event->SetString("time", time);
251 sanitized_event->SetString("bypass_time", time);
239 bypass_params->SetInteger("bypass_type", 4); 252 bypass_params->SetInteger("bypass_type", 4);
240 sanitized_event->SetInteger("bypass_type", 4); 253 sanitized_event->SetInteger("bypass_type", 4);
241 bypass_params->SetString("bypass_duration_seconds", "40"); 254 bypass_params->SetString("bypass_duration_seconds", "40");
242 sanitized_event->SetString("bypass_seconds", "40"); 255 sanitized_event->SetString("bypass_seconds", "40");
243 bypass_params->SetString("url", "http://www.foo.com/bar?baz=1234"); 256 bypass_params->SetString("url", "http://www.foo.com/bar?baz=1234");
244 sanitized_event->SetString("url", "http://www.foo.com/bar"); 257 sanitized_event->SetString("url", "http://www.foo.com/bar");
245 258
246 bypass_event->Set("params", bypass_params.Pass()); 259 bypass_event->Set("params", bypass_params.Pass());
247 std::string sanitized_output; 260 std::string sanitized_output;
248 base::JSONWriter::Write(*sanitized_event.get(), &sanitized_output); 261 base::JSONWriter::Write(*sanitized_event.get(), &sanitized_output);
249 event_store()->AddAndSetLastBypassEvent(bypass_event.Pass(), 0); 262 event_store()->AddAndSetLastBypassEvent(bypass_event.Pass(), 0);
250 EXPECT_EQ(sanitized_output, event_store()->SanitizedLastBypassEvent()); 263 EXPECT_EQ(sanitized_output, event_store()->SanitizedLastBypassEvent());
264 }
251 265
252 configurator.Disable(); 266 TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventHostOnly) {
253 EXPECT_EQ(std::string(), event_store()->GetHttpProxyList()); 267 DataReductionProxyConfigurator configurator(net_log(), event_creator());
254 EXPECT_EQ(std::string(), event_store()->GetHttpsProxyList()); 268 std::vector<net::ProxyServer> http_proxies;
269 std::vector<net::ProxyServer> https_proxies;
270 configurator.Enable(false, http_proxies, https_proxies);
271
272 scoped_ptr<base::DictionaryValue> bypass_event(new base::DictionaryValue());
273 scoped_ptr<base::DictionaryValue> bypass_params(new base::DictionaryValue());
274 scoped_ptr<base::DictionaryValue> sanitized_event(
275 new base::DictionaryValue());
276
277 int64 delta_time =
278 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
279 // Set bypass event time to be 5 minutes ago.
280 delta_time -= 300000;
281 std::string time = base::Int64ToString(delta_time);
282 bypass_event->SetString("time", time);
283 sanitized_event->SetString("bypass_time", time);
284 bypass_params->SetInteger("bypass_type", 4);
285 sanitized_event->SetInteger("bypass_type", 4);
286 bypass_params->SetString("bypass_duration_seconds", "40");
287 sanitized_event->SetString("bypass_seconds", "40");
288 bypass_params->SetString("url", "http://www.foo.com/bar?baz=1234");
289 sanitized_event->SetString("url", "www.foo.com");
290
291 bypass_event->Set("params", bypass_params.Pass());
292 std::string sanitized_output;
293 base::JSONWriter::Write(*sanitized_event.get(), &sanitized_output);
294 event_store()->AddAndSetLastBypassEvent(bypass_event.Pass(), 0);
295 EXPECT_EQ(sanitized_output, event_store()->SanitizedLastBypassEvent());
255 } 296 }
256 297
257 } // namespace data_reduction_proxy 298 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698