| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_UNITTEST_H_ | 5 #ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_UNITTEST_H_ |
| 6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_UNITTEST_H_ | 6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_UNITTEST_H_ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram_samples.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
| 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" | 12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" |
| 12 #include "net/url_request/test_url_fetcher_factory.h" | 13 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 class PrefService; | 17 class PrefService; |
| 17 class TestingPrefServiceSimple; | 18 class TestingPrefServiceSimple; |
| 18 | 19 |
| 20 using spdyproxy::ProbeURLFetchResult; |
| 21 using spdyproxy::ProxyStartupState; |
| 22 |
| 19 template <class C> | 23 template <class C> |
| 20 class MockDataReductionProxySettings : public C { | 24 class MockDataReductionProxySettings : public C { |
| 21 public: | 25 public: |
| 22 MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); | 26 MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); |
| 23 MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); | 27 MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); |
| 24 MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); | 28 MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); |
| 25 MOCK_METHOD3(LogProxyState, void( | 29 MOCK_METHOD3(LogProxyState, void( |
| 26 bool enabled, bool restricted, bool at_startup)); | 30 bool enabled, bool restricted, bool at_startup)); |
| 31 MOCK_METHOD1(RecordProbeURLFetchResult, |
| 32 void(ProbeURLFetchResult result)); |
| 33 MOCK_METHOD1(RecordStartupState, |
| 34 void(ProxyStartupState state)); |
| 27 | 35 |
| 28 // SetProxyConfigs should always call LogProxyState exactly once. | 36 // SetProxyConfigs should always call LogProxyState exactly once. |
| 29 virtual void SetProxyConfigs( | 37 virtual void SetProxyConfigs( |
| 30 bool enabled, bool restricted, bool at_startup) OVERRIDE { | 38 bool enabled, bool restricted, bool at_startup) OVERRIDE { |
| 31 EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); | 39 EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); |
| 32 C::SetProxyConfigs(enabled, restricted, at_startup); | 40 C::SetProxyConfigs(enabled, restricted, at_startup); |
| 33 } | 41 } |
| 34 }; | 42 }; |
| 35 | 43 |
| 36 class DataReductionProxySettingsTestBase : public testing::Test { | 44 class DataReductionProxySettingsTestBase : public testing::Test { |
| 37 public: | 45 public: |
| 38 DataReductionProxySettingsTestBase(); | 46 DataReductionProxySettingsTestBase(); |
| 39 virtual ~DataReductionProxySettingsTestBase(); | 47 virtual ~DataReductionProxySettingsTestBase(); |
| 40 | 48 |
| 41 void AddProxyToCommandLine(); | 49 void AddProxyToCommandLine(); |
| 42 | 50 |
| 43 virtual void SetUp() OVERRIDE; | 51 virtual void SetUp() OVERRIDE; |
| 44 | 52 |
| 45 template <class C> void ResetSettings(); | 53 template <class C> void ResetSettings(); |
| 46 virtual void ResetSettings() = 0; | 54 virtual void ResetSettings() = 0; |
| 47 | 55 |
| 48 template <class C> void SetProbeResult( | 56 template <class C> void SetProbeResult( |
| 49 const std::string& test_url, | 57 const std::string& test_url, |
| 50 const std::string& response, | 58 const std::string& response, |
| 59 ProbeURLFetchResult state, |
| 51 bool success, | 60 bool success, |
| 52 int expected_calls); | 61 int expected_calls); |
| 53 virtual void SetProbeResult(const std::string& test_url, | 62 virtual void SetProbeResult(const std::string& test_url, |
| 54 const std::string& response, | 63 const std::string& response, |
| 64 ProbeURLFetchResult result, |
| 55 bool success, | 65 bool success, |
| 56 int expected_calls) = 0; | 66 int expected_calls) = 0; |
| 57 | 67 |
| 58 void CheckProxyPref(const std::string& expected_servers, | 68 void CheckProxyPref(const std::string& expected_servers, |
| 59 const std::string& expected_mode); | 69 const std::string& expected_mode); |
| 60 void CheckProxyConfigs(bool expected_enabled, bool expected_restricted); | 70 void CheckProxyConfigs(bool expected_enabled, bool expected_restricted); |
| 61 void CheckProbe(bool initially_enabled, | 71 void CheckProbe(bool initially_enabled, |
| 62 const std::string& probe_url, | 72 const std::string& probe_url, |
| 63 const std::string& response, | 73 const std::string& response, |
| 64 bool request_success, | 74 bool request_success, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 class ConcreteDataReductionProxySettingsTest | 95 class ConcreteDataReductionProxySettingsTest |
| 86 : public DataReductionProxySettingsTestBase { | 96 : public DataReductionProxySettingsTestBase { |
| 87 public: | 97 public: |
| 88 typedef MockDataReductionProxySettings<C> MockSettings; | 98 typedef MockDataReductionProxySettings<C> MockSettings; |
| 89 virtual void ResetSettings() OVERRIDE { | 99 virtual void ResetSettings() OVERRIDE { |
| 90 return DataReductionProxySettingsTestBase::ResetSettings<C>(); | 100 return DataReductionProxySettingsTestBase::ResetSettings<C>(); |
| 91 } | 101 } |
| 92 | 102 |
| 93 virtual void SetProbeResult(const std::string& test_url, | 103 virtual void SetProbeResult(const std::string& test_url, |
| 94 const std::string& response, | 104 const std::string& response, |
| 105 ProbeURLFetchResult result, |
| 95 bool success, | 106 bool success, |
| 96 int expected_calls) OVERRIDE { | 107 int expected_calls) OVERRIDE { |
| 97 return DataReductionProxySettingsTestBase::SetProbeResult<C>( | 108 return DataReductionProxySettingsTestBase::SetProbeResult<C>( |
| 98 test_url, response, success, expected_calls); | 109 test_url, response, result, success, expected_calls); |
| 99 } | 110 } |
| 100 }; | 111 }; |
| 101 | 112 |
| 102 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_UNITTEST_H
_ | 113 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_UNITTEST_H
_ |
| OLD | NEW |