Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / net / spdyproxy / data_reduction_proxy_chrome_settings_unittest.cc
blob9d0d21343b5b0c9d7d3614cefc3819e480a0ee5c
1 // Copyright 2015 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 <string>
7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/testing_pref_service.h"
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
11 #include "chrome/common/pref_names.h"
12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using testing::_;
19 using testing::Return;
21 class DataReductionProxyChromeSettingsTest : public testing::Test {
22 public:
23 void SetUp() override {
24 drp_chrome_settings_ =
25 make_scoped_ptr(new DataReductionProxyChromeSettings());
26 test_context_ =
27 data_reduction_proxy::DataReductionProxyTestContext::Builder()
28 .WithParamsFlags(
29 data_reduction_proxy::DataReductionProxyParams::kAllowed |
30 data_reduction_proxy::DataReductionProxyParams::
31 kFallbackAllowed |
32 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed)
33 .WithParamsDefinitions(
34 data_reduction_proxy::TestDataReductionProxyParams::
35 HAS_EVERYTHING &
36 ~data_reduction_proxy::TestDataReductionProxyParams::
37 HAS_DEV_ORIGIN &
38 ~data_reduction_proxy::TestDataReductionProxyParams::
39 HAS_DEV_FALLBACK_ORIGIN)
40 .WithMockConfig()
41 .SkipSettingsInitialization()
42 .Build();
43 config_ = test_context_->mock_config();
44 drp_chrome_settings_->ResetConfigForTest(config_);
45 dict_ = make_scoped_ptr(new base::DictionaryValue());
47 PrefRegistrySimple* registry = test_context_->pref_service()->registry();
48 registry->RegisterDictionaryPref(prefs::kProxy);
51 scoped_ptr<DataReductionProxyChromeSettings> drp_chrome_settings_;
52 scoped_ptr<base::DictionaryValue> dict_;
53 scoped_ptr<data_reduction_proxy::DataReductionProxyTestContext> test_context_;
54 data_reduction_proxy::MockDataReductionProxyConfig* config_;
57 TEST_F(DataReductionProxyChromeSettingsTest, MigrateEmptyProxy) {
58 EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(0);
59 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
60 test_context_->pref_service());
62 EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
65 TEST_F(DataReductionProxyChromeSettingsTest, MigrateSystemProxy) {
66 dict_->SetString("mode", "system");
67 test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
68 EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(0);
70 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
71 test_context_->pref_service());
73 EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
76 TEST_F(DataReductionProxyChromeSettingsTest, MigrateDataReductionProxy) {
77 dict_->SetString("mode", "fixed_servers");
78 dict_->SetString("server", "http=https://proxy.googlezip.net");
79 test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
80 EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(1)
81 .WillOnce(Return(true));
83 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
84 test_context_->pref_service());
86 EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
89 TEST_F(DataReductionProxyChromeSettingsTest, MigrateIgnoreOtherProxy) {
90 dict_->SetString("mode", "fixed_servers");
91 dict_->SetString("server", "http=https://youtube.com");
92 test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
93 EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(1)
94 .WillOnce(Return(false));
96 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
97 test_context_->pref_service());
99 base::DictionaryValue* value =
100 (base::DictionaryValue*)test_context_->pref_service()->GetUserPref(
101 prefs::kProxy);
102 std::string mode;
103 EXPECT_TRUE(value->GetString("mode", &mode));
104 EXPECT_EQ("fixed_servers", mode);
105 std::string server;
106 EXPECT_TRUE(value->GetString("server", &server));
107 EXPECT_EQ("http=https://youtube.com", server);