OLD | NEW |
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/browser/data_reduction_proxy_sett
ings_test_utils.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings_test_utils.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 .WithMockDataReductionProxyService() | 47 .WithMockDataReductionProxyService() |
48 .SkipSettingsInitialization() | 48 .SkipSettingsInitialization() |
49 .Build(); | 49 .Build(); |
50 | 50 |
51 test_context_->SetDataReductionProxyEnabled(false); | 51 test_context_->SetDataReductionProxyEnabled(false); |
52 TestingPrefServiceSimple* pref_service = test_context_->pref_service(); | 52 TestingPrefServiceSimple* pref_service = test_context_->pref_service(); |
53 pref_service->SetInt64(prefs::kDailyHttpContentLengthLastUpdateDate, 0L); | 53 pref_service->SetInt64(prefs::kDailyHttpContentLengthLastUpdateDate, 0L); |
54 pref_service->registry()->RegisterDictionaryPref(kProxy); | 54 pref_service->registry()->RegisterDictionaryPref(kProxy); |
55 pref_service->SetBoolean(prefs::kDataReductionProxyWasEnabledBefore, false); | 55 pref_service->SetBoolean(prefs::kDataReductionProxyWasEnabledBefore, false); |
56 | 56 |
57 ResetSettings(nullptr, true, false); | 57 ResetSettings(nullptr); |
58 | 58 |
59 ListPrefUpdate original_update(test_context_->pref_service(), | 59 ListPrefUpdate original_update(test_context_->pref_service(), |
60 prefs::kDailyHttpOriginalContentLength); | 60 prefs::kDailyHttpOriginalContentLength); |
61 ListPrefUpdate received_update(test_context_->pref_service(), | 61 ListPrefUpdate received_update(test_context_->pref_service(), |
62 prefs::kDailyHttpReceivedContentLength); | 62 prefs::kDailyHttpReceivedContentLength); |
63 for (int64_t i = 0; i < kNumDaysInHistory; i++) { | 63 for (int64_t i = 0; i < kNumDaysInHistory; i++) { |
64 original_update->Insert( | 64 original_update->Insert( |
65 0, base::MakeUnique<base::Value>(base::Int64ToString(2 * i))); | 65 0, base::MakeUnique<base::Value>(base::Int64ToString(2 * i))); |
66 received_update->Insert( | 66 received_update->Insert( |
67 0, base::MakeUnique<base::Value>(base::Int64ToString(i))); | 67 0, base::MakeUnique<base::Value>(base::Int64ToString(i))); |
68 } | 68 } |
69 last_update_time_ = base::Time::Now().LocalMidnight(); | 69 last_update_time_ = base::Time::Now().LocalMidnight(); |
70 pref_service->SetInt64(prefs::kDailyHttpContentLengthLastUpdateDate, | 70 pref_service->SetInt64(prefs::kDailyHttpContentLengthLastUpdateDate, |
71 last_update_time_.ToInternalValue()); | 71 last_update_time_.ToInternalValue()); |
72 } | 72 } |
73 | 73 |
74 template <class C> | 74 template <class C> |
75 void DataReductionProxySettingsTestBase::ResetSettings( | 75 void DataReductionProxySettingsTestBase::ResetSettings( |
76 std::unique_ptr<base::Clock> clock, | 76 std::unique_ptr<base::Clock> clock) { |
77 bool promo_allowed, | |
78 bool holdback) { | |
79 int flags = 0; | |
80 if (promo_allowed) | |
81 flags |= DataReductionProxyParams::kPromoAllowed; | |
82 if (holdback) | |
83 flags |= DataReductionProxyParams::kHoldback; | |
84 MockDataReductionProxySettings<C>* settings = | 77 MockDataReductionProxySettings<C>* settings = |
85 new MockDataReductionProxySettings<C>(); | 78 new MockDataReductionProxySettings<C>(); |
86 settings->config_ = test_context_->config(); | 79 settings->config_ = test_context_->config(); |
87 settings->prefs_ = test_context_->pref_service(); | 80 settings->prefs_ = test_context_->pref_service(); |
88 settings->data_reduction_proxy_service_ = | 81 settings->data_reduction_proxy_service_ = |
89 test_context_->CreateDataReductionProxyService(settings); | 82 test_context_->CreateDataReductionProxyService(settings); |
90 if (clock) | 83 if (clock) |
91 settings->clock_ = std::move(clock); | 84 settings->clock_ = std::move(clock); |
92 test_context_->config()->ResetParamFlagsForTest(flags); | |
93 settings->UpdateConfigValues(); | |
94 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) | 85 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) |
95 .Times(AnyNumber()) | 86 .Times(AnyNumber()) |
96 .WillRepeatedly(Return(test_context_->pref_service())); | 87 .WillRepeatedly(Return(test_context_->pref_service())); |
97 EXPECT_CALL(*settings, GetLocalStatePrefs()) | 88 EXPECT_CALL(*settings, GetLocalStatePrefs()) |
98 .Times(AnyNumber()) | 89 .Times(AnyNumber()) |
99 .WillRepeatedly(Return(test_context_->pref_service())); | 90 .WillRepeatedly(Return(test_context_->pref_service())); |
100 settings_.reset(settings); | 91 settings_.reset(settings); |
101 } | 92 } |
102 | 93 |
103 // Explicitly generate required instantiations. | 94 // Explicitly generate required instantiations. |
104 template void DataReductionProxySettingsTestBase::ResetSettings< | 95 template void DataReductionProxySettingsTestBase::ResetSettings< |
105 DataReductionProxySettings>(std::unique_ptr<base::Clock> clock, | 96 DataReductionProxySettings>(std::unique_ptr<base::Clock> clock); |
106 bool promo_allowed, | |
107 bool holdback); | |
108 | 97 |
109 void DataReductionProxySettingsTestBase::ExpectSetProxyPrefs( | 98 void DataReductionProxySettingsTestBase::ExpectSetProxyPrefs( |
110 bool expected_enabled, | 99 bool expected_enabled, |
111 bool expected_at_startup) { | 100 bool expected_at_startup) { |
112 MockDataReductionProxyService* mock_service = | 101 MockDataReductionProxyService* mock_service = |
113 static_cast<MockDataReductionProxyService*>( | 102 static_cast<MockDataReductionProxyService*>( |
114 settings_->data_reduction_proxy_service()); | 103 settings_->data_reduction_proxy_service()); |
115 EXPECT_CALL(*mock_service, | 104 EXPECT_CALL(*mock_service, |
116 SetProxyPrefs(expected_enabled, expected_at_startup)); | 105 SetProxyPrefs(expected_enabled, expected_at_startup)); |
117 } | 106 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 143 } |
155 | 144 |
156 bool DataReductionProxySettingsTestBase::OnSyntheticFieldTrialRegistration( | 145 bool DataReductionProxySettingsTestBase::OnSyntheticFieldTrialRegistration( |
157 base::StringPiece trial_name, | 146 base::StringPiece trial_name, |
158 base::StringPiece group_name) { | 147 base::StringPiece group_name) { |
159 synthetic_field_trials_[trial_name.as_string()] = group_name.as_string(); | 148 synthetic_field_trials_[trial_name.as_string()] = group_name.as_string(); |
160 return true; | 149 return true; |
161 } | 150 } |
162 | 151 |
163 } // namespace data_reduction_proxy | 152 } // namespace data_reduction_proxy |
OLD | NEW |