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

Side by Side Diff: chromeos/network/proxy/proxy_config_service_impl_unittest.cc

Issue 2946153002: Fix chromeos::ProxyConfigService starting with the wrong ProxyConfig. (Closed)
Patch Set: Fix tests (!!), finish removing active_config_state_ from ProxyConfigServiceImpl Created 3 years, 6 months 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
(Empty)
1 // Copyright 2017 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.
4
5 #include "chromeos/network/proxy/proxy_config_service_impl.h"
6
7 #include <memory>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/test/scoped_task_environment.h"
11 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/values.h"
13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/network/network_handler.h"
15 #include "chromeos/network/network_state_test.h"
16 #include "components/prefs/pref_service.h"
17 #include "components/prefs/testing_pref_service.h"
18 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
19 #include "components/proxy_config/proxy_config_pref_names.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace chromeos {
23 namespace {
24
25 const char kFixedPacUrl[] = "http://fixed/";
26
stevenjb 2017/06/21 19:38:02 I don't think we usually put the entire test suite
mmenke 2017/06/21 19:44:18 In net/ we often do, but I don't have strong feeli
27 // Testing proxy config service that allows us to fire notifications at will.
28 class TestProxyConfigService : public net::ProxyConfigService {
29 public:
30 TestProxyConfigService(const net::ProxyConfig& config,
31 ConfigAvailability availability)
32 : config_(config), availability_(availability) {}
33
34 private:
35 void AddObserver(net::ProxyConfigService::Observer* observer) override {}
36
stevenjb 2017/06/21 19:38:02 nit: no blank line here
mmenke 2017/06/21 19:44:18 Done.
37 void RemoveObserver(net::ProxyConfigService::Observer* observer) override {}
38
39 net::ProxyConfigService::ConfigAvailability GetLatestProxyConfig(
40 net::ProxyConfig* config) override {
41 *config = config_;
42 return availability_;
43 }
44
45 net::ProxyConfig config_;
46 ConfigAvailability availability_;
47 };
48
49 class ProxyConfigServiceImplTest : public NetworkStateTest {
50 void SetUp() override {
51 DBusThreadManager::Initialize();
52 chromeos::NetworkHandler::Initialize();
53 NetworkStateTest::SetUp();
54 }
55
56 void TearDown() override {
57 NetworkStateTest::TearDown();
58 chromeos::NetworkHandler::Shutdown();
59 DBusThreadManager::Shutdown();
60 }
61
62 protected:
63 base::test::ScopedTaskEnvironment environment_;
64 };
65
66 // By default, ProxyConfigServiceImpl should ignore the state of the nested
67 // ProxyConfigService.
68 TEST_F(ProxyConfigServiceImplTest, IgnoresNestedProxyConfigServiceByDefault) {
69 TestingPrefServiceSimple profile_prefs;
70 PrefProxyConfigTrackerImpl::RegisterProfilePrefs(profile_prefs.registry());
71 TestingPrefServiceSimple local_state_prefs;
72
73 net::ProxyConfig fixed_config;
74 fixed_config.set_pac_url(GURL(kFixedPacUrl));
75 std::unique_ptr<TestProxyConfigService> nested_service =
76 base::MakeUnique<TestProxyConfigService>(
77 fixed_config, net::ProxyConfigService::CONFIG_VALID);
78
79 ProxyConfigServiceImpl proxy_tracker(&profile_prefs, &local_state_prefs,
80 base::ThreadTaskRunnerHandle::Get());
81
82 std::unique_ptr<net::ProxyConfigService> proxy_service =
83 proxy_tracker.CreateTrackingProxyConfigService(std::move(nested_service));
84
85 net::ProxyConfig config;
86 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
87 proxy_service->GetLatestProxyConfig(&config));
88 EXPECT_TRUE(config.Equals(net::ProxyConfig::CreateDirect()));
89
90 environment_.RunUntilIdle();
91 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
92 proxy_service->GetLatestProxyConfig(&config));
93 EXPECT_TRUE(config.Equals(net::ProxyConfig::CreateDirect()));
94
95 proxy_tracker.DetachFromPrefService();
96 }
97
98 // Sets proxy_config::prefs::kUseSharedProxies to true, and makes sure the
99 // nested ProxyConfigService is used.
100 TEST_F(ProxyConfigServiceImplTest, UsesNestedProxyConfigService) {
101 TestingPrefServiceSimple profile_prefs;
102 PrefProxyConfigTrackerImpl::RegisterProfilePrefs(profile_prefs.registry());
103 TestingPrefServiceSimple local_state_prefs;
104 profile_prefs.SetUserPref(proxy_config::prefs::kUseSharedProxies,
105 base::MakeUnique<base::Value>(true));
106
107 net::ProxyConfig fixed_config;
108 fixed_config.set_pac_url(GURL(kFixedPacUrl));
109 std::unique_ptr<TestProxyConfigService> nested_service =
110 base::MakeUnique<TestProxyConfigService>(
111 fixed_config, net::ProxyConfigService::CONFIG_VALID);
112
113 ProxyConfigServiceImpl proxy_tracker(&profile_prefs, &local_state_prefs,
114 base::ThreadTaskRunnerHandle::Get());
115
116 std::unique_ptr<net::ProxyConfigService> proxy_service =
117 proxy_tracker.CreateTrackingProxyConfigService(std::move(nested_service));
118
119 net::ProxyConfig config;
120 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
121 proxy_service->GetLatestProxyConfig(&config));
122 EXPECT_TRUE(config.Equals(fixed_config));
123
124 environment_.RunUntilIdle();
125 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
126 proxy_service->GetLatestProxyConfig(&config));
127 EXPECT_TRUE(config.Equals(fixed_config));
128
129 proxy_tracker.DetachFromPrefService();
130 }
131
132 } // namespace
133 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698