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(true, true, false, true)) {} |
| 59 MockDataReductionProxySettings<C>(bool allowed, |
| 60 bool fallback_allowed, |
| 61 bool alt_allowed, |
| 62 bool promo_allowed) |
| 63 : C(new DataReductionProxyParams(allowed, |
| 64 fallback_allowed, |
| 65 alt_allowed, |
| 66 promo_allowed)) {} |
52 MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); | 67 MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); |
53 MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); | 68 MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); |
54 MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); | 69 MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); |
55 MOCK_METHOD3(LogProxyState, void( | 70 MOCK_METHOD3(LogProxyState, void( |
56 bool enabled, bool restricted, bool at_startup)); | 71 bool enabled, bool restricted, bool at_startup)); |
57 MOCK_METHOD1(RecordProbeURLFetchResult, | 72 MOCK_METHOD1(RecordProbeURLFetchResult, |
58 void(ProbeURLFetchResult result)); | 73 void(ProbeURLFetchResult result)); |
59 MOCK_METHOD1(RecordStartupState, | 74 MOCK_METHOD1(RecordStartupState, |
60 void(ProxyStartupState state)); | 75 void(ProxyStartupState state)); |
61 | 76 |
62 // SetProxyConfigs should always call LogProxyState exactly once. | 77 // SetProxyConfigs should always call LogProxyState exactly once. |
63 virtual void SetProxyConfigs( | 78 virtual void SetProxyConfigs(bool enabled, |
64 bool enabled, bool restricted, bool at_startup) OVERRIDE { | 79 bool alternative_enabled, |
| 80 bool restricted, |
| 81 bool at_startup) OVERRIDE { |
65 EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); | 82 EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); |
66 C::SetProxyConfigs(enabled, restricted, at_startup); | 83 C::SetProxyConfigs(enabled, alternative_enabled, restricted, at_startup); |
67 } | 84 } |
68 }; | 85 }; |
69 | 86 |
70 class DataReductionProxySettingsTestBase : public testing::Test { | 87 class DataReductionProxySettingsTestBase : public testing::Test { |
71 public: | 88 public: |
| 89 static void AddTestProxyToCommandLine(); |
| 90 |
72 DataReductionProxySettingsTestBase(); | 91 DataReductionProxySettingsTestBase(); |
| 92 DataReductionProxySettingsTestBase(bool allowed, |
| 93 bool fallback_allowed, |
| 94 bool alt_allowed, |
| 95 bool promo_allowed); |
73 virtual ~DataReductionProxySettingsTestBase(); | 96 virtual ~DataReductionProxySettingsTestBase(); |
74 | 97 |
75 void AddProxyToCommandLine(); | 98 void AddProxyToCommandLine(); |
76 | 99 |
77 virtual void SetUp() OVERRIDE; | 100 virtual void SetUp() OVERRIDE; |
78 | 101 |
79 template <class C> void ResetSettings(); | 102 template <class C> void ResetSettings(bool allowed, |
80 virtual void ResetSettings() = 0; | 103 bool fallback_allowed, |
| 104 bool alt_allowed, |
| 105 bool promo_allowed); |
| 106 virtual void ResetSettings(bool allowed, |
| 107 bool fallback_allowed, |
| 108 bool alt_allowed, |
| 109 bool promo_allowed) = 0; |
81 | 110 |
82 template <class C> void SetProbeResult( | 111 template <class C> void SetProbeResult( |
83 const std::string& test_url, | 112 const std::string& test_url, |
84 const std::string& response, | 113 const std::string& response, |
85 ProbeURLFetchResult state, | 114 ProbeURLFetchResult state, |
86 bool success, | 115 bool success, |
87 int expected_calls); | 116 int expected_calls); |
88 virtual void SetProbeResult(const std::string& test_url, | 117 virtual void SetProbeResult(const std::string& test_url, |
89 const std::string& response, | 118 const std::string& response, |
90 ProbeURLFetchResult result, | 119 ProbeURLFetchResult result, |
(...skipping 24 matching lines...) Expand all Loading... |
115 }; | 144 }; |
116 | 145 |
117 // Test implementations should be subclasses of an instantiation of this | 146 // Test implementations should be subclasses of an instantiation of this |
118 // class parameterized for whatever DataReductionProxySettings class | 147 // class parameterized for whatever DataReductionProxySettings class |
119 // is being tested. | 148 // is being tested. |
120 template <class C> | 149 template <class C> |
121 class ConcreteDataReductionProxySettingsTest | 150 class ConcreteDataReductionProxySettingsTest |
122 : public DataReductionProxySettingsTestBase { | 151 : public DataReductionProxySettingsTestBase { |
123 public: | 152 public: |
124 typedef MockDataReductionProxySettings<C> MockSettings; | 153 typedef MockDataReductionProxySettings<C> MockSettings; |
125 virtual void ResetSettings() OVERRIDE { | 154 virtual void ResetSettings(bool allowed, |
126 return DataReductionProxySettingsTestBase::ResetSettings<C>(); | 155 bool fallback_allowed, |
| 156 bool alt_allowed, |
| 157 bool promo_allowed) OVERRIDE { |
| 158 return DataReductionProxySettingsTestBase::ResetSettings<C>( |
| 159 allowed, fallback_allowed, alt_allowed, promo_allowed); |
127 } | 160 } |
128 | 161 |
129 virtual void SetProbeResult(const std::string& test_url, | 162 virtual void SetProbeResult(const std::string& test_url, |
130 const std::string& response, | 163 const std::string& response, |
131 ProbeURLFetchResult result, | 164 ProbeURLFetchResult result, |
132 bool success, | 165 bool success, |
133 int expected_calls) OVERRIDE { | 166 int expected_calls) OVERRIDE { |
134 return DataReductionProxySettingsTestBase::SetProbeResult<C>( | 167 return DataReductionProxySettingsTestBase::SetProbeResult<C>( |
135 test_url, response, result, success, expected_calls); | 168 test_url, response, result, success, expected_calls); |
136 } | 169 } |
137 }; | 170 }; |
138 | 171 |
139 } // namespace data_reduction_proxy | 172 } // namespace data_reduction_proxy |
140 | 173 |
141 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS
_TEST_UTILS_H_ | 174 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS
_TEST_UTILS_H_ |
OLD | NEW |