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/"; | 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) { |
30 MockDataReductionProxySettings<C>* settings = | 31 MockDataReductionProxySettings<C>* settings = |
31 new MockDataReductionProxySettings<C>; | 32 new MockDataReductionProxySettings<C>( |
| 33 allowed, fallback_allowed, alt_allowed, promo_allowed); |
32 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) | 34 EXPECT_CALL(*settings, GetOriginalProfilePrefs()) |
33 .Times(AnyNumber()) | 35 .Times(AnyNumber()) |
34 .WillRepeatedly(Return(&pref_service_)); | 36 .WillRepeatedly(Return(&pref_service_)); |
35 EXPECT_CALL(*settings, GetLocalStatePrefs()) | 37 EXPECT_CALL(*settings, GetLocalStatePrefs()) |
36 .Times(AnyNumber()) | 38 .Times(AnyNumber()) |
37 .WillRepeatedly(Return(&pref_service_)); | 39 .WillRepeatedly(Return(&pref_service_)); |
38 EXPECT_CALL(*settings, GetURLFetcher()).Times(0); | 40 EXPECT_CALL(*settings, GetURLFetcher()).Times(0); |
39 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); | 41 EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); |
40 settings_.reset(settings); | 42 settings_.reset(settings); |
41 } | 43 } |
(...skipping 19 matching lines...) Expand all Loading... |
61 settings, | 63 settings, |
62 response, | 64 response, |
63 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR, | 65 success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR, |
64 success ? net::URLRequestStatus::SUCCESS : | 66 success ? net::URLRequestStatus::SUCCESS : |
65 net::URLRequestStatus::FAILED))); | 67 net::URLRequestStatus::FAILED))); |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 template void | 71 template void |
70 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< | 72 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< |
71 DataReductionProxySettingsAndroid>(); | 73 DataReductionProxySettingsAndroid>(bool allowed, |
| 74 bool fallback_allowed, |
| 75 bool alt_allowed, |
| 76 bool promo_allowed); |
72 | 77 |
73 template void | 78 template void |
74 data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult< | 79 data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult< |
75 DataReductionProxySettingsAndroid>(const std::string& test_url, | 80 DataReductionProxySettingsAndroid>(const std::string& test_url, |
76 const std::string& response, | 81 const std::string& response, |
77 ProbeURLFetchResult result, | 82 ProbeURLFetchResult result, |
78 bool success, | 83 bool success, |
79 int expected_calls); | 84 int expected_calls); |
80 | 85 |
81 class DataReductionProxySettingsAndroidTest | 86 class DataReductionProxySettingsAndroidTest |
(...skipping 14 matching lines...) Expand all Loading... |
96 JNIEnv* env_; | 101 JNIEnv* env_; |
97 }; | 102 }; |
98 | 103 |
99 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { | 104 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { |
100 AddProxyToCommandLine(); | 105 AddProxyToCommandLine(); |
101 // SetUp() adds the origin to the command line, which should be returned here. | 106 // SetUp() adds the origin to the command line, which should be returned here. |
102 ScopedJavaLocalRef<jstring> result = | 107 ScopedJavaLocalRef<jstring> result = |
103 Settings()->GetDataReductionProxyOrigin(env_, NULL); | 108 Settings()->GetDataReductionProxyOrigin(env_, NULL); |
104 ASSERT_TRUE(result.obj()); | 109 ASSERT_TRUE(result.obj()); |
105 const base::android::JavaRef<jstring>& str_ref = result; | 110 const base::android::JavaRef<jstring>& str_ref = result; |
106 EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); | 111 EXPECT_EQ(GURL(kDataReductionProxyOrigin), |
| 112 GURL(ConvertJavaStringToUTF8(str_ref))); |
107 } | 113 } |
108 | 114 |
109 TEST_F(DataReductionProxySettingsAndroidTest, | 115 TEST_F(DataReductionProxySettingsAndroidTest, |
110 TestGetDataReductionProxyDevOrigin) { | 116 TestGetDataReductionProxyDevOrigin) { |
111 AddProxyToCommandLine(); | 117 AddProxyToCommandLine(); |
112 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 118 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
113 data_reduction_proxy::switches::kDataReductionProxyDev, | 119 data_reduction_proxy::switches::kDataReductionProxyDev, |
114 kDataReductionProxyDev); | 120 kDataReductionProxyDev); |
| 121 ResetSettings(true, true, false, true); |
115 ScopedJavaLocalRef<jstring> result = | 122 ScopedJavaLocalRef<jstring> result = |
116 Settings()->GetDataReductionProxyOrigin(env_, NULL); | 123 Settings()->GetDataReductionProxyOrigin(env_, NULL); |
117 ASSERT_TRUE(result.obj()); | 124 ASSERT_TRUE(result.obj()); |
118 const base::android::JavaRef<jstring>& str_ref = result; | 125 const base::android::JavaRef<jstring>& str_ref = result; |
119 EXPECT_EQ(kDataReductionProxyDev, ConvertJavaStringToUTF8(str_ref)); | 126 EXPECT_EQ(GURL(kDataReductionProxyDev), |
| 127 GURL(ConvertJavaStringToUTF8(str_ref))); |
120 } | 128 } |
121 | 129 |
122 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) { | 130 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) { |
123 ScopedJavaLocalRef<jlongArray> result = Settings()->GetDailyContentLengths( | 131 ScopedJavaLocalRef<jlongArray> result = Settings()->GetDailyContentLengths( |
124 env_, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength); | 132 env_, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength); |
125 ASSERT_TRUE(result.obj()); | 133 ASSERT_TRUE(result.obj()); |
126 | 134 |
127 jsize java_array_len = env_->GetArrayLength(result.obj()); | 135 jsize java_array_len = env_->GetArrayLength(result.obj()); |
128 ASSERT_EQ(static_cast<jsize>(data_reduction_proxy::kNumDaysInHistory), | 136 ASSERT_EQ(static_cast<jsize>(data_reduction_proxy::kNumDaysInHistory), |
129 java_array_len); | 137 java_array_len); |
130 | 138 |
131 jlong value; | 139 jlong value; |
132 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { | 140 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) { |
133 env_->GetLongArrayRegion(result.obj(), i, 1, &value); | 141 env_->GetLongArrayRegion(result.obj(), i, 1, &value); |
134 ASSERT_EQ( | 142 ASSERT_EQ( |
135 static_cast<long>( | 143 static_cast<long>( |
136 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), | 144 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), |
137 value); | 145 value); |
138 } | 146 } |
139 } | 147 } |
140 | 148 |
OLD | NEW |