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_unittest.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.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/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.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/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/metrics/variations/variations_util.h" | 20 #include "chrome/common/metrics/variations/variations_util.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "components/variations/entropy_provider.h" | 22 #include "components/variations/entropy_provider.h" |
23 #include "net/url_request/test_url_fetcher_factory.h" | 23 #include "net/url_request/test_url_fetcher_factory.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.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.com:443/"; | 28 const char kDataReductionProxyOrigin[] = "https://foo.com:443/"; |
| 29 const char kDataReductionProxyDevHost[] = "http://foo-dev.com:80"; |
29 const char kDataReductionProxyOriginPAC[] = "HTTPS foo.com:443;"; | 30 const char kDataReductionProxyOriginPAC[] = "HTTPS foo.com:443;"; |
30 const char kDataReductionProxyFallbackPAC[] = "PROXY bar.com:80;"; | 31 const char kDataReductionProxyFallbackPAC[] = "PROXY bar.com:80;"; |
31 | 32 |
32 class DataReductionProxySettingsAndroidTest | 33 class DataReductionProxySettingsAndroidTest |
33 : public ConcreteDataReductionProxySettingsTest< | 34 : public ConcreteDataReductionProxySettingsTest< |
34 DataReductionProxySettingsAndroid> { | 35 DataReductionProxySettingsAndroid> { |
35 public: | 36 public: |
36 // DataReductionProxySettingsTest implementation: | 37 // DataReductionProxySettingsTest implementation: |
37 virtual void SetUp() OVERRIDE { | 38 virtual void SetUp() OVERRIDE { |
38 env_ = base::android::AttachCurrentThread(); | 39 env_ = base::android::AttachCurrentThread(); |
(...skipping 22 matching lines...) Expand all Loading... |
61 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { | 62 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { |
62 AddProxyToCommandLine(); | 63 AddProxyToCommandLine(); |
63 // SetUp() adds the origin to the command line, which should be returned here. | 64 // SetUp() adds the origin to the command line, which should be returned here. |
64 ScopedJavaLocalRef<jstring> result = | 65 ScopedJavaLocalRef<jstring> result = |
65 Settings()->GetDataReductionProxyOrigin(env_, NULL); | 66 Settings()->GetDataReductionProxyOrigin(env_, NULL); |
66 ASSERT_TRUE(result.obj()); | 67 ASSERT_TRUE(result.obj()); |
67 const base::android::JavaRef<jstring>& str_ref = result; | 68 const base::android::JavaRef<jstring>& str_ref = result; |
68 EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); | 69 EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); |
69 } | 70 } |
70 | 71 |
| 72 TEST_F(DataReductionProxySettingsAndroidTest, |
| 73 TestGetDataReductionProxyDevOrigin) { |
| 74 AddProxyToCommandLine(); |
| 75 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 76 switches::kSpdyProxyDevAuthOrigin, kDataReductionProxyDevHost); |
| 77 ScopedJavaLocalRef<jstring> result = |
| 78 Settings()->GetDataReductionProxyOrigin(env_, NULL); |
| 79 ASSERT_TRUE(result.obj()); |
| 80 const base::android::JavaRef<jstring>& str_ref = result; |
| 81 EXPECT_EQ(kDataReductionProxyDevHost, ConvertJavaStringToUTF8(str_ref)); |
| 82 } |
| 83 |
71 // Confirm that the bypass rule functions generate the intended JavaScript | 84 // Confirm that the bypass rule functions generate the intended JavaScript |
72 // code for the Proxy PAC. | 85 // code for the Proxy PAC. |
73 TEST_F(DataReductionProxySettingsAndroidTest, TestBypassPACRules) { | 86 TEST_F(DataReductionProxySettingsAndroidTest, TestBypassPACRules) { |
74 Settings()->AddURLPatternToBypass("http://foo.com/*"); | 87 Settings()->AddURLPatternToBypass("http://foo.com/*"); |
75 Settings()->AddHostPatternToBypass("bar.com"); | 88 Settings()->AddHostPatternToBypass("bar.com"); |
76 | 89 |
77 EXPECT_EQ(Settings()->pac_bypass_rules_.size(), 1u); | 90 EXPECT_EQ(Settings()->pac_bypass_rules_.size(), 1u); |
78 EXPECT_EQ("shExpMatch(url, 'http://foo.com/*')", | 91 EXPECT_EQ("shExpMatch(url, 'http://foo.com/*')", |
79 Settings()->pac_bypass_rules_[0]); | 92 Settings()->pac_bypass_rules_[0]); |
80 | 93 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 ASSERT_EQ(static_cast<jsize>(spdyproxy::kNumDaysInHistory), java_array_len); | 139 ASSERT_EQ(static_cast<jsize>(spdyproxy::kNumDaysInHistory), java_array_len); |
127 | 140 |
128 jlong value; | 141 jlong value; |
129 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { | 142 for (size_t i = 0; i < spdyproxy::kNumDaysInHistory; ++i) { |
130 env_->GetLongArrayRegion(result.obj(), i, 1, &value); | 143 env_->GetLongArrayRegion(result.obj(), i, 1, &value); |
131 ASSERT_EQ( | 144 ASSERT_EQ( |
132 static_cast<long>((spdyproxy::kNumDaysInHistory - 1 - i) * 2), value); | 145 static_cast<long>((spdyproxy::kNumDaysInHistory - 1 - i) * 2), value); |
133 } | 146 } |
134 } | 147 } |
135 | 148 |
OLD | NEW |