| 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 #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/"; | |
| 26 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; | 25 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; |
| 27 | 26 |
| 28 template <class C> | 27 template <class C> |
| 29 void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings( | 28 void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings( |
| 30 bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed) { | 29 bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed) { |
| 31 int flags = 0; | 30 int flags = 0; |
| 32 if (allowed) | 31 if (allowed) |
| 33 flags |= DataReductionProxyParams::kAllowed; | 32 flags |= DataReductionProxyParams::kAllowed; |
| 34 if (fallback_allowed) | 33 if (fallback_allowed) |
| 35 flags |= DataReductionProxyParams::kFallbackAllowed; | 34 flags |= DataReductionProxyParams::kFallbackAllowed; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 int expected_calls); | 93 int expected_calls); |
| 95 | 94 |
| 96 class DataReductionProxySettingsAndroidTest | 95 class DataReductionProxySettingsAndroidTest |
| 97 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest< | 96 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest< |
| 98 DataReductionProxySettingsAndroid> { | 97 DataReductionProxySettingsAndroid> { |
| 99 public: | 98 public: |
| 100 // DataReductionProxySettingsTest implementation: | 99 // DataReductionProxySettingsTest implementation: |
| 101 virtual void SetUp() OVERRIDE { | 100 virtual void SetUp() OVERRIDE { |
| 102 env_ = base::android::AttachCurrentThread(); | 101 env_ = base::android::AttachCurrentThread(); |
| 103 DataReductionProxySettingsAndroid::Register(env_); | 102 DataReductionProxySettingsAndroid::Register(env_); |
| 104 DataReductionProxySettingsTestBase::AddProxyToCommandLine(); | |
| 105 DataReductionProxySettingsTestBase::SetUp(); | 103 DataReductionProxySettingsTestBase::SetUp(); |
| 106 } | 104 } |
| 107 | 105 |
| 108 DataReductionProxySettingsAndroid* Settings() { | 106 DataReductionProxySettingsAndroid* Settings() { |
| 109 return static_cast<DataReductionProxySettingsAndroid*>(settings_.get()); | 107 return static_cast<DataReductionProxySettingsAndroid*>(settings_.get()); |
| 110 } | 108 } |
| 111 | 109 |
| 112 JNIEnv* env_; | 110 JNIEnv* env_; |
| 113 }; | 111 }; |
| 114 | 112 |
| 115 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { | 113 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { |
| 116 // 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. |
| 117 ScopedJavaLocalRef<jstring> result = | 115 ScopedJavaLocalRef<jstring> result = |
| 118 Settings()->GetDataReductionProxyOrigin(env_, NULL); | 116 Settings()->GetDataReductionProxyOrigin(env_, NULL); |
| 119 ASSERT_TRUE(result.obj()); | 117 ASSERT_TRUE(result.obj()); |
| 120 const base::android::JavaRef<jstring>& str_ref = result; | 118 const base::android::JavaRef<jstring>& str_ref = result; |
| 121 EXPECT_EQ(GURL(kDataReductionProxyOrigin), | 119 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), |
| 122 GURL(ConvertJavaStringToUTF8(str_ref))); | 120 GURL(ConvertJavaStringToUTF8(str_ref))); |
| 123 } | 121 } |
| 124 | 122 |
| 125 TEST_F(DataReductionProxySettingsAndroidTest, | 123 TEST_F(DataReductionProxySettingsAndroidTest, |
| 126 TestGetDataReductionProxyDevOrigin) { | 124 TestGetDataReductionProxyDevOrigin) { |
| 127 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 125 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 128 data_reduction_proxy::switches::kDataReductionProxyDev, | 126 data_reduction_proxy::switches::kDataReductionProxyDev, |
| 129 kDataReductionProxyDev); | 127 kDataReductionProxyDev); |
| 130 ResetSettings(true, true, false, true); | 128 ResetSettings(true, true, false, true); |
| 131 ScopedJavaLocalRef<jstring> result = | 129 ScopedJavaLocalRef<jstring> result = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 148 jlong value; | 146 jlong value; |
| 149 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { | 147 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { |
| 150 env_->GetLongArrayRegion(result.obj(), i, 1, &value); | 148 env_->GetLongArrayRegion(result.obj(), i, 1, &value); |
| 151 ASSERT_EQ( | 149 ASSERT_EQ( |
| 152 static_cast<long>( | 150 static_cast<long>( |
| 153 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), | 151 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), |
| 154 value); | 152 value); |
| 155 } | 153 } |
| 156 } | 154 } |
| 157 | 155 |
| OLD | NEW |