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

Unified Diff: chrome/browser/chromeos/arc/arc_settings_service_browsertest.cc

Issue 2306673002: arc: update proxy settings from UI and ONC policy. (Closed)
Patch Set: arc: update proxy settings from UI and ONC policy. Created 4 years, 3 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: chrome/browser/chromeos/arc/arc_settings_service_browsertest.cc
diff --git a/chrome/browser/chromeos/arc/arc_settings_service_browsertest.cc b/chrome/browser/chromeos/arc/arc_settings_service_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d5d920aa5ee18b05de66a0a0c7c01525c5289efd
--- /dev/null
+++ b/chrome/browser/chromeos/arc/arc_settings_service_browsertest.cc
@@ -0,0 +1,234 @@
+// Copyright 2016 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 <memory>
+#include <string>
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/command_line.h"
+#include "base/json/json_reader.h"
+#include "base/memory/ptr_util.h"
+#include "base/memory/weak_ptr.h"
+#include "base/run_loop.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/arc/arc_settings_service.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/shill_profile_client.h"
+#include "chromeos/dbus/shill_service_client.h"
+#include "components/arc/arc_service_manager.h"
+#include "components/arc/test/fake_arc_bridge_service.h"
+#include "components/arc/test/fake_intent_helper_instance.h"
+#include "components/policy/core/browser/browser_policy_connector.h"
+#include "components/policy/core/common/mock_configuration_policy_provider.h"
+#include "components/policy/core/common/policy_map.h"
+#include "components/policy/core/common/policy_types.h"
+#include "components/policy/policy_constants.h"
+#include "components/proxy_config/proxy_prefs.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+using testing::_;
+using testing::Return;
+
+namespace arc {
+
+namespace {
+// char kCmdProxyServer[] = "proxy:8888";
+char kONCPolicy[] =
+ "{ \"NetworkConfigurations\": ["
+ " { \"GUID\": \"stub_ethernet_guid\","
+ " \"Type\": \"Ethernet\","
+ " \"Name\": \"My Ethernet\","
+ " \"Ethernet\": {"
+ " \"Authentication\": \"None\" },"
+ " \"ProxySettings\": {"
+ " \"PAC\": \"http://domain.com/x\","
+ " \"Type\": \"PAC\" }"
+ " }"
+ " ],"
+ " \"Type\": \"UnencryptedConfiguration\""
+ "}";
+char kONCPacUrl[] = "http://domain.com/x";
+const char* kUserProfilePath = "user_profile";
+
+} // namespace
+
+// Receives a proxy settings broadcast and matches it with the expected proxy
+// settings.
+class ProxyBroadcastCollector {
+ public:
+ ProxyBroadcastCollector() : proxy_settings_(new base::DictionaryValue()) {
+ proxy_settings_->SetString("mode", ProxyPrefs::kDirectProxyModeName);
+ }
+
+ ~ProxyBroadcastCollector() {}
+
+ int number() { return number_; }
+
+ void Start(std::unique_ptr<base::DictionaryValue> proxy_settings) {
+ number_ = 0;
+ proxy_settings_.reset();
+ proxy_settings_ = std::move(proxy_settings);
+ }
+
+ void OnSendBroadcast(const std::string& action, const std::string& extras) {
+ if (action == "org.chromium.arc.intent_helper.SET_PROXY") {
+ EXPECT_TRUE(
+ base::JSONReader::Read(extras)->Equals(proxy_settings_.get()));
+ number_++;
+ }
+ }
+
+ private:
+ int number_;
+ std::unique_ptr<base::DictionaryValue> proxy_settings_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProxyBroadcastCollector);
+};
+
+class ArcSettingsServiceTest : public InProcessBrowserTest {
+ public:
+ ArcSettingsServiceTest()
+ : proxy_broadcast_collector_(new ProxyBroadcastCollector()),
+ weak_ptr_factory_(this) {}
+
+ // InProcessBrowserTest:
+ ~ArcSettingsServiceTest() override {}
+
+ void SetUpInProcessBrowserTestFixture() override {
+ EXPECT_CALL(provider_, IsInitializationComplete(_))
+ .WillRepeatedly(Return(true));
+ policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
+
+ fake_intent_helper_instance_.reset(new FakeIntentHelperInstance());
+ fake_intent_helper_instance_->SetCallback(
+ base::Bind(&ArcSettingsServiceTest::OnSendBroadcast,
+ weak_ptr_factory_.GetWeakPtr()));
+
+ ArcServiceManager::SetArcBridgeServiceForTesting(
+ base::MakeUnique<FakeArcBridgeService>());
+ }
+
+ void SetUpOnMainThread() override {
+ SetupNetworkEnvironment();
+ ArcBridgeService::Get()->intent_helper()->SetInstance(
+ fake_intent_helper_instance_.get());
+ }
+
+ void TearDownOnMainThread() override {
+ ArcBridgeService::Get()->intent_helper()->SetInstance(nullptr);
+ }
+
+ void OnSendBroadcast(const std::string& action, const std::string& extras) {
+ proxy_broadcast_collector_->OnSendBroadcast(action, extras);
+ }
+
+ void UpdatePolicy(const policy::PolicyMap& policy) {
+ provider_.UpdateChromePolicy(policy);
+ DCHECK(base::MessageLoop::current());
+ base::RunLoop loop;
+ loop.RunUntilIdle();
+ }
+
+ protected:
+ std::unique_ptr<ProxyBroadcastCollector> proxy_broadcast_collector_;
+
+ private:
+ void SetupNetworkEnvironment() {
+ chromeos::ShillProfileClient::TestInterface* profile_test =
+ chromeos::DBusThreadManager::Get()
+ ->GetShillProfileClient()
+ ->GetTestInterface();
+ chromeos::ShillServiceClient::TestInterface* service_test =
+ chromeos::DBusThreadManager::Get()
+ ->GetShillServiceClient()
+ ->GetTestInterface();
+
+ profile_test->AddProfile(kUserProfilePath, "user");
+
+ service_test->ClearServices();
+ service_test->AddService("stub_ethernet", "stub_ethernet_guid", "eth0",
+ shill::kTypeEthernet, shill::kStateOnline,
+ true /* add_to_visible */);
+ service_test->SetServiceProperty("stub_ethernet", shill::kProfileProperty,
+ base::StringValue(kUserProfilePath));
+ }
+
+ policy::MockConfigurationPolicyProvider provider_;
+ std::unique_ptr<FakeIntentHelperInstance> fake_intent_helper_instance_;
+
+ base::WeakPtrFactory<ArcSettingsServiceTest> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest);
+};
+
+IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) {
+ policy::PolicyMap policy;
+ policy.Set(
+ policy::key::kProxyMode, policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(ProxyPrefs::kAutoDetectProxyModeName),
+ nullptr);
+ std::unique_ptr<base::DictionaryValue> proxy_settings(
+ base::MakeUnique<base::DictionaryValue>());
+ proxy_settings->SetString("mode", ProxyPrefs::kAutoDetectProxyModeName);
+ proxy_settings->SetString("pacUrl", "http://wpad/wpad.dat");
+ proxy_broadcast_collector_->Start(std::move(proxy_settings));
+
+ UpdatePolicy(policy);
+
+ EXPECT_EQ(proxy_broadcast_collector_->number(), 1);
+}
+
+IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ONCProxyPolicyTest) {
+ policy::PolicyMap policy;
+ policy.Set(policy::key::kOpenNetworkConfiguration,
+ policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
+ policy::POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(kONCPolicy), nullptr);
+
+ std::unique_ptr<base::DictionaryValue> proxy_settings(
+ base::MakeUnique<base::DictionaryValue>());
+ proxy_settings->SetString("mode", ProxyPrefs::kPacScriptProxyModeName);
+ proxy_settings->SetString("pacUrl", kONCPacUrl);
+ proxy_broadcast_collector_->Start(std::move(proxy_settings));
+
+ UpdatePolicy(policy);
+
+ EXPECT_EQ(proxy_broadcast_collector_->number(), 1);
+}
+
+// Proxy policy has a higher priority than proxy settings in ONC policy.
+IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, SetTwoPoliciesTest) {
+ policy::PolicyMap policy;
+ // Proxy policy.
+ policy.Set(policy::key::kProxyMode, policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(
+ ProxyPrefs::kFixedServersProxyModeName),
+ nullptr);
+ policy.Set(policy::key::kProxyServer, policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>("proxy:8888"), nullptr);
+ // ONC policy.
+ policy.Set(policy::key::kOpenNetworkConfiguration,
+ policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
+ policy::POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(kONCPolicy), nullptr);
+
+ std::unique_ptr<base::DictionaryValue> proxy_settings(
+ base::MakeUnique<base::DictionaryValue>());
+ proxy_settings->SetString("mode", ProxyPrefs::kFixedServersProxyModeName);
+ proxy_settings->SetString("host", "proxy");
+ proxy_settings->SetInteger("port", 8888);
+ proxy_broadcast_collector_->Start(std::move(proxy_settings));
+
+ UpdatePolicy(policy);
+
+ EXPECT_EQ(proxy_broadcast_collector_->number(), 1);
+}
stevenjb 2016/09/02 16:20:55 We should test that changes to the default network
Polina Bondarenko 2016/09/05 20:08:45 Done, added tests.
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698