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/browser/data_reduction_proxy_settings_
test_utils.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_
test_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 12 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
14 | 14 |
15 using testing::_; | 15 using testing::_; |
16 using testing::AnyNumber; | 16 using testing::AnyNumber; |
17 using testing::Return; | 17 using testing::Return; |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kDataReductionProxy[] = "https://foo.com:443/"; | |
22 const char kDataReductionProxyFallback[] = "http://bar.com:80/"; | |
23 const char kDataReductionProxyKey[] = "12345"; | |
24 | |
25 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 21 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
26 const char kWarmupURLWithNoContentResponse[] = "http://warm.org/"; | 22 const char kWarmupURLWithNoContentResponse[] = "http://warm.org/"; |
27 | 23 |
28 const char kProxy[] = "proxy"; | 24 const char kProxy[] = "proxy"; |
29 | 25 |
30 } // namespace | 26 } // namespace |
31 | 27 |
32 namespace data_reduction_proxy { | 28 namespace data_reduction_proxy { |
33 | 29 |
34 // Transform "normal"-looking headers (\n-separated) to the appropriate | 30 // Transform "normal"-looking headers (\n-separated) to the appropriate |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 67 |
72 void TestDataReductionProxyConfig::Disable() { | 68 void TestDataReductionProxyConfig::Disable() { |
73 enabled_ = false; | 69 enabled_ = false; |
74 restricted_ = false; | 70 restricted_ = false; |
75 fallback_restricted_ = false; | 71 fallback_restricted_ = false; |
76 origin_ = ""; | 72 origin_ = ""; |
77 fallback_origin_ = ""; | 73 fallback_origin_ = ""; |
78 ssl_origin_ = ""; | 74 ssl_origin_ = ""; |
79 } | 75 } |
80 | 76 |
81 // static | |
82 void DataReductionProxySettingsTestBase::AddTestProxyToCommandLine() { | |
83 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
84 switches::kDataReductionProxy, kDataReductionProxy); | |
85 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
86 switches::kDataReductionProxyFallback, kDataReductionProxyFallback); | |
87 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
88 switches::kDataReductionProxyKey, kDataReductionProxyKey); | |
89 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
90 switches::kDataReductionProxyProbeURL, kProbeURLWithOKResponse); | |
91 } | |
92 | |
93 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() | 77 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() |
94 : testing::Test() { | 78 : testing::Test() { |
95 } | 79 } |
96 | 80 |
97 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} | 81 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} |
98 | 82 |
99 void DataReductionProxySettingsTestBase::AddProxyToCommandLine() { | |
100 AddTestProxyToCommandLine(); | |
101 } | |
102 | |
103 // testing::Test implementation: | 83 // testing::Test implementation: |
104 void DataReductionProxySettingsTestBase::SetUp() { | 84 void DataReductionProxySettingsTestBase::SetUp() { |
105 PrefRegistrySimple* registry = pref_service_.registry(); | 85 PrefRegistrySimple* registry = pref_service_.registry(); |
106 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); | 86 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); |
107 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); | 87 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); |
108 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, | 88 registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, |
109 0L); | 89 0L); |
110 registry->RegisterDictionaryPref(kProxy); | 90 registry->RegisterDictionaryPref(kProxy); |
111 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); | 91 registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); |
112 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); | 92 registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); |
113 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, | 93 registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, |
114 false); | 94 false); |
115 AddProxyToCommandLine(); | 95 //AddProxyToCommandLine(); |
116 ResetSettings(true, true, false, true); | 96 ResetSettings(true, true, false, true); |
117 | 97 |
118 ListPrefUpdate original_update(&pref_service_, | 98 ListPrefUpdate original_update(&pref_service_, |
119 prefs::kDailyHttpOriginalContentLength); | 99 prefs::kDailyHttpOriginalContentLength); |
120 ListPrefUpdate received_update(&pref_service_, | 100 ListPrefUpdate received_update(&pref_service_, |
121 prefs::kDailyHttpReceivedContentLength); | 101 prefs::kDailyHttpReceivedContentLength); |
122 for (int64 i = 0; i < kNumDaysInHistory; i++) { | 102 for (int64 i = 0; i < kNumDaysInHistory; i++) { |
123 original_update->Insert(0, | 103 original_update->Insert(0, |
124 new base::StringValue(base::Int64ToString(2 * i))); | 104 new base::StringValue(base::Int64ToString(2 * i))); |
125 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); | 105 received_update->Insert(0, new base::StringValue(base::Int64ToString(i))); |
126 } | 106 } |
127 last_update_time_ = base::Time::Now().LocalMidnight(); | 107 last_update_time_ = base::Time::Now().LocalMidnight(); |
128 pref_service_.SetInt64( | 108 pref_service_.SetInt64( |
129 prefs::kDailyHttpContentLengthLastUpdateDate, | 109 prefs::kDailyHttpContentLengthLastUpdateDate, |
130 last_update_time_.ToInternalValue()); | 110 last_update_time_.ToInternalValue()); |
| 111 expected_params_.reset(new TestDataReductionProxyParams( |
| 112 DataReductionProxyParams::kAllowed | |
| 113 DataReductionProxyParams::kFallbackAllowed | |
| 114 DataReductionProxyParams::kPromoAllowed, |
| 115 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 116 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); |
131 } | 117 } |
132 | 118 |
133 template <class C> | 119 template <class C> |
134 void DataReductionProxySettingsTestBase::ResetSettings(bool allowed, | 120 void DataReductionProxySettingsTestBase::ResetSettings(bool allowed, |
135 bool fallback_allowed, | 121 bool fallback_allowed, |
136 bool alt_allowed, | 122 bool alt_allowed, |
137 bool promo_allowed) { | 123 bool promo_allowed) { |
138 int flags = 0; | 124 int flags = 0; |
139 if (allowed) | 125 if (allowed) |
140 flags |= DataReductionProxyParams::kAllowed; | 126 flags |= DataReductionProxyParams::kAllowed; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 294 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
309 settings_->InitDataReductionProxySettings(&pref_service_, | 295 settings_->InitDataReductionProxySettings(&pref_service_, |
310 &pref_service_, | 296 &pref_service_, |
311 request_context.get()); | 297 request_context.get()); |
312 | 298 |
313 base::MessageLoop::current()->RunUntilIdle(); | 299 base::MessageLoop::current()->RunUntilIdle(); |
314 CheckProxyConfigs(enabled_at_startup, false, false); | 300 CheckProxyConfigs(enabled_at_startup, false, false); |
315 } | 301 } |
316 | 302 |
317 } // namespace data_reduction_proxy | 303 } // namespace data_reduction_proxy |
OLD | NEW |