| 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_conf
ig_retrieval_params.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_retrieval_params.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <map> | 9 #include <map> |
| 8 | 10 |
| 9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.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/time/time.h" | 14 #include "base/time/time.h" |
| 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
| 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
| 15 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // Test value for how long a Data Reduction Proxy configuration should be valid. | 22 // Test value for how long a Data Reduction Proxy configuration should be valid. |
| 21 const int64 kConfigExpirationSeconds = 60 * 60 * 24; | 23 const int64_t kConfigExpirationSeconds = 60 * 60 * 24; |
| 22 | 24 |
| 23 // Checks that |actual| falls in the range of |min| + |delta| and | 25 // Checks that |actual| falls in the range of |min| + |delta| and |
| 24 // |max| + |delta|. | 26 // |max| + |delta|. |
| 25 void ExpectInTimeRange(const base::Time& min, | 27 void ExpectInTimeRange(const base::Time& min, |
| 26 const base::Time& max, | 28 const base::Time& max, |
| 27 const base::TimeDelta& delta, | 29 const base::TimeDelta& delta, |
| 28 const base::Time& actual) { | 30 const base::Time& actual) { |
| 29 EXPECT_GE(actual, min + delta); | 31 EXPECT_GE(actual, min + delta); |
| 30 EXPECT_LE(actual, max + delta); | 32 EXPECT_LE(actual, max + delta); |
| 31 } | 33 } |
| 32 | 34 |
| 33 } // namespace | 35 } // namespace |
| 34 | 36 |
| 35 namespace data_reduction_proxy { | 37 namespace data_reduction_proxy { |
| 36 | 38 |
| 37 class DataReductionProxyConfigRetrievalParamsTest : public testing::Test { | 39 class DataReductionProxyConfigRetrievalParamsTest : public testing::Test { |
| 38 protected: | 40 protected: |
| 39 void SetUp() override { | 41 void SetUp() override { |
| 40 test_context_ = DataReductionProxyTestContext::Builder().Build(); | 42 test_context_ = DataReductionProxyTestContext::Builder().Build(); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void SetConfigExperimentValues( | 45 void SetConfigExperimentValues( |
| 44 bool enabled, | 46 bool enabled, |
| 45 const base::TimeDelta& retrieve_offset_from_now, | 47 const base::TimeDelta& retrieve_offset_from_now, |
| 46 int64 roundtrip_milliseconds_base, | 48 int64_t roundtrip_milliseconds_base, |
| 47 double roundtrip_multiplier, | 49 double roundtrip_multiplier, |
| 48 int64 roundtrip_milliseconds_increment, | 50 int64_t roundtrip_milliseconds_increment, |
| 49 int64 expiration_seconds, | 51 int64_t expiration_seconds, |
| 50 bool always_stale) { | 52 bool always_stale) { |
| 51 variations::testing::ClearAllVariationParams(); | 53 variations::testing::ClearAllVariationParams(); |
| 52 std::map<std::string, std::string> variation_params; | 54 std::map<std::string, std::string> variation_params; |
| 53 variation_params[kConfigRoundtripMillisecondsBaseParam] = | 55 variation_params[kConfigRoundtripMillisecondsBaseParam] = |
| 54 base::Int64ToString(roundtrip_milliseconds_base); | 56 base::Int64ToString(roundtrip_milliseconds_base); |
| 55 variation_params[kConfigRoundtripMultiplierParam] = | 57 variation_params[kConfigRoundtripMultiplierParam] = |
| 56 base::DoubleToString(roundtrip_multiplier); | 58 base::DoubleToString(roundtrip_multiplier); |
| 57 variation_params[kConfigRoundtripMillisecondsIncrementParam] = | 59 variation_params[kConfigRoundtripMillisecondsIncrementParam] = |
| 58 base::Int64ToString(roundtrip_milliseconds_increment); | 60 base::Int64ToString(roundtrip_milliseconds_increment); |
| 59 variation_params[kConfigExpirationSecondsParam] = | 61 variation_params[kConfigExpirationSecondsParam] = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 | 74 |
| 73 private: | 75 private: |
| 74 base::MessageLoopForIO message_loop_; | 76 base::MessageLoopForIO message_loop_; |
| 75 scoped_ptr<DataReductionProxyTestContext> test_context_; | 77 scoped_ptr<DataReductionProxyTestContext> test_context_; |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 TEST_F(DataReductionProxyConfigRetrievalParamsTest, ExpectedVariations) { | 80 TEST_F(DataReductionProxyConfigRetrievalParamsTest, ExpectedVariations) { |
| 79 struct { | 81 struct { |
| 80 bool experiment_enabled; | 82 bool experiment_enabled; |
| 81 base::TimeDelta retrieve_offset_from_now; | 83 base::TimeDelta retrieve_offset_from_now; |
| 82 int64 expiration_seconds; | 84 int64_t expiration_seconds; |
| 83 int64 roundtrip_milliseconds_base; | 85 int64_t roundtrip_milliseconds_base; |
| 84 double roundtrip_multiplier; | 86 double roundtrip_multiplier; |
| 85 int64 roundtrip_milliseconds_increment; | 87 int64_t roundtrip_milliseconds_increment; |
| 86 bool always_stale; | 88 bool always_stale; |
| 87 bool expected_has_variations; | 89 bool expected_has_variations; |
| 88 base::TimeDelta expected_config_expiration_from_now; | 90 base::TimeDelta expected_config_expiration_from_now; |
| 89 base::TimeDelta expected_delta_0; | 91 base::TimeDelta expected_delta_0; |
| 90 base::TimeDelta expected_delta_2; | 92 base::TimeDelta expected_delta_2; |
| 91 base::TimeDelta expected_delta_5; | 93 base::TimeDelta expected_delta_5; |
| 92 } test_cases[] = { | 94 } test_cases[] = { |
| 93 // Experiment is disabled. | 95 // Experiment is disabled. |
| 94 {false, | 96 {false, |
| 95 base::TimeDelta::FromHours(-2), | 97 base::TimeDelta::FromHours(-2), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 ExpectInTimeRange( | 221 ExpectInTimeRange( |
| 220 min_now, max_now, test_case.expected_delta_5, | 222 min_now, max_now, test_case.expected_delta_5, |
| 221 config_params->variations()[5].simulated_config_retrieved()); | 223 config_params->variations()[5].simulated_config_retrieved()); |
| 222 } else { | 224 } else { |
| 223 EXPECT_EQ(0u, config_params->variations().size()); | 225 EXPECT_EQ(0u, config_params->variations().size()); |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 | 229 |
| 228 } // namespace data_reduction_proxy | 230 } // namespace data_reduction_proxy |
| OLD | NEW |