Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / net / spdyproxy / data_reduction_proxy_settings_unittest_android.cc
blobcdb0aea2ec47768b3969c8bd8efe2a7971ca2471
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/browser/prefs/proxy_prefs.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h"
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.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 alt_allowed,
59 bool promo_allowed,
60 bool holdback) {
61 int flags = 0;
62 if (allowed)
63 flags |= DataReductionProxyParams::kAllowed;
64 if (fallback_allowed)
65 flags |= DataReductionProxyParams::kFallbackAllowed;
66 if (alt_allowed)
67 flags |= DataReductionProxyParams::kAlternativeAllowed;
68 if (promo_allowed)
69 flags |= DataReductionProxyParams::kPromoAllowed;
70 if (holdback)
71 flags |= DataReductionProxyParams::kHoldback;
72 MockDataReductionProxySettings<C>* settings =
73 new MockDataReductionProxySettings<C>();
74 settings->config_ = test_context_->config();
75 settings->data_reduction_proxy_service_ =
76 test_context_->CreateDataReductionProxyService();
77 test_context_->config()->ResetParamFlagsForTest(flags);
78 settings->UpdateConfigValues();
79 EXPECT_CALL(*settings, GetOriginalProfilePrefs())
80 .Times(AnyNumber())
81 .WillRepeatedly(Return(test_context_->pref_service()));
82 EXPECT_CALL(*settings, GetLocalStatePrefs())
83 .Times(AnyNumber())
84 .WillRepeatedly(Return(test_context_->pref_service()));
85 settings_.reset(settings);
88 template void
89 data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
90 DataReductionProxyChromeSettings>(bool allowed,
91 bool fallback_allowed,
92 bool alt_allowed,
93 bool promo_allowed,
94 bool holdback);
96 class DataReductionProxySettingsAndroidTest
97 : public data_reduction_proxy::ConcreteDataReductionProxySettingsTest<
98 DataReductionProxyChromeSettings> {
99 public:
100 // DataReductionProxySettingsTest implementation:
101 void SetUp() override {
102 env_ = base::android::AttachCurrentThread();
103 DataReductionProxySettingsAndroid::Register(env_);
104 DataReductionProxySettingsTestBase::SetUp();
105 ResetSettingsAndroid();
108 void ResetSettingsAndroid() {
109 settings_android_.reset(new TestDataReductionProxySettingsAndroid(
110 settings_.get()));
113 DataReductionProxySettings* Settings() {
114 return settings_.get();
117 DataReductionProxySettingsAndroid* SettingsAndroid() {
118 return settings_android_.get();
121 scoped_ptr<DataReductionProxySettingsAndroid> settings_android_;
122 JNIEnv* env_;
125 TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) {
126 ScopedJavaLocalRef<jlongArray> result =
127 SettingsAndroid()->GetDailyContentLengths(
128 env_, data_reduction_proxy::prefs::kDailyHttpOriginalContentLength);
129 ASSERT_TRUE(result.obj());
131 jsize java_array_len = env_->GetArrayLength(result.obj());
132 ASSERT_EQ(static_cast<jsize>(data_reduction_proxy::kNumDaysInHistory),
133 java_array_len);
135 jlong value;
136 for (size_t i = 0; i < data_reduction_proxy::kNumDaysInHistory; ++i) {
137 env_->GetLongArrayRegion(result.obj(), i, 1, &value);
138 ASSERT_EQ(
139 static_cast<long>(
140 (data_reduction_proxy::kNumDaysInHistory - 1 - i) * 2), value);