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

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

Issue 30883003: Simple fallback implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patched
Patch Set: Created 7 years, 1 month 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_unittest.h" 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.h"
6 6
7 7
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/testing_pref_service.h" 15 #include "base/prefs/testing_pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" 17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
18 #include "chrome/browser/prefs/proxy_prefs.h" 18 #include "chrome/browser/prefs/proxy_prefs.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 19 #include "chrome/browser/prefs/scoped_user_pref_update.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/metrics/variations/variations_util.h" 21 #include "chrome/common/metrics/variations/variations_util.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "components/variations/entropy_provider.h" 23 #include "components/variations/entropy_provider.h"
24 #include "net/url_request/test_url_fetcher_factory.h" 24 #include "net/url_request/test_url_fetcher_factory.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 const char kDataReductionProxyOrigin[] = "https://foo:443/"; 28 const char kDataReductionProxyOrigin[] = "https://foo.com:443/";
29 const char kDataReductionProxyOriginHostPort[] = "foo:443"; 29 const char kDataReductionProxyOriginPAC[] = "HTTPS foo.com:443;";
30 const char kDataReductionProxyFallback[] = "http://bar.com:80/";
31 const char kDataReductionProxyFallbackPAC[] = "HTTP bar.com:80;";
30 const char kDataReductionProxyAuth[] = "12345"; 32 const char kDataReductionProxyAuth[] = "12345";
31 33
32 class TestDataReductionProxySettingsAndroid 34 class TestDataReductionProxySettingsAndroid
33 : public DataReductionProxySettingsAndroid { 35 : public DataReductionProxySettingsAndroid {
34 public: 36 public:
35 TestDataReductionProxySettingsAndroid(JNIEnv* env, 37 TestDataReductionProxySettingsAndroid(JNIEnv* env,
36 jobject obj, 38 jobject obj,
37 PrefService* profile_prefs, 39 PrefService* profile_prefs,
38 PrefService* local_state_prefs) 40 PrefService* local_state_prefs)
39 : DataReductionProxySettingsAndroid(env, obj), 41 : DataReductionProxySettingsAndroid(env, obj),
40 success_(false), 42 success_(false),
41 fake_fetcher_request_count_(0), 43 fake_fetcher_request_count_(0),
42 profile_prefs_(profile_prefs), 44 profile_prefs_(profile_prefs),
43 local_state_prefs_(local_state_prefs) { 45 local_state_prefs_(local_state_prefs) {
44 } 46 }
45 47
46 // DataReductionProxySettings implementation: 48 // TODO(marq): Replace virtual methods with MOCKs.
49 // DataReductionProxySettingsAndroid implementation:
47 virtual net::URLFetcher* GetURLFetcher() OVERRIDE { 50 virtual net::URLFetcher* GetURLFetcher() OVERRIDE {
48 if (test_url_.empty()) 51 if (test_url_.empty())
49 return NULL; 52 return NULL;
50 net::URLFetcher* fetcher = 53 net::URLFetcher* fetcher =
51 new net::FakeURLFetcher(GURL(test_url_), this, response_, success_); 54 new net::FakeURLFetcher(GURL(test_url_), this, response_, success_);
52 fake_fetcher_request_count_++; 55 fake_fetcher_request_count_++;
53 return fetcher; 56 return fetcher;
54 } 57 }
55 58
56 virtual PrefService* GetOriginalProfilePrefs() OVERRIDE { 59 virtual PrefService* GetOriginalProfilePrefs() OVERRIDE {
57 return profile_prefs_; 60 return profile_prefs_;
58 } 61 }
62
59 virtual PrefService* GetLocalStatePrefs() OVERRIDE { 63 virtual PrefService* GetLocalStatePrefs() OVERRIDE {
60 return local_state_prefs_; 64 return local_state_prefs_;
61 } 65 }
62 66
63 void set_probe_result(const std::string& test_url, 67 void set_probe_result(const std::string& test_url,
64 const std::string& response, 68 const std::string& response,
65 bool success) { 69 bool success) {
66 test_url_ = test_url; 70 test_url_ = test_url;
67 response_ = response; 71 response_ = response;
68 success_ = success; 72 success_ = success;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { 129 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) {
126 AddProxyToCommandLine(); 130 AddProxyToCommandLine();
127 // SetUp() adds the origin to the command line, which should be returned here. 131 // SetUp() adds the origin to the command line, which should be returned here.
128 ScopedJavaLocalRef<jstring> result = 132 ScopedJavaLocalRef<jstring> result =
129 settings_->GetDataReductionProxyOrigin(env_, NULL); 133 settings_->GetDataReductionProxyOrigin(env_, NULL);
130 ASSERT_TRUE(result.obj()); 134 ASSERT_TRUE(result.obj());
131 const base::android::JavaRef<jstring>& str_ref = result; 135 const base::android::JavaRef<jstring>& str_ref = result;
132 EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); 136 EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref));
133 } 137 }
134 138
135 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyAuth) {
136 AddProxyToCommandLine();
137 // SetUp() adds the auth string to the command line, which should be returned
138 // here.
139 ScopedJavaLocalRef<jstring> result =
140 settings_->GetDataReductionProxyAuth(env_, NULL);
141 ASSERT_TRUE(result.obj());
142 const base::android::JavaRef<jstring>& str_ref = result;
143 EXPECT_EQ(kDataReductionProxyAuth, ConvertJavaStringToUTF8(str_ref));
144 }
145
146 // Test that the auth value set by preprocessor directive is not returned
147 // when an origin is set via a switch. This test only does anything useful in
148 // Chrome builds.
149 TEST_F(DataReductionProxySettingsAndroidTest,
150 TestGetDataReductionProxyAuthWithOriginSetViaSwitch) {
151 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
152 switches::kSpdyProxyAuthOrigin, kDataReductionProxyOrigin);
153 // SetUp() adds the auth string to the command line, which should be returned
154 // here.
155 ScopedJavaLocalRef<jstring> result =
156 settings_->GetDataReductionProxyAuth(env_, NULL);
157 ASSERT_TRUE(result.obj());
158 const base::android::JavaRef<jstring>& str_ref = result;
159 EXPECT_EQ(std::string(), ConvertJavaStringToUTF8(str_ref));
160 }
161
162 // Confirm that the bypass rule functions generate the intended JavaScript 139 // Confirm that the bypass rule functions generate the intended JavaScript
163 // code for the Proxy PAC. 140 // code for the Proxy PAC.
164 TEST_F(DataReductionProxySettingsAndroidTest, TestBypassPACRules) { 141 TEST_F(DataReductionProxySettingsAndroidTest, TestBypassPACRules) {
165 settings_->AddURLPatternToBypass("http://foo.com/*"); 142 settings_->AddURLPatternToBypass("http://foo.com/*");
166 settings_->AddHostPatternToBypass("bar.com"); 143 settings_->AddHostPatternToBypass("bar.com");
167 144
168 EXPECT_EQ(settings_->pac_bypass_rules_.size(), 1u); 145 EXPECT_EQ(settings_->pac_bypass_rules_.size(), 1u);
169 EXPECT_EQ("shExpMatch(url, 'http://foo.com/*')", 146 EXPECT_EQ("shExpMatch(url, 'http://foo.com/*')",
170 settings_->pac_bypass_rules_[0]); 147 settings_->pac_bypass_rules_[0]);
171 148
172 EXPECT_EQ(settings_->BypassRules().size(), 1u); 149 EXPECT_EQ(settings_->BypassRules().size(), 1u);
173 EXPECT_EQ("bar.com", settings_->BypassRules()[0]); 150 EXPECT_EQ("bar.com", settings_->BypassRules()[0]);
174 } 151 }
175 152
176 TEST_F(DataReductionProxySettingsAndroidTest, TestSetProxyPac) { 153 TEST_F(DataReductionProxySettingsAndroidTest, TestSetProxyPac) {
154 AddProxyToCommandLine();
177 settings_->AddDefaultProxyBypassRules(); 155 settings_->AddDefaultProxyBypassRules();
156 std::string raw_pac = settings_->GetProxyPacScript();
157 EXPECT_NE(raw_pac.find(kDataReductionProxyOriginPAC), std::string::npos);
158 EXPECT_NE(raw_pac.find(kDataReductionProxyFallbackPAC), std::string::npos);;
178 std::string pac; 159 std::string pac;
179 base::Base64Encode(settings_->GetProxyPacScript(), &pac); 160 base::Base64Encode(raw_pac, &pac);
180 std::string expected_pac_url = 161 std::string expected_pac_url =
181 "data:application/x-ns-proxy-autoconfig;base64," + pac; 162 "data:application/x-ns-proxy-autoconfig;base64," + pac;
182 // Test setting the PAC, without generating histograms. 163 // Test setting the PAC, without generating histograms.
183 settings_->SetHasTurnedOn(); 164 settings_->SetHasTurnedOn();
184 settings_->SetProxyConfigs(true, false); 165 settings_->SetProxyConfigs(true, false);
185 CheckProxyPacPref(expected_pac_url, 166 CheckProxyPacPref(expected_pac_url,
186 ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT)); 167 ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT));
187 168
188 // Test disabling the PAC, without generating histograms. 169 // Test disabling the PAC, without generating histograms.
189 settings_->SetHasTurnedOff(); 170 settings_->SetHasTurnedOff();
(...skipping 10 matching lines...) Expand all
200 ASSERT_EQ(static_cast<jsize>(spdyproxy::kNumDaysInHistory), java_array_len); 181 ASSERT_EQ(static_cast<jsize>(spdyproxy::kNumDaysInHistory), java_array_len);
201 182
202 jlong value; 183 jlong value;
203 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { 184 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) {
204 env_->GetLongArrayRegion(result.obj(), i, 1, &value); 185 env_->GetLongArrayRegion(result.obj(), i, 1, &value);
205 ASSERT_EQ( 186 ASSERT_EQ(
206 static_cast<long>((spdyproxy::kNumDaysInHistory - 1 - i) * 2), value); 187 static_cast<long>((spdyproxy::kNumDaysInHistory - 1 - i) * 2), value);
207 } 188 }
208 } 189 }
209 190
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698