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

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"
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h" 22 #include "url/gurl.h"
21 23
22 using testing::_; 24 using testing::_;
23 using testing::AnyNumber; 25 using testing::AnyNumber;
24 using testing::Return; 26 using testing::Return;
25 27
26 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; 28 const char kDataReductionProxyDev[] = "http://foo-dev.com:80";
27 29
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 flags |= DataReductionProxyParams::kAllowed; 61 flags |= DataReductionProxyParams::kAllowed;
60 if (fallback_allowed) 62 if (fallback_allowed)
61 flags |= DataReductionProxyParams::kFallbackAllowed; 63 flags |= DataReductionProxyParams::kFallbackAllowed;
62 if (alt_allowed) 64 if (alt_allowed)
63 flags |= DataReductionProxyParams::kAlternativeAllowed; 65 flags |= DataReductionProxyParams::kAlternativeAllowed;
64 if (promo_allowed) 66 if (promo_allowed)
65 flags |= DataReductionProxyParams::kPromoAllowed; 67 flags |= DataReductionProxyParams::kPromoAllowed;
66 if (holdback) 68 if (holdback)
67 flags |= DataReductionProxyParams::kHoldback; 69 flags |= DataReductionProxyParams::kHoldback;
68 MockDataReductionProxySettings<C>* settings = 70 MockDataReductionProxySettings<C>* settings =
69 new MockDataReductionProxySettings<C>(flags); 71 new MockDataReductionProxySettings<C>();
72 settings->config_ = test_context_->config();
73 test_context_->config()->ResetParamFlagsForTest(flags);
74 settings->UpdateConfigValues();
70 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) 75 EXPECT_CALL(*settings, GetOriginalProfilePrefs())
71 .Times(AnyNumber()) 76 .Times(AnyNumber())
72 .WillRepeatedly(Return(&pref_service_)); 77 .WillRepeatedly(Return(&pref_service_));
73 EXPECT_CALL(*settings, GetLocalStatePrefs()) 78 EXPECT_CALL(*settings, GetLocalStatePrefs())
74 .Times(AnyNumber()) 79 .Times(AnyNumber())
75 .WillRepeatedly(Return(&pref_service_)); 80 .WillRepeatedly(Return(&pref_service_));
76 EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
77 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
78 settings_.reset(settings); 81 settings_.reset(settings);
79 settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get()); 82 settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get());
80 } 83 }
81 84
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 85 template void
109 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< 86 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
110 DataReductionProxyChromeSettings>(bool allowed, 87 DataReductionProxyChromeSettings>(bool allowed,
111 bool fallback_allowed, 88 bool fallback_allowed,
112 bool alt_allowed, 89 bool alt_allowed,
113 bool promo_allowed, 90 bool promo_allowed,
114 bool holdback); 91 bool holdback);
115 92
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 93 class DataReductionProxySettingsAndroidTest
125 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest< 94 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest<
126 DataReductionProxyChromeSettings> { 95 DataReductionProxyChromeSettings> {
127 public: 96 public:
128 // DataReductionProxySettingsTest implementation: 97 // DataReductionProxySettingsTest implementation:
129 virtual void SetUp() override { 98 virtual void SetUp() override {
130 env_ = base::android::AttachCurrentThread(); 99 env_ = base::android::AttachCurrentThread();
131 DataReductionProxySettingsAndroid::Register(env_); 100 DataReductionProxySettingsAndroid::Register(env_);
132 DataReductionProxySettingsTestBase::SetUp(); 101 DataReductionProxySettingsTestBase::SetUp();
133 ResetSettingsAndroid(); 102 ResetSettingsAndroid();
(...skipping 15 matching lines...) Expand all
149 scoped_ptr<DataReductionProxySettingsAndroid> settings_android_; 118 scoped_ptr<DataReductionProxySettingsAndroid> settings_android_;
150 JNIEnv* env_; 119 JNIEnv* env_;
151 }; 120 };
152 121
153 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { 122 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) {
154 // SetUp() adds the origin to the command line, which should be returned here. 123 // SetUp() adds the origin to the command line, which should be returned here.
155 ScopedJavaLocalRef<jstring> result = 124 ScopedJavaLocalRef<jstring> result =
156 SettingsAndroid()->GetDataReductionProxyOrigin(env_, NULL); 125 SettingsAndroid()->GetDataReductionProxyOrigin(env_, NULL);
157 ASSERT_TRUE(result.obj()); 126 ASSERT_TRUE(result.obj());
158 const base::android::JavaRef<jstring>& str_ref = result; 127 const base::android::JavaRef<jstring>& str_ref = result;
159 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), 128 EXPECT_EQ(GURL(test_context_->config()->test_params()->DefaultOrigin()),
160 GURL(ConvertJavaStringToUTF8(str_ref))); 129 GURL(ConvertJavaStringToUTF8(str_ref)));
161 } 130 }
162 131
163 TEST_F(DataReductionProxySettingsAndroidTest, 132 TEST_F(DataReductionProxySettingsAndroidTest,
164 TestGetDataReductionProxyDevOrigin) { 133 TestGetDataReductionProxyDevOrigin) {
165 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 134 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
166 data_reduction_proxy::switches::kDataReductionProxyDev, 135 data_reduction_proxy::switches::kDataReductionProxyDev,
167 kDataReductionProxyDev); 136 kDataReductionProxyDev);
168 ResetSettings(true, true, false, true, false); 137 ResetSettings(true, true, false, true, false);
169 ResetSettingsAndroid(); 138 ResetSettingsAndroid();
(...skipping 17 matching lines...) Expand all
187 156
188 jlong value; 157 jlong value;
189 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { 158 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) {
190 env_->GetLongArrayRegion(result.obj(), i, 1, &value); 159 env_->GetLongArrayRegion(result.obj(), i, 1, &value);
191 ASSERT_EQ( 160 ASSERT_EQ(
192 static_cast<long>( 161 static_cast<long>(
193 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), value); 162 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), value);
194 } 163 }
195 } 164 }
196 165
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698