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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_TE
ST_UTILS_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_TE
ST_UTILS_H_ |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_TE
ST_UTILS_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_TE
ST_UTILS_H_ |
7 | 7 |
8 | 8 |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura
tor.h" | 10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura
tor.h" |
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
12 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 class PrefService; | 17 class PrefService; |
18 class TestingPrefServiceSimple; | 18 class TestingPrefServiceSimple; |
19 | 19 |
20 namespace data_reduction_proxy { | 20 namespace data_reduction_proxy { |
21 | 21 |
22 class TestDataReductionProxyConfig : public DataReductionProxyConfigurator { | 22 class TestDataReductionProxyConfig : public DataReductionProxyConfigurator { |
23 public: | 23 public: |
24 TestDataReductionProxyConfig() | 24 TestDataReductionProxyConfig(); |
25 : enabled_(false), restricted_(false), fallback_restricted_(false) {} | |
26 virtual ~TestDataReductionProxyConfig() {} | 25 virtual ~TestDataReductionProxyConfig() {} |
27 virtual void Enable(bool restricted, | 26 virtual void Enable(bool restricted, |
28 bool fallback_restricted, | 27 bool fallback_restricted, |
29 const std::string& primary_origin, | 28 const std::string& primary_origin, |
30 const std::string& fallback_origin) OVERRIDE; | 29 const std::string& fallback_origin, |
| 30 const std::string& ssl_origin) OVERRIDE; |
31 virtual void Disable() OVERRIDE; | 31 virtual void Disable() OVERRIDE; |
32 virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE {} | 32 virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE {} |
33 virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE {} | 33 virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE {} |
34 | 34 |
35 // True if the proxy has been enabled, i.e., only after |Enable| has been | 35 // True if the proxy has been enabled, i.e., only after |Enable| has been |
36 // called. Defaults to false. | 36 // called. Defaults to false. |
37 bool enabled_; | 37 bool enabled_; |
38 | 38 |
39 // Describes whether the proxy has been put in a restricted mode. True if | 39 // Describes whether the proxy has been put in a restricted mode. True if |
40 // |Enable| is called with |restricted| set to true. Defaults to false. | 40 // |Enable| is called with |restricted| set to true. Defaults to false. |
41 bool restricted_; | 41 bool restricted_; |
42 | 42 |
43 // Describes whether the proxy has been put in a mode where the fallback | 43 // Describes whether the proxy has been put in a mode where the fallback |
44 // configuration has been disallowed. True if |Enable| is called with | 44 // configuration has been disallowed. True if |Enable| is called with |
45 // |fallback_restricted| set to true. Defaults to false. | 45 // |fallback_restricted| set to true. Defaults to false. |
46 bool fallback_restricted_; | 46 bool fallback_restricted_; |
| 47 |
| 48 // The origins that are passed to |Enable|. |
| 49 std::string origin_; |
| 50 std::string fallback_origin_; |
| 51 std::string ssl_origin_; |
47 }; | 52 }; |
48 | 53 |
49 template <class C> | 54 template <class C> |
50 class MockDataReductionProxySettings : public C { | 55 class MockDataReductionProxySettings : public C { |
51 public: | 56 public: |
| 57 MockDataReductionProxySettings<C>() : DataReductionProxySettings( |
| 58 new DataReductionProxyParams( |
| 59 DataReductionProxyParams::kAllowed | |
| 60 DataReductionProxyParams::kFallbackAllowed | |
| 61 DataReductionProxyParams::kPromoAllowed)) {} |
| 62 MockDataReductionProxySettings<C>(int flags) |
| 63 : C(new DataReductionProxyParams(flags)) {} |
52 MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); | 64 MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); |
53 MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); | 65 MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); |
54 MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); | 66 MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); |
55 MOCK_METHOD3(LogProxyState, void( | 67 MOCK_METHOD3(LogProxyState, void( |
56 bool enabled, bool restricted, bool at_startup)); | 68 bool enabled, bool restricted, bool at_startup)); |
57 MOCK_METHOD1(RecordProbeURLFetchResult, | 69 MOCK_METHOD1(RecordProbeURLFetchResult, |
58 void(ProbeURLFetchResult result)); | 70 void(ProbeURLFetchResult result)); |
59 MOCK_METHOD1(RecordStartupState, | 71 MOCK_METHOD1(RecordStartupState, |
60 void(ProxyStartupState state)); | 72 void(ProxyStartupState state)); |
61 | 73 |
62 // SetProxyConfigs should always call LogProxyState exactly once. | 74 // SetProxyConfigs should always call LogProxyState exactly once. |
63 virtual void SetProxyConfigs( | 75 virtual void SetProxyConfigs(bool enabled, |
64 bool enabled, bool restricted, bool at_startup) OVERRIDE { | 76 bool alternative_enabled, |
| 77 bool restricted, |
| 78 bool at_startup) OVERRIDE { |
65 EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); | 79 EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); |
66 C::SetProxyConfigs(enabled, restricted, at_startup); | 80 C::SetProxyConfigs(enabled, alternative_enabled, restricted, at_startup); |
67 } | 81 } |
68 }; | 82 }; |
69 | 83 |
70 class DataReductionProxySettingsTestBase : public testing::Test { | 84 class DataReductionProxySettingsTestBase : public testing::Test { |
71 public: | 85 public: |
| 86 static void AddTestProxyToCommandLine(); |
| 87 |
72 DataReductionProxySettingsTestBase(); | 88 DataReductionProxySettingsTestBase(); |
| 89 DataReductionProxySettingsTestBase(bool allowed, |
| 90 bool fallback_allowed, |
| 91 bool alt_allowed, |
| 92 bool promo_allowed); |
73 virtual ~DataReductionProxySettingsTestBase(); | 93 virtual ~DataReductionProxySettingsTestBase(); |
74 | 94 |
75 void AddProxyToCommandLine(); | 95 void AddProxyToCommandLine(); |
76 | 96 |
77 virtual void SetUp() OVERRIDE; | 97 virtual void SetUp() OVERRIDE; |
78 | 98 |
79 template <class C> void ResetSettings(); | 99 template <class C> void ResetSettings(bool allowed, |
80 virtual void ResetSettings() = 0; | 100 bool fallback_allowed, |
| 101 bool alt_allowed, |
| 102 bool promo_allowed); |
| 103 virtual void ResetSettings(bool allowed, |
| 104 bool fallback_allowed, |
| 105 bool alt_allowed, |
| 106 bool promo_allowed) = 0; |
81 | 107 |
82 template <class C> void SetProbeResult( | 108 template <class C> void SetProbeResult( |
83 const std::string& test_url, | 109 const std::string& test_url, |
84 const std::string& response, | 110 const std::string& response, |
85 ProbeURLFetchResult state, | 111 ProbeURLFetchResult state, |
86 bool success, | 112 bool success, |
87 int expected_calls); | 113 int expected_calls); |
88 virtual void SetProbeResult(const std::string& test_url, | 114 virtual void SetProbeResult(const std::string& test_url, |
89 const std::string& response, | 115 const std::string& response, |
90 ProbeURLFetchResult result, | 116 ProbeURLFetchResult result, |
(...skipping 24 matching lines...) Expand all Loading... |
115 }; | 141 }; |
116 | 142 |
117 // Test implementations should be subclasses of an instantiation of this | 143 // Test implementations should be subclasses of an instantiation of this |
118 // class parameterized for whatever DataReductionProxySettings class | 144 // class parameterized for whatever DataReductionProxySettings class |
119 // is being tested. | 145 // is being tested. |
120 template <class C> | 146 template <class C> |
121 class ConcreteDataReductionProxySettingsTest | 147 class ConcreteDataReductionProxySettingsTest |
122 : public DataReductionProxySettingsTestBase { | 148 : public DataReductionProxySettingsTestBase { |
123 public: | 149 public: |
124 typedef MockDataReductionProxySettings<C> MockSettings; | 150 typedef MockDataReductionProxySettings<C> MockSettings; |
125 virtual void ResetSettings() OVERRIDE { | 151 virtual void ResetSettings(bool allowed, |
126 return DataReductionProxySettingsTestBase::ResetSettings<C>(); | 152 bool fallback_allowed, |
| 153 bool alt_allowed, |
| 154 bool promo_allowed) OVERRIDE { |
| 155 return DataReductionProxySettingsTestBase::ResetSettings<C>( |
| 156 allowed, fallback_allowed, alt_allowed, promo_allowed); |
127 } | 157 } |
128 | 158 |
129 virtual void SetProbeResult(const std::string& test_url, | 159 virtual void SetProbeResult(const std::string& test_url, |
130 const std::string& response, | 160 const std::string& response, |
131 ProbeURLFetchResult result, | 161 ProbeURLFetchResult result, |
132 bool success, | 162 bool success, |
133 int expected_calls) OVERRIDE { | 163 int expected_calls) OVERRIDE { |
134 return DataReductionProxySettingsTestBase::SetProbeResult<C>( | 164 return DataReductionProxySettingsTestBase::SetProbeResult<C>( |
135 test_url, response, result, success, expected_calls); | 165 test_url, response, result, success, expected_calls); |
136 } | 166 } |
137 }; | 167 }; |
138 | 168 |
139 } // namespace data_reduction_proxy | 169 } // namespace data_reduction_proxy |
140 | 170 |
141 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS
_TEST_UTILS_H_ | 171 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS
_TEST_UTILS_H_ |
OLD | NEW |