| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/data_reduction_proxy_expe
riments_stats.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_expe
riments_stats.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <map> | 9 #include <map> |
| 8 | 10 |
| 9 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_retrieval_params.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_retrieval_params.h" |
| 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
| 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
| 17 #include "components/variations/variations_associated_data.h" | 19 #include "components/variations/variations_associated_data.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 // Test value for how long a Data Reduction Proxy configuration should be valid. | 24 // Test value for how long a Data Reduction Proxy configuration should be valid. |
| 23 const int64 kConfigExpirationSeconds = 60 * 60 * 24; | 25 const int64_t kConfigExpirationSeconds = 60 * 60 * 24; |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 namespace data_reduction_proxy { | 29 namespace data_reduction_proxy { |
| 28 | 30 |
| 29 class DataReductionProxyExperimentsStatsTest : public testing::Test { | 31 class DataReductionProxyExperimentsStatsTest : public testing::Test { |
| 30 public: | 32 public: |
| 31 void SetPrefValue(const std::string& path, int64 value) {} | 33 void SetPrefValue(const std::string& path, int64_t value) {} |
| 32 | 34 |
| 33 protected: | 35 protected: |
| 34 void SetUp() override { | 36 void SetUp() override { |
| 35 test_context_ = DataReductionProxyTestContext::Builder().Build(); | 37 test_context_ = DataReductionProxyTestContext::Builder().Build(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 void SetConfigExperimentValues( | 40 void SetConfigExperimentValues( |
| 39 bool enabled, | 41 bool enabled, |
| 40 const base::TimeDelta& retrieve_offset_from_now, | 42 const base::TimeDelta& retrieve_offset_from_now, |
| 41 int64 roundtrip_milliseconds_base, | 43 int64_t roundtrip_milliseconds_base, |
| 42 double roundtrip_multiplier, | 44 double roundtrip_multiplier, |
| 43 int64 roundtrip_milliseconds_increment, | 45 int64_t roundtrip_milliseconds_increment, |
| 44 int64 expiration_seconds, | 46 int64_t expiration_seconds, |
| 45 bool always_stale) { | 47 bool always_stale) { |
| 46 variations::testing::ClearAllVariationParams(); | 48 variations::testing::ClearAllVariationParams(); |
| 47 std::map<std::string, std::string> variation_params; | 49 std::map<std::string, std::string> variation_params; |
| 48 variation_params[kConfigRoundtripMillisecondsBaseParam] = | 50 variation_params[kConfigRoundtripMillisecondsBaseParam] = |
| 49 base::Int64ToString(roundtrip_milliseconds_base); | 51 base::Int64ToString(roundtrip_milliseconds_base); |
| 50 variation_params[kConfigRoundtripMultiplierParam] = | 52 variation_params[kConfigRoundtripMultiplierParam] = |
| 51 base::DoubleToString(roundtrip_multiplier); | 53 base::DoubleToString(roundtrip_multiplier); |
| 52 variation_params[kConfigRoundtripMillisecondsIncrementParam] = | 54 variation_params[kConfigRoundtripMillisecondsIncrementParam] = |
| 53 base::Int64ToString(roundtrip_milliseconds_increment); | 55 base::Int64ToString(roundtrip_milliseconds_increment); |
| 54 variation_params[kConfigExpirationSecondsParam] = | 56 variation_params[kConfigExpirationSecondsParam] = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 85 histogram_tester.ExpectTotalCount( | 87 histogram_tester.ExpectTotalCount( |
| 86 "DataReductionProxy.ConfigFetchLostBytesCL_0", 0); | 88 "DataReductionProxy.ConfigFetchLostBytesCL_0", 0); |
| 87 histogram_tester.ExpectTotalCount( | 89 histogram_tester.ExpectTotalCount( |
| 88 "DataReductionProxy.ConfigFetchLostBytesDiff_0", 0); | 90 "DataReductionProxy.ConfigFetchLostBytesDiff_0", 0); |
| 89 } | 91 } |
| 90 | 92 |
| 91 TEST_F(DataReductionProxyExperimentsStatsTest, CheckConfigHistograms) { | 93 TEST_F(DataReductionProxyExperimentsStatsTest, CheckConfigHistograms) { |
| 92 struct { | 94 struct { |
| 93 DataReductionProxyRequestType request_type; | 95 DataReductionProxyRequestType request_type; |
| 94 base::Time request_time; | 96 base::Time request_time; |
| 95 int64 received_content_length; | 97 int64_t received_content_length; |
| 96 int64 original_content_length; | 98 int64_t original_content_length; |
| 97 int64 expected_received_content_length; | 99 int64_t expected_received_content_length; |
| 98 int64 expected_original_content_length; | 100 int64_t expected_original_content_length; |
| 99 int64 expected_diff; | 101 int64_t expected_diff; |
| 100 } test_cases[] = { | 102 } test_cases[] = { |
| 101 { | 103 { |
| 102 VIA_DATA_REDUCTION_PROXY, | 104 VIA_DATA_REDUCTION_PROXY, |
| 103 base::Time::Now() + base::TimeDelta::FromMinutes(5), | 105 base::Time::Now() + base::TimeDelta::FromMinutes(5), |
| 104 500, | 106 500, |
| 105 1000, | 107 1000, |
| 106 -1, | 108 -1, |
| 107 -1, | 109 -1, |
| 108 -1, | 110 -1, |
| 109 }, | 111 }, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 "DataReductionProxy.ConfigFetchLostBytesDiff_0", 0); | 156 "DataReductionProxy.ConfigFetchLostBytesDiff_0", 0); |
| 155 } else { | 157 } else { |
| 156 histogram_tester.ExpectUniqueSample( | 158 histogram_tester.ExpectUniqueSample( |
| 157 "DataReductionProxy.ConfigFetchLostBytesDiff_0", | 159 "DataReductionProxy.ConfigFetchLostBytesDiff_0", |
| 158 test_case.expected_diff, 1); | 160 test_case.expected_diff, 1); |
| 159 } | 161 } |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 } // namespace data_reduction_proxy | 165 } // namespace data_reduction_proxy |
| OLD | NEW |