Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / net / spdyproxy / data_reduction_proxy_settings_unittest_android.cc
blobe7c55cbc0ee433114b3a01a2a57ababb68affbf7
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
3 // found in the LICENSE file.
5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/base64.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/test/test_simple_task_runner.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h"
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
24 #include "components/proxy_config/proxy_prefs.h"
25 #include "net/proxy/proxy_server.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "url/gurl.h"
30 using testing::_;
31 using testing::AnyNumber;
32 using testing::Return;
34 using data_reduction_proxy::DataReductionProxySettings;
36 // Used for testing the DataReductionProxySettingsAndroid class.
37 class TestDataReductionProxySettingsAndroid
38 : public DataReductionProxySettingsAndroid {
39 public:
40 // Constructs an Android settings object for test that wraps the provided
41 // settings object.
42 explicit TestDataReductionProxySettingsAndroid(
43 DataReductionProxySettings* settings)
44 : DataReductionProxySettingsAndroid(),
45 settings_(settings) {}
47 // Returns the provided setting object. Used by wrapping methods.
48 DataReductionProxySettings* Settings() override { return settings_; }
50 // The wrapped settings object.
51 DataReductionProxySettings* settings_;
54 template <class C>
55 void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings(
56 bool allowed,
57 bool fallback_allowed,
58 bool promo_allowed,
59 bool holdback) {
60 int flags = 0;
61 if (allowed)
62 flags |= DataReductionProxyParams::kAllowed;
63 if (fallback_allowed)
64 flags |= DataReductionProxyParams::kFallbackAllowed;
65 if (promo_allowed)
66 flags |= DataReductionProxyParams::kPromoAllowed;
67 if (holdback)
68 flags |= DataReductionProxyParams::kHoldback;
69 MockDataReductionProxySettings<C>* settings =
70 new MockDataReductionProxySettings<C>();
71 settings->config_ = test_context_->config();
72 test_context_->config()->ResetParamFlagsForTest(flags);
73 settings->UpdateConfigValues();
74 EXPECT_CALL(*settings, GetOriginalProfilePrefs())
75 .Times(AnyNumber())
76 .WillRepeatedly(Return(test_context_->pref_service()));
77 EXPECT_CALL(*settings, GetLocalStatePrefs())
78 .Times(AnyNumber())
79 .WillRepeatedly(Return(test_context_->pref_service()));
80 settings_.reset(settings);
81 settings_->data_reduction_proxy_service_ =
82 test_context_->CreateDataReductionProxyService(settings_.get());
85 template void
86 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
87 DataReductionProxyChromeSettings>(bool allowed,
88 bool fallback_allowed,
89 bool promo_allowed,
90 bool holdback);
92 class DataReductionProxySettingsAndroidTest
93 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest<
94 DataReductionProxyChromeSettings> {
95 public:
96 // DataReductionProxySettingsTest implementation:
97 void SetUp() override {
98 env_ = base::android::AttachCurrentThread();
99 DataReductionProxySettingsAndroid::Register(env_);
100 DataReductionProxySettingsTestBase::SetUp();
101 ResetSettingsAndroid();
104 void ResetSettingsAndroid() {
105 settings_android_.reset(new TestDataReductionProxySettingsAndroid(
106 settings_.get()));
109 DataReductionProxySettings* Settings() {
110 return settings_.get();
113 DataReductionProxySettingsAndroid* SettingsAndroid() {
114 return settings_android_.get();
117 scoped_ptr<DataReductionProxySettingsAndroid> settings_android_;
118 JNIEnv* env_;
121 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) {
122 ScopedJavaLocalRef<jlongArray> result =
123 SettingsAndroid()->GetDailyContentLengths(
124 env_, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength);
125 ASSERT_TRUE(result.obj());
127 jsize java_array_len = env_->GetArrayLength(result.obj());
128 ASSERT_EQ(static_cast<jsize>(data_reduction_proxy::kNumDaysInHistory),
129 java_array_len);
131 jlong value;
132 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) {
133 env_->GetLongArrayRegion(result.obj(), i, 1, &value);
134 ASSERT_EQ(
135 static_cast<long>(
136 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), value);