| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 <memory> | |
| 6 #include <string> | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/json/json_reader.h" | |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "base/run_loop.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/chromeos/arc/arc_settings_service.h" | |
| 16 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | |
| 18 #include "chrome/browser/ui/browser.h" | |
| 19 #include "chrome/test/base/in_process_browser_test.h" | |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 21 #include "chromeos/dbus/shill_profile_client.h" | |
| 22 #include "chromeos/dbus/shill_service_client.h" | |
| 23 #include "chromeos/network/network_handler.h" | |
| 24 #include "chromeos/network/network_state.h" | |
| 25 #include "chromeos/network/network_state_handler.h" | |
| 26 #include "components/arc/arc_service_manager.h" | |
| 27 #include "components/arc/test/fake_arc_bridge_service.h" | |
| 28 #include "components/arc/test/fake_intent_helper_instance.h" | |
| 29 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 30 #include "components/policy/core/common/mock_configuration_policy_provider.h" | |
| 31 #include "components/policy/core/common/policy_map.h" | |
| 32 #include "components/policy/core/common/policy_types.h" | |
| 33 #include "components/policy/policy_constants.h" | |
| 34 #include "components/prefs/pref_service.h" | |
| 35 #include "components/proxy_config/proxy_config_dictionary.h" | |
| 36 #include "components/proxy_config/proxy_config_pref_names.h" | |
| 37 #include "components/proxy_config/proxy_prefs.h" | |
| 38 #include "testing/gtest/include/gtest/gtest.h" | |
| 39 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 40 | |
| 41 using testing::_; | |
| 42 using testing::Return; | |
| 43 | |
| 44 namespace arc { | |
| 45 | |
| 46 namespace { | |
| 47 constexpr char kONCPolicy[] = | |
| 48 "{ \"NetworkConfigurations\": [" | |
| 49 " { \"GUID\": \"stub_ethernet_guid\"," | |
| 50 " \"Type\": \"Ethernet\"," | |
| 51 " \"Name\": \"My Ethernet\"," | |
| 52 " \"Ethernet\": {" | |
| 53 " \"Authentication\": \"None\" }," | |
| 54 " \"ProxySettings\": {" | |
| 55 " \"PAC\": \"http://domain.com/x\"," | |
| 56 " \"Type\": \"PAC\" }" | |
| 57 " }" | |
| 58 " ]," | |
| 59 " \"Type\": \"UnencryptedConfiguration\"" | |
| 60 "}"; | |
| 61 | |
| 62 constexpr char kDeviceONCPolicy[] = | |
| 63 "{" | |
| 64 " \"GlobalNetworkConfiguration\": {" | |
| 65 " \"AllowOnlyPolicyNetworksToAutoconnect\": false," | |
| 66 " \"AllowOnlyPolicyNetworksToConnect\": false" | |
| 67 " }," | |
| 68 " \"NetworkConfigurations\": [ {" | |
| 69 " \"GUID\": \"{wifi1_guid}\"," | |
| 70 " \"Name\": \"wifi1\"," | |
| 71 " \"ProxySettings\": {" | |
| 72 " \"Manual\": {" | |
| 73 " \"FTPProxy\": {" | |
| 74 " \"Host\": \"proxy\"," | |
| 75 " \"Port\": 5000" | |
| 76 " }," | |
| 77 " \"HTTPProxy\": {" | |
| 78 " \"Host\": \"proxy\"," | |
| 79 " \"Port\": 5000" | |
| 80 " }," | |
| 81 " \"SOCKS\": {" | |
| 82 " \"Host\": \"proxy\"," | |
| 83 " \"Port\": 5000" | |
| 84 " }," | |
| 85 " \"SecureHTTPProxy\": {" | |
| 86 " \"Host\": \"proxy\"," | |
| 87 " \"Port\": 5000" | |
| 88 " }" | |
| 89 " }," | |
| 90 " \"Type\": \"Manual\"" | |
| 91 " }," | |
| 92 " \"Type\": \"WiFi\"," | |
| 93 " \"WiFi\": {" | |
| 94 " \"AutoConnect\": false," | |
| 95 " \"HiddenSSID\": false," | |
| 96 " \"SSID\": \"wifi1\"," | |
| 97 " \"Security\": \"None\"" | |
| 98 " }" | |
| 99 " } ]" | |
| 100 "}"; | |
| 101 | |
| 102 constexpr char kUserONCPolicy[] = | |
| 103 "{" | |
| 104 " \"NetworkConfigurations\": [ {" | |
| 105 " \"GUID\": \"{direct_guid}\"," | |
| 106 " \"Name\": \"EAP-TTLS\"," | |
| 107 " \"ProxySettings\": {" | |
| 108 " \"Type\": \"Direct\"" | |
| 109 " }," | |
| 110 " \"Type\": \"WiFi\"," | |
| 111 " \"WiFi\": {" | |
| 112 " \"AutoConnect\": false," | |
| 113 " \"EAP\": {" | |
| 114 " \"Identity\": \"CrOS\"," | |
| 115 " \"Inner\": \"Automatic\"," | |
| 116 " \"Outer\": \"EAP-TTLS\"," | |
| 117 " \"Password\": \"********\"," | |
| 118 " \"Recommended\": [" | |
| 119 " \"AnonymousIdentity\"," | |
| 120 " \"Identity\"," | |
| 121 " \"Password\"" | |
| 122 " ]," | |
| 123 " \"SaveCredentials\": true," | |
| 124 " \"UseSystemCAs\": false" | |
| 125 " }," | |
| 126 " \"HiddenSSID\": false," | |
| 127 " \"SSID\": \"direct_ssid\"," | |
| 128 " \"Security\": \"WPA-EAP\"" | |
| 129 " }" | |
| 130 " }, {" | |
| 131 " \"GUID\": \"{wifi0_guid}\"," | |
| 132 " \"Name\": \"wifi0\"," | |
| 133 " \"ProxySettings\": {" | |
| 134 " \"Manual\": {" | |
| 135 " \"FTPProxy\": {" | |
| 136 " \"Host\": \"proxy-n300\"," | |
| 137 " \"Port\": 3000" | |
| 138 " }," | |
| 139 " \"HTTPProxy\": {" | |
| 140 " \"Host\": \"proxy-n300\"," | |
| 141 " \"Port\": 3000" | |
| 142 " }," | |
| 143 " \"SOCKS\": {" | |
| 144 " \"Host\": \"proxy-n300\"," | |
| 145 " \"Port\": 3000" | |
| 146 " }," | |
| 147 " \"SecureHTTPProxy\": {" | |
| 148 " \"Host\": \"proxy-n300\"," | |
| 149 " \"Port\": 3000" | |
| 150 " }" | |
| 151 " }," | |
| 152 " \"Type\": \"Manual\"" | |
| 153 " }," | |
| 154 " \"Type\": \"WiFi\"," | |
| 155 " \"WiFi\": {" | |
| 156 " \"AutoConnect\": false," | |
| 157 " \"HiddenSSID\": false," | |
| 158 " \"SSID\": \"wifi0\"," | |
| 159 " \"Security\": \"None\"" | |
| 160 " }" | |
| 161 " } ]" | |
| 162 "}"; | |
| 163 | |
| 164 constexpr char kUserProfilePath[] = "user_profile"; | |
| 165 constexpr char kDefaultServicePath[] = "stub_ethernet"; | |
| 166 | |
| 167 constexpr char kWifi0ServicePath[] = "stub_wifi0"; | |
| 168 constexpr char kWifi0Ssid[] = "wifi0"; | |
| 169 constexpr char kWifi0Guid[] = "{wifi0_guid}"; | |
| 170 | |
| 171 constexpr char kWifi1ServicePath[] = "stub_wifi1"; | |
| 172 constexpr char kWifi1Ssid[] = "wifi1"; | |
| 173 constexpr char kWifi1Guid[] = "{wifi1_guid}"; | |
| 174 | |
| 175 constexpr char kONCPacUrl[] = "http://domain.com/x"; | |
| 176 | |
| 177 // Returns an amount of |broadcasts| matched with |proxy_settings|. | |
| 178 int CountProxyBroadcasts( | |
| 179 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, | |
| 180 const base::DictionaryValue* proxy_settings) { | |
| 181 size_t count = 0; | |
| 182 for (const FakeIntentHelperInstance::Broadcast& broadcast : broadcasts) { | |
| 183 if (broadcast.action == "org.chromium.arc.intent_helper.SET_PROXY") { | |
| 184 EXPECT_TRUE( | |
| 185 base::JSONReader::Read(broadcast.extras)->Equals(proxy_settings)); | |
| 186 count++; | |
| 187 } | |
| 188 } | |
| 189 return count; | |
| 190 } | |
| 191 | |
| 192 void RunUntilIdle() { | |
| 193 DCHECK(base::MessageLoop::current()); | |
| 194 base::RunLoop loop; | |
| 195 loop.RunUntilIdle(); | |
| 196 } | |
| 197 | |
| 198 } // namespace | |
| 199 | |
| 200 class ArcSettingsServiceTest : public InProcessBrowserTest { | |
| 201 public: | |
| 202 ArcSettingsServiceTest() = default; | |
| 203 | |
| 204 // InProcessBrowserTest: | |
| 205 ~ArcSettingsServiceTest() override = default; | |
| 206 | |
| 207 void SetUpInProcessBrowserTestFixture() override { | |
| 208 EXPECT_CALL(provider_, IsInitializationComplete(_)) | |
| 209 .WillRepeatedly(Return(true)); | |
| 210 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | |
| 211 fake_intent_helper_instance_.reset(new FakeIntentHelperInstance()); | |
| 212 | |
| 213 ArcServiceManager::SetArcBridgeServiceForTesting( | |
| 214 base::MakeUnique<FakeArcBridgeService>()); | |
| 215 } | |
| 216 | |
| 217 void SetUpOnMainThread() override { | |
| 218 SetupNetworkEnvironment(); | |
| 219 RunUntilIdle(); | |
| 220 | |
| 221 ArcBridgeService::Get()->intent_helper()->SetInstance( | |
| 222 fake_intent_helper_instance_.get()); | |
| 223 } | |
| 224 | |
| 225 void TearDownOnMainThread() override { | |
| 226 ArcBridgeService::Get()->intent_helper()->SetInstance(nullptr); | |
| 227 } | |
| 228 | |
| 229 void UpdatePolicy(const policy::PolicyMap& policy) { | |
| 230 provider_.UpdateChromePolicy(policy); | |
| 231 RunUntilIdle(); | |
| 232 } | |
| 233 | |
| 234 protected: | |
| 235 void DisconnectNetworkService(const std::string& service_path) { | |
| 236 chromeos::ShillServiceClient::TestInterface* service_test = | |
| 237 chromeos::DBusThreadManager::Get() | |
| 238 ->GetShillServiceClient() | |
| 239 ->GetTestInterface(); | |
| 240 base::StringValue value(shill::kStateIdle); | |
| 241 service_test->SetServiceProperty(service_path, shill::kStateProperty, | |
| 242 value); | |
| 243 RunUntilIdle(); | |
| 244 } | |
| 245 | |
| 246 void ConnectWifiNetworkService(const std::string& service_path, | |
| 247 const std::string& guid, | |
| 248 const std::string& ssid) { | |
| 249 chromeos::ShillServiceClient::TestInterface* service_test = | |
| 250 chromeos::DBusThreadManager::Get() | |
| 251 ->GetShillServiceClient() | |
| 252 ->GetTestInterface(); | |
| 253 | |
| 254 service_test->AddService(service_path, guid, ssid, shill::kTypeWifi, | |
| 255 shill::kStateOnline, true /* add_to_visible */); | |
| 256 | |
| 257 service_test->SetServiceProperty(service_path, shill::kProfileProperty, | |
| 258 base::StringValue(kUserProfilePath)); | |
| 259 RunUntilIdle(); | |
| 260 } | |
| 261 | |
| 262 void SetProxyConfigForNetworkService( | |
| 263 const std::string& service_path, | |
| 264 const base::DictionaryValue* proxy_config) { | |
| 265 ProxyConfigDictionary proxy_config_dict(proxy_config); | |
| 266 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | |
| 267 ->network_state_handler() | |
| 268 ->GetNetworkState(service_path); | |
| 269 ASSERT_TRUE(network); | |
| 270 chromeos::proxy_config::SetProxyConfigForNetwork(proxy_config_dict, | |
| 271 *network); | |
| 272 } | |
| 273 | |
| 274 std::unique_ptr<FakeIntentHelperInstance> fake_intent_helper_instance_; | |
| 275 | |
| 276 private: | |
| 277 void SetupNetworkEnvironment() { | |
| 278 chromeos::ShillProfileClient::TestInterface* profile_test = | |
| 279 chromeos::DBusThreadManager::Get() | |
| 280 ->GetShillProfileClient() | |
| 281 ->GetTestInterface(); | |
| 282 chromeos::ShillServiceClient::TestInterface* service_test = | |
| 283 chromeos::DBusThreadManager::Get() | |
| 284 ->GetShillServiceClient() | |
| 285 ->GetTestInterface(); | |
| 286 | |
| 287 profile_test->AddProfile(kUserProfilePath, "user"); | |
| 288 | |
| 289 service_test->ClearServices(); | |
| 290 | |
| 291 service_test->AddService(kDefaultServicePath, "stub_ethernet_guid", "eth0", | |
| 292 shill::kTypeEthernet, shill::kStateOnline, | |
| 293 true /* add_to_visible */); | |
| 294 service_test->SetServiceProperty(kDefaultServicePath, | |
| 295 shill::kProfileProperty, | |
| 296 base::StringValue(kUserProfilePath)); | |
| 297 } | |
| 298 | |
| 299 policy::MockConfigurationPolicyProvider provider_; | |
| 300 | |
| 301 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); | |
| 302 }; | |
| 303 | |
| 304 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { | |
| 305 fake_intent_helper_instance_->clear_broadcasts(); | |
| 306 | |
| 307 policy::PolicyMap policy; | |
| 308 policy.Set( | |
| 309 policy::key::kProxyMode, policy::POLICY_LEVEL_MANDATORY, | |
| 310 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | |
| 311 base::MakeUnique<base::StringValue>(ProxyPrefs::kAutoDetectProxyModeName), | |
| 312 nullptr); | |
| 313 UpdatePolicy(policy); | |
| 314 | |
| 315 std::unique_ptr<base::DictionaryValue> expected_proxy_config( | |
| 316 base::MakeUnique<base::DictionaryValue>()); | |
| 317 expected_proxy_config->SetString("mode", | |
| 318 ProxyPrefs::kAutoDetectProxyModeName); | |
| 319 expected_proxy_config->SetString("pacUrl", "http://wpad/wpad.dat"); | |
| 320 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 321 expected_proxy_config.get()), | |
| 322 1); | |
| 323 } | |
| 324 | |
| 325 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ONCProxyPolicyTest) { | |
| 326 fake_intent_helper_instance_->clear_broadcasts(); | |
| 327 | |
| 328 policy::PolicyMap policy; | |
| 329 policy.Set(policy::key::kOpenNetworkConfiguration, | |
| 330 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | |
| 331 policy::POLICY_SOURCE_CLOUD, | |
| 332 base::MakeUnique<base::StringValue>(kONCPolicy), nullptr); | |
| 333 UpdatePolicy(policy); | |
| 334 | |
| 335 std::unique_ptr<base::DictionaryValue> expected_proxy_config( | |
| 336 base::MakeUnique<base::DictionaryValue>()); | |
| 337 expected_proxy_config->SetString("mode", ProxyPrefs::kPacScriptProxyModeName); | |
| 338 expected_proxy_config->SetString("pacUrl", kONCPacUrl); | |
| 339 | |
| 340 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 341 expected_proxy_config.get()), | |
| 342 1); | |
| 343 } | |
| 344 | |
| 345 // Proxy policy has a higher priority than proxy default settings. | |
| 346 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, TwoSourcesTest) { | |
| 347 fake_intent_helper_instance_->clear_broadcasts(); | |
| 348 | |
| 349 policy::PolicyMap policy; | |
| 350 // Proxy policy. | |
| 351 policy.Set(policy::key::kProxyMode, policy::POLICY_LEVEL_MANDATORY, | |
| 352 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | |
| 353 base::MakeUnique<base::StringValue>( | |
| 354 ProxyPrefs::kFixedServersProxyModeName), | |
| 355 nullptr); | |
| 356 policy.Set(policy::key::kProxyServer, policy::POLICY_LEVEL_MANDATORY, | |
| 357 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | |
| 358 base::MakeUnique<base::StringValue>("proxy:8888"), nullptr); | |
| 359 UpdatePolicy(policy); | |
| 360 | |
| 361 std::unique_ptr<base::DictionaryValue> proxy_config( | |
| 362 base::MakeUnique<base::DictionaryValue>()); | |
| 363 proxy_config->SetString("mode", ProxyPrefs::kAutoDetectProxyModeName); | |
| 364 ProxyConfigDictionary proxy_config_dict(proxy_config.get()); | |
| 365 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | |
| 366 ->network_state_handler() | |
| 367 ->DefaultNetwork(); | |
| 368 ASSERT_TRUE(network); | |
| 369 chromeos::proxy_config::SetProxyConfigForNetwork(proxy_config_dict, *network); | |
| 370 RunUntilIdle(); | |
| 371 | |
| 372 std::unique_ptr<base::DictionaryValue> expected_proxy_config( | |
| 373 base::MakeUnique<base::DictionaryValue>()); | |
| 374 expected_proxy_config->SetString("mode", | |
| 375 ProxyPrefs::kFixedServersProxyModeName); | |
| 376 expected_proxy_config->SetString("host", "proxy"); | |
| 377 expected_proxy_config->SetInteger("port", 8888); | |
| 378 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 379 expected_proxy_config.get()), | |
| 380 1); | |
| 381 } | |
| 382 | |
| 383 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyPrefTest) { | |
| 384 fake_intent_helper_instance_->clear_broadcasts(); | |
| 385 | |
| 386 std::unique_ptr<base::DictionaryValue> proxy_config( | |
| 387 base::MakeUnique<base::DictionaryValue>()); | |
| 388 proxy_config->SetString("mode", ProxyPrefs::kPacScriptProxyModeName); | |
| 389 proxy_config->SetString("pac_url", "http://proxy"); | |
| 390 browser()->profile()->GetPrefs()->Set(proxy_config::prefs::kProxy, | |
| 391 *proxy_config.get()); | |
| 392 RunUntilIdle(); | |
| 393 | |
| 394 std::unique_ptr<base::DictionaryValue> expected_proxy_config( | |
| 395 base::MakeUnique<base::DictionaryValue>()); | |
| 396 expected_proxy_config->SetString("mode", ProxyPrefs::kPacScriptProxyModeName); | |
| 397 expected_proxy_config->SetString("pacUrl", "http://proxy"); | |
| 398 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 399 expected_proxy_config.get()), | |
| 400 1); | |
| 401 } | |
| 402 | |
| 403 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, DefaultNetworkProxyConfigTest) { | |
| 404 fake_intent_helper_instance_->clear_broadcasts(); | |
| 405 | |
| 406 std::unique_ptr<base::DictionaryValue> proxy_config( | |
| 407 base::MakeUnique<base::DictionaryValue>()); | |
| 408 proxy_config->SetString("mode", ProxyPrefs::kFixedServersProxyModeName); | |
| 409 proxy_config->SetString("server", "proxy:8080"); | |
| 410 SetProxyConfigForNetworkService(kDefaultServicePath, proxy_config.get()); | |
| 411 RunUntilIdle(); | |
| 412 | |
| 413 std::unique_ptr<base::DictionaryValue> expected_proxy_config( | |
| 414 base::MakeUnique<base::DictionaryValue>()); | |
| 415 expected_proxy_config->SetString("mode", | |
| 416 ProxyPrefs::kFixedServersProxyModeName); | |
| 417 expected_proxy_config->SetString("host", "proxy"); | |
| 418 expected_proxy_config->SetInteger("port", 8080); | |
| 419 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 420 expected_proxy_config.get()), | |
| 421 1); | |
| 422 } | |
| 423 | |
| 424 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, DefaultNetworkDisconnectedTest) { | |
| 425 ConnectWifiNetworkService(kWifi0ServicePath, kWifi0Guid, kWifi0Ssid); | |
| 426 fake_intent_helper_instance_->clear_broadcasts(); | |
| 427 // Set proxy confog for default network. | |
| 428 std::unique_ptr<base::DictionaryValue> default_proxy_config( | |
| 429 base::MakeUnique<base::DictionaryValue>()); | |
| 430 default_proxy_config->SetString("mode", | |
| 431 ProxyPrefs::kFixedServersProxyModeName); | |
| 432 default_proxy_config->SetString("server", "default/proxy:8080"); | |
| 433 SetProxyConfigForNetworkService(kDefaultServicePath, | |
| 434 default_proxy_config.get()); | |
| 435 RunUntilIdle(); | |
| 436 | |
| 437 // Set proxy confog for WI-FI network. | |
| 438 std::unique_ptr<base::DictionaryValue> wifi_proxy_config( | |
| 439 base::MakeUnique<base::DictionaryValue>()); | |
| 440 wifi_proxy_config->SetString("mode", ProxyPrefs::kFixedServersProxyModeName); | |
| 441 wifi_proxy_config->SetString("server", "wifi/proxy:8080"); | |
| 442 SetProxyConfigForNetworkService(kWifi0ServicePath, wifi_proxy_config.get()); | |
| 443 RunUntilIdle(); | |
| 444 | |
| 445 // Observe default network proxy config broadcast. | |
| 446 std::unique_ptr<base::DictionaryValue> expected_default_proxy_config( | |
| 447 base::MakeUnique<base::DictionaryValue>()); | |
| 448 expected_default_proxy_config->SetString( | |
| 449 "mode", ProxyPrefs::kFixedServersProxyModeName); | |
| 450 expected_default_proxy_config->SetString("host", "default/proxy"); | |
| 451 expected_default_proxy_config->SetInteger("port", 8080); | |
| 452 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 453 expected_default_proxy_config.get()), | |
| 454 1); | |
| 455 | |
| 456 // Disconnect default network. | |
| 457 fake_intent_helper_instance_->clear_broadcasts(); | |
| 458 DisconnectNetworkService(kDefaultServicePath); | |
| 459 | |
| 460 // Observe WI-FI network proxy config broadcast. | |
| 461 std::unique_ptr<base::DictionaryValue> expected_wifi_proxy_config( | |
| 462 base::MakeUnique<base::DictionaryValue>()); | |
| 463 expected_wifi_proxy_config->SetString("mode", | |
| 464 ProxyPrefs::kFixedServersProxyModeName); | |
| 465 expected_wifi_proxy_config->SetString("host", "wifi/proxy"); | |
| 466 expected_wifi_proxy_config->SetInteger("port", 8080); | |
| 467 | |
| 468 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 469 expected_wifi_proxy_config.get()), | |
| 470 1); | |
| 471 } | |
| 472 | |
| 473 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, NoNetworkConnectedTest) { | |
| 474 // Disconnect all networks. | |
| 475 fake_intent_helper_instance_->clear_broadcasts(); | |
| 476 DisconnectNetworkService(kDefaultServicePath); | |
| 477 | |
| 478 EXPECT_EQ( | |
| 479 CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), nullptr), | |
| 480 0); | |
| 481 } | |
| 482 | |
| 483 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, TwoONCProxyPolicyTest) { | |
| 484 // Connect to wifi1 with appliead device ONC policy. | |
| 485 ConnectWifiNetworkService(kWifi1ServicePath, kWifi1Guid, kWifi1Ssid); | |
| 486 | |
| 487 // Disconnect default network. | |
| 488 DisconnectNetworkService(kDefaultServicePath); | |
| 489 | |
| 490 fake_intent_helper_instance_->clear_broadcasts(); | |
| 491 | |
| 492 policy::PolicyMap policy; | |
| 493 policy.Set(policy::key::kOpenNetworkConfiguration, | |
| 494 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | |
| 495 policy::POLICY_SOURCE_CLOUD, | |
| 496 base::MakeUnique<base::StringValue>(kUserONCPolicy), nullptr); | |
| 497 policy.Set(policy::key::kDeviceOpenNetworkConfiguration, | |
| 498 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE, | |
| 499 policy::POLICY_SOURCE_CLOUD, | |
| 500 base::MakeUnique<base::StringValue>(kDeviceONCPolicy), nullptr); | |
| 501 UpdatePolicy(policy); | |
| 502 | |
| 503 std::unique_ptr<base::DictionaryValue> expected_proxy_config( | |
| 504 base::MakeUnique<base::DictionaryValue>()); | |
| 505 expected_proxy_config->SetString("mode", | |
| 506 ProxyPrefs::kFixedServersProxyModeName); | |
| 507 expected_proxy_config->SetString("host", "proxy"); | |
| 508 expected_proxy_config->SetInteger("port", 5000); | |
| 509 | |
| 510 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 511 expected_proxy_config.get()), | |
| 512 1); | |
| 513 | |
| 514 DisconnectNetworkService(kWifi1ServicePath); | |
| 515 fake_intent_helper_instance_->clear_broadcasts(); | |
| 516 | |
| 517 // Connect to wifi0 with appliead user ONC policy. | |
| 518 ConnectWifiNetworkService(kWifi0ServicePath, kWifi0Guid, kWifi0Ssid); | |
| 519 | |
| 520 expected_proxy_config->SetString("mode", | |
| 521 ProxyPrefs::kFixedServersProxyModeName); | |
| 522 expected_proxy_config->SetString("host", "proxy-n300"); | |
| 523 expected_proxy_config->SetInteger("port", 3000); | |
| 524 | |
| 525 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | |
| 526 expected_proxy_config.get()), | |
| 527 1); | |
| 528 } | |
| 529 | |
| 530 } // namespace arc | |
| OLD | NEW |