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

Unified Diff: chromeos/network/proxy/proxy_config_service_impl_unittest.cc

Issue 2946153002: Fix chromeos::ProxyConfigService starting with the wrong ProxyConfig. (Closed)
Patch Set: Remove incorrect comment 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/network/proxy/proxy_config_service_impl_unittest.cc
diff --git a/chromeos/network/proxy/proxy_config_service_impl_unittest.cc b/chromeos/network/proxy/proxy_config_service_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..04633c012b97d56cc752ae9f0ed95e5997408b7b
--- /dev/null
+++ b/chromeos/network/proxy/proxy_config_service_impl_unittest.cc
@@ -0,0 +1,132 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/network/proxy/proxy_config_service_impl.h"
+
+#include <memory>
+
+#include "base/memory/ptr_util.h"
+#include "base/test/scoped_task_environment.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "base/values.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/network/network_handler.h"
+#include "chromeos/network/network_state_test.h"
+#include "components/prefs/pref_service.h"
+#include "components/prefs/testing_pref_service.h"
+#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
+#include "components/proxy_config/proxy_config_pref_names.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+namespace {
+
+const char kFixedPacUrl[] = "http://fixed/";
+
+class TestProxyConfigService : public net::ProxyConfigService {
+ public:
+ TestProxyConfigService(const net::ProxyConfig& config,
+ ConfigAvailability availability)
+ : config_(config), availability_(availability) {}
+
+ private:
+ void AddObserver(net::ProxyConfigService::Observer* observer) override {}
+ void RemoveObserver(net::ProxyConfigService::Observer* observer) override {}
+
+ net::ProxyConfigService::ConfigAvailability GetLatestProxyConfig(
+ net::ProxyConfig* config) override {
+ *config = config_;
+ return availability_;
+ }
+
+ net::ProxyConfig config_;
+ ConfigAvailability availability_;
+};
+
+} // namespace
+
+class ProxyConfigServiceImplTest : public NetworkStateTest {
+ void SetUp() override {
+ DBusThreadManager::Initialize();
+ chromeos::NetworkHandler::Initialize();
+ NetworkStateTest::SetUp();
+ }
+
+ void TearDown() override {
+ NetworkStateTest::TearDown();
+ chromeos::NetworkHandler::Shutdown();
+ DBusThreadManager::Shutdown();
+ }
+
+ protected:
+ base::test::ScopedTaskEnvironment environment_;
+};
+
+// By default, ProxyConfigServiceImpl should ignore the state of the nested
+// ProxyConfigService.
+TEST_F(ProxyConfigServiceImplTest, IgnoresNestedProxyConfigServiceByDefault) {
+ TestingPrefServiceSimple profile_prefs;
+ PrefProxyConfigTrackerImpl::RegisterProfilePrefs(profile_prefs.registry());
+ TestingPrefServiceSimple local_state_prefs;
+
+ net::ProxyConfig fixed_config;
+ fixed_config.set_pac_url(GURL(kFixedPacUrl));
+ std::unique_ptr<TestProxyConfigService> nested_service =
+ base::MakeUnique<TestProxyConfigService>(
+ fixed_config, net::ProxyConfigService::CONFIG_VALID);
+
+ ProxyConfigServiceImpl proxy_tracker(&profile_prefs, &local_state_prefs,
+ base::ThreadTaskRunnerHandle::Get());
+
+ std::unique_ptr<net::ProxyConfigService> proxy_service =
+ proxy_tracker.CreateTrackingProxyConfigService(std::move(nested_service));
+
+ net::ProxyConfig config;
+ EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
+ proxy_service->GetLatestProxyConfig(&config));
+ EXPECT_TRUE(config.Equals(net::ProxyConfig::CreateDirect()));
+
+ environment_.RunUntilIdle();
+ EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
+ proxy_service->GetLatestProxyConfig(&config));
+ EXPECT_TRUE(config.Equals(net::ProxyConfig::CreateDirect()));
+
+ proxy_tracker.DetachFromPrefService();
+}
+
+// Sets proxy_config::prefs::kUseSharedProxies to true, and makes sure the
+// nested ProxyConfigService is used.
+TEST_F(ProxyConfigServiceImplTest, UsesNestedProxyConfigService) {
+ TestingPrefServiceSimple profile_prefs;
+ PrefProxyConfigTrackerImpl::RegisterProfilePrefs(profile_prefs.registry());
+ TestingPrefServiceSimple local_state_prefs;
+ profile_prefs.SetUserPref(proxy_config::prefs::kUseSharedProxies,
+ base::MakeUnique<base::Value>(true));
+
+ net::ProxyConfig fixed_config;
+ fixed_config.set_pac_url(GURL(kFixedPacUrl));
+ std::unique_ptr<TestProxyConfigService> nested_service =
+ base::MakeUnique<TestProxyConfigService>(
+ fixed_config, net::ProxyConfigService::CONFIG_VALID);
+
+ ProxyConfigServiceImpl proxy_tracker(&profile_prefs, &local_state_prefs,
+ base::ThreadTaskRunnerHandle::Get());
+
+ std::unique_ptr<net::ProxyConfigService> proxy_service =
+ proxy_tracker.CreateTrackingProxyConfigService(std::move(nested_service));
+
+ net::ProxyConfig config;
+ EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
+ proxy_service->GetLatestProxyConfig(&config));
+ EXPECT_TRUE(config.Equals(fixed_config));
+
+ environment_.RunUntilIdle();
+ EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
+ proxy_service->GetLatestProxyConfig(&config));
+ EXPECT_TRUE(config.Equals(fixed_config));
+
+ proxy_tracker.DetachFromPrefService();
+}
+
+} // namespace chromeos
« no previous file with comments | « chromeos/network/proxy/proxy_config_service_impl.cc ('k') | components/proxy_config/pref_proxy_config_tracker_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698