Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc

Issue 893003002: Data Reduction Proxy class ownership updates and Settings cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
14 #include "chrome/browser/prefs/proxy_prefs.h" 14 #include "chrome/browser/prefs/proxy_prefs.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings_test_utils.h" 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings_test_utils.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 using testing::_; 23 using testing::_;
23 using testing::AnyNumber; 24 using testing::AnyNumber;
24 using testing::Return; 25 using testing::Return;
25 26
26 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; 27 const char kDataReductionProxyDev[] = "http://foo-dev.com:80";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 flags |= DataReductionProxyParams::kAllowed; 60 flags |= DataReductionProxyParams::kAllowed;
60 if (fallback_allowed) 61 if (fallback_allowed)
61 flags |= DataReductionProxyParams::kFallbackAllowed; 62 flags |= DataReductionProxyParams::kFallbackAllowed;
62 if (alt_allowed) 63 if (alt_allowed)
63 flags |= DataReductionProxyParams::kAlternativeAllowed; 64 flags |= DataReductionProxyParams::kAlternativeAllowed;
64 if (promo_allowed) 65 if (promo_allowed)
65 flags |= DataReductionProxyParams::kPromoAllowed; 66 flags |= DataReductionProxyParams::kPromoAllowed;
66 if (holdback) 67 if (holdback)
67 flags |= DataReductionProxyParams::kHoldback; 68 flags |= DataReductionProxyParams::kHoldback;
68 MockDataReductionProxySettings<C>* settings = 69 MockDataReductionProxySettings<C>* settings =
69 new MockDataReductionProxySettings<C>(flags); 70 new MockDataReductionProxySettings<C>();
71 MockDataReductionProxyConfig* config =
72 static_cast<MockDataReductionProxyConfig*>(config_.get());
bengr 2015/02/03 21:51:58 To avoid this dance, couldn't config_ just be a Mo
jeremyim 2015/02/04 01:31:21 It actually already is... Oops! Done.
73 settings->config_ = config;
74 config->ResetParamsForTest(flags);
75 settings->UpdateConfigValues();
70 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) 76 EXPECT_CALL(*settings, GetOriginalProfilePrefs())
71 .Times(AnyNumber()) 77 .Times(AnyNumber())
72 .WillRepeatedly(Return(&pref_service_)); 78 .WillRepeatedly(Return(&pref_service_));
73 EXPECT_CALL(*settings, GetLocalStatePrefs()) 79 EXPECT_CALL(*settings, GetLocalStatePrefs())
74 .Times(AnyNumber()) 80 .Times(AnyNumber())
75 .WillRepeatedly(Return(&pref_service_)); 81 .WillRepeatedly(Return(&pref_service_));
76 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
77 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
78 settings_.reset(settings); 82 settings_.reset(settings);
79 settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get()); 83 settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get());
80 } 84 }
81 85
82 template <class C>
83 void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult(
84 const std::string& test_url,
85 const std::string& response,
86 ProbeURLFetchResult result,
87 bool success,
88 int expected_calls) {
89 MockDataReductionProxySettings<C>* settings =
90 static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
91 if (0 == expected_calls) {
92 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
93 EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
94 } else {
95 EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
96 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
97 .Times(expected_calls)
98 .WillRepeatedly(Return(new net::FakeURLFetcher(
99 GURL(test_url),
100 settings,
101 response,
102 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
103 success ? net::URLRequestStatus::SUCCESS :
104 net::URLRequestStatus::FAILED)));
105 }
106 }
107
108 template void 86 template void
109 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< 87 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
110 DataReductionProxyChromeSettings>(bool allowed, 88 DataReductionProxyChromeSettings>(bool allowed,
111 bool fallback_allowed, 89 bool fallback_allowed,
112 bool alt_allowed, 90 bool alt_allowed,
113 bool promo_allowed, 91 bool promo_allowed,
114 bool holdback); 92 bool holdback);
115 93
116 template void
117 data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult<
118 DataReductionProxyChromeSettings>(const std::string& test_url,
119 const std::string& response,
120 ProbeURLFetchResult result,
121 bool success,
122 int expected_calls);
123
124 class DataReductionProxySettingsAndroidTest 94 class DataReductionProxySettingsAndroidTest
125 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest< 95 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest<
126 DataReductionProxyChromeSettings> { 96 DataReductionProxyChromeSettings> {
127 public: 97 public:
128 // DataReductionProxySettingsTest implementation: 98 // DataReductionProxySettingsTest implementation:
129 virtual void SetUp() override { 99 virtual void SetUp() override {
130 env_ = base::android::AttachCurrentThread(); 100 env_ = base::android::AttachCurrentThread();
131 DataReductionProxySettingsAndroid::Register(env_); 101 DataReductionProxySettingsAndroid::Register(env_);
132 DataReductionProxySettingsTestBase::SetUp(); 102 DataReductionProxySettingsTestBase::SetUp();
133 ResetSettingsAndroid(); 103 ResetSettingsAndroid();
(...skipping 15 matching lines...) Expand all
149 scoped_ptr<DataReductionProxySettingsAndroid> settings_android_; 119 scoped_ptr<DataReductionProxySettingsAndroid> settings_android_;
150 JNIEnv* env_; 120 JNIEnv* env_;
151 }; 121 };
152 122
153 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { 123 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) {
154 // SetUp() adds the origin to the command line, which should be returned here. 124 // SetUp() adds the origin to the command line, which should be returned here.
155 ScopedJavaLocalRef<jstring> result = 125 ScopedJavaLocalRef<jstring> result =
156 SettingsAndroid()->GetDataReductionProxyOrigin(env_, NULL); 126 SettingsAndroid()->GetDataReductionProxyOrigin(env_, NULL);
157 ASSERT_TRUE(result.obj()); 127 ASSERT_TRUE(result.obj());
158 const base::android::JavaRef<jstring>& str_ref = result; 128 const base::android::JavaRef<jstring>& str_ref = result;
159 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), 129 EXPECT_EQ(GURL(config_->test_params()->DefaultOrigin()),
160 GURL(ConvertJavaStringToUTF8(str_ref))); 130 GURL(ConvertJavaStringToUTF8(str_ref)));
161 } 131 }
162 132
163 TEST_F(DataReductionProxySettingsAndroidTest, 133 TEST_F(DataReductionProxySettingsAndroidTest,
164 TestGetDataReductionProxyDevOrigin) { 134 TestGetDataReductionProxyDevOrigin) {
165 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 135 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
166 data_reduction_proxy::switches::kDataReductionProxyDev, 136 data_reduction_proxy::switches::kDataReductionProxyDev,
167 kDataReductionProxyDev); 137 kDataReductionProxyDev);
168 ResetSettings(true, true, false, true, false); 138 ResetSettings(true, true, false, true, false);
169 ResetSettingsAndroid(); 139 ResetSettingsAndroid();
(...skipping 17 matching lines...) Expand all
187 157
188 jlong value; 158 jlong value;
189 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { 159 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) {
190 env_->GetLongArrayRegion(result.obj(), i, 1, &value); 160 env_->GetLongArrayRegion(result.obj(), i, 1, &value);
191 ASSERT_EQ( 161 ASSERT_EQ(
192 static_cast<long>( 162 static_cast<long>(
193 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), value); 163 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), value);
194 } 164 }
195 } 165 }
196 166
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698