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

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

Issue 286013002: Added alternative configuration for the data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK fix Created 6 years, 6 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/prefs/proxy_prefs.h" 13 #include "chrome/browser/prefs/proxy_prefs.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_ test_utils.h" 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_ test_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 using testing::_; 21 using testing::_;
22 using testing::AnyNumber; 22 using testing::AnyNumber;
23 using testing::Return; 23 using testing::Return;
24 24
25 const char kDataReductionProxyOrigin[] = "https://foo.com:443/"; 25 const char kDataReductionProxyOrigin[] = "https://foo.com:443/";
26 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; 26 const char kDataReductionProxyDev[] = "http://foo-dev.com:80";
27 27
28 template <class C> 28 template <class C>
29 void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings() { 29 void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings(
30 bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed) {
31 int flags = 0;
32 if (allowed)
33 flags |= DataReductionProxyParams::kAllowed;
34 if (fallback_allowed)
35 flags |= DataReductionProxyParams::kFallbackAllowed;
36 if (alt_allowed)
37 flags |= DataReductionProxyParams::kAlternativeAllowed;
38 if (promo_allowed)
39 flags |= DataReductionProxyParams::kPromoAllowed;
30 MockDataReductionProxySettings<C>* settings = 40 MockDataReductionProxySettings<C>* settings =
31 new MockDataReductionProxySettings<C>; 41 new MockDataReductionProxySettings<C>(flags);
32 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) 42 EXPECT_CALL(*settings, GetOriginalProfilePrefs())
33 .Times(AnyNumber()) 43 .Times(AnyNumber())
34 .WillRepeatedly(Return(&pref_service_)); 44 .WillRepeatedly(Return(&pref_service_));
35 EXPECT_CALL(*settings, GetLocalStatePrefs()) 45 EXPECT_CALL(*settings, GetLocalStatePrefs())
36 .Times(AnyNumber()) 46 .Times(AnyNumber())
37 .WillRepeatedly(Return(&pref_service_)); 47 .WillRepeatedly(Return(&pref_service_));
38 EXPECT_CALL(*settings, GetURLFetcher()).Times(0); 48 EXPECT_CALL(*settings, GetURLFetcher()).Times(0);
39 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); 49 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
40 settings_.reset(settings); 50 settings_.reset(settings);
41 } 51 }
(...skipping 19 matching lines...) Expand all
61 settings, 71 settings,
62 response, 72 response,
63 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR, 73 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
64 success ? net::URLRequestStatus::SUCCESS : 74 success ? net::URLRequestStatus::SUCCESS :
65 net::URLRequestStatus::FAILED))); 75 net::URLRequestStatus::FAILED)));
66 } 76 }
67 } 77 }
68 78
69 template void 79 template void
70 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< 80 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
71 DataReductionProxySettingsAndroid>(); 81 DataReductionProxySettingsAndroid>(bool allowed,
82 bool fallback_allowed,
83 bool alt_allowed,
84 bool promo_allowed);
72 85
73 template void 86 template void
74 data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult< 87 data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult<
75 DataReductionProxySettingsAndroid>(const std::string& test_url, 88 DataReductionProxySettingsAndroid>(const std::string& test_url,
76 const std::string& response, 89 const std::string& response,
77 ProbeURLFetchResult result, 90 ProbeURLFetchResult result,
78 bool success, 91 bool success,
79 int expected_calls); 92 int expected_calls);
80 93
81 class DataReductionProxySettingsAndroidTest 94 class DataReductionProxySettingsAndroidTest
82 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest< 95 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest<
83 DataReductionProxySettingsAndroid> { 96 DataReductionProxySettingsAndroid> {
84 public: 97 public:
85 // DataReductionProxySettingsTest implementation: 98 // DataReductionProxySettingsTest implementation:
86 virtual void SetUp() OVERRIDE { 99 virtual void SetUp() OVERRIDE {
87 env_ = base::android::AttachCurrentThread(); 100 env_ = base::android::AttachCurrentThread();
88 DataReductionProxySettingsAndroid::Register(env_); 101 DataReductionProxySettingsAndroid::Register(env_);
102 DataReductionProxySettingsTestBase::AddProxyToCommandLine();
89 DataReductionProxySettingsTestBase::SetUp(); 103 DataReductionProxySettingsTestBase::SetUp();
90 } 104 }
91 105
92 DataReductionProxySettingsAndroid* Settings() { 106 DataReductionProxySettingsAndroid* Settings() {
93 return static_cast<DataReductionProxySettingsAndroid*>(settings_.get()); 107 return static_cast<DataReductionProxySettingsAndroid*>(settings_.get());
94 } 108 }
95 109
96 JNIEnv* env_; 110 JNIEnv* env_;
97 }; 111 };
98 112
99 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { 113 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) {
100 AddProxyToCommandLine();
101 // SetUp() adds the origin to the command line, which should be returned here. 114 // SetUp() adds the origin to the command line, which should be returned here.
102 ScopedJavaLocalRef<jstring> result = 115 ScopedJavaLocalRef<jstring> result =
103 Settings()->GetDataReductionProxyOrigin(env_, NULL); 116 Settings()->GetDataReductionProxyOrigin(env_, NULL);
104 ASSERT_TRUE(result.obj()); 117 ASSERT_TRUE(result.obj());
105 const base::android::JavaRef<jstring>& str_ref = result; 118 const base::android::JavaRef<jstring>& str_ref = result;
106 EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); 119 EXPECT_EQ(GURL(kDataReductionProxyOrigin),
120 GURL(ConvertJavaStringToUTF8(str_ref)));
107 } 121 }
108 122
109 TEST_F(DataReductionProxySettingsAndroidTest, 123 TEST_F(DataReductionProxySettingsAndroidTest,
110 TestGetDataReductionProxyDevOrigin) { 124 TestGetDataReductionProxyDevOrigin) {
111 AddProxyToCommandLine();
112 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 125 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
113 data_reduction_proxy::switches::kDataReductionProxyDev, 126 data_reduction_proxy::switches::kDataReductionProxyDev,
114 kDataReductionProxyDev); 127 kDataReductionProxyDev);
128 ResetSettings(true, true, false, true);
115 ScopedJavaLocalRef<jstring> result = 129 ScopedJavaLocalRef<jstring> result =
116 Settings()->GetDataReductionProxyOrigin(env_, NULL); 130 Settings()->GetDataReductionProxyOrigin(env_, NULL);
117 ASSERT_TRUE(result.obj()); 131 ASSERT_TRUE(result.obj());
118 const base::android::JavaRef<jstring>& str_ref = result; 132 const base::android::JavaRef<jstring>& str_ref = result;
119 EXPECT_EQ(kDataReductionProxyDev, ConvertJavaStringToUTF8(str_ref)); 133 EXPECT_EQ(GURL(kDataReductionProxyDev),
134 GURL(ConvertJavaStringToUTF8(str_ref)));
120 } 135 }
121 136
122 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) { 137 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) {
123 ScopedJavaLocalRef<jlongArray> result = Settings()->GetDailyContentLengths( 138 ScopedJavaLocalRef<jlongArray> result = Settings()->GetDailyContentLengths(
124 env_, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength); 139 env_, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength);
125 ASSERT_TRUE(result.obj()); 140 ASSERT_TRUE(result.obj());
126 141
127 jsize java_array_len = env_->GetArrayLength(result.obj()); 142 jsize java_array_len = env_->GetArrayLength(result.obj());
128 ASSERT_EQ(static_cast<jsize>(data_reduction_proxy::kNumDaysInHistory), 143 ASSERT_EQ(static_cast<jsize>(data_reduction_proxy::kNumDaysInHistory),
129 java_array_len); 144 java_array_len);
130 145
131 jlong value; 146 jlong value;
132 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { 147 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) {
133 env_->GetLongArrayRegion(result.obj(), i, 1, &value); 148 env_->GetLongArrayRegion(result.obj(), i, 1, &value);
134 ASSERT_EQ( 149 ASSERT_EQ(
135 static_cast<long>( 150 static_cast<long>(
136 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), 151 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2),
137 value); 152 value);
138 } 153 }
139 } 154 }
140 155
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698