| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/arc/intent_helper/arc_settings_service.h" | 15 #include "chrome/browser/chromeos/arc/intent_helper/arc_settings_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chromeos/dbus/shill_profile_client.h" | 21 #include "chromeos/dbus/shill_profile_client.h" |
| 21 #include "chromeos/dbus/shill_service_client.h" | 22 #include "chromeos/dbus/shill_service_client.h" |
| 22 #include "chromeos/network/network_handler.h" | 23 #include "chromeos/network/network_handler.h" |
| 23 #include "chromeos/network/network_state.h" | 24 #include "chromeos/network/network_state.h" |
| 24 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 25 #include "chromeos/network/proxy/proxy_config_handler.h" | 26 #include "chromeos/network/proxy/proxy_config_handler.h" |
| 26 #include "components/arc/arc_bridge_service.h" | 27 #include "components/arc/arc_bridge_service.h" |
| 27 #include "components/arc/arc_service_manager.h" | 28 #include "components/arc/arc_service_manager.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 constexpr char kWifi0ServicePath[] = "stub_wifi0"; | 168 constexpr char kWifi0ServicePath[] = "stub_wifi0"; |
| 168 constexpr char kWifi0Ssid[] = "wifi0"; | 169 constexpr char kWifi0Ssid[] = "wifi0"; |
| 169 constexpr char kWifi0Guid[] = "{wifi0_guid}"; | 170 constexpr char kWifi0Guid[] = "{wifi0_guid}"; |
| 170 | 171 |
| 171 constexpr char kWifi1ServicePath[] = "stub_wifi1"; | 172 constexpr char kWifi1ServicePath[] = "stub_wifi1"; |
| 172 constexpr char kWifi1Ssid[] = "wifi1"; | 173 constexpr char kWifi1Ssid[] = "wifi1"; |
| 173 constexpr char kWifi1Guid[] = "{wifi1_guid}"; | 174 constexpr char kWifi1Guid[] = "{wifi1_guid}"; |
| 174 | 175 |
| 175 constexpr char kONCPacUrl[] = "http://domain.com/x"; | 176 constexpr char kONCPacUrl[] = "http://domain.com/x"; |
| 176 | 177 |
| 178 constexpr char kBackupBroadcastAction[] = |
| 179 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED"; |
| 177 constexpr char kLocationServiceBroadcastAction[] = | 180 constexpr char kLocationServiceBroadcastAction[] = |
| 178 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED"; | 181 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED"; |
| 179 constexpr char kSetProxyBroadcastAction[] = | 182 constexpr char kSetProxyBroadcastAction[] = |
| 180 "org.chromium.arc.intent_helper.SET_PROXY"; | 183 "org.chromium.arc.intent_helper.SET_PROXY"; |
| 181 | 184 |
| 182 // Returns the number of |broadcasts| having the |action| action, and checks | 185 // Returns the number of |broadcasts| having the |action| action, and checks |
| 183 // that all their extras match with |extras|. | 186 // that all their extras match with |extras|. |
| 184 int CountBroadcasts( | 187 int CountBroadcasts( |
| 185 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, | 188 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, |
| 186 const std::string& action, | 189 const std::string& action, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 service_test->SetServiceProperty(kDefaultServicePath, | 313 service_test->SetServiceProperty(kDefaultServicePath, |
| 311 shill::kProfileProperty, | 314 shill::kProfileProperty, |
| 312 base::StringValue(kUserProfilePath)); | 315 base::StringValue(kUserProfilePath)); |
| 313 } | 316 } |
| 314 | 317 |
| 315 policy::MockConfigurationPolicyProvider provider_; | 318 policy::MockConfigurationPolicyProvider provider_; |
| 316 | 319 |
| 317 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); | 320 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); |
| 318 }; | 321 }; |
| 319 | 322 |
| 320 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, LocationServicePolicyTest) { | 323 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, BackupRestorePolicyTest) { |
| 324 PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 325 |
| 326 // Set the user pref as initially enabled. |
| 327 prefs->SetBoolean(prefs::kArcBackupRestoreEnabled, true); |
| 328 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
| 329 |
| 321 fake_intent_helper_instance_->clear_broadcasts(); | 330 fake_intent_helper_instance_->clear_broadcasts(); |
| 322 | 331 |
| 323 // The policy is set to false. | 332 // The policy is set to false. |
| 333 policy::PolicyMap policy; |
| 334 policy.Set(policy::key::kArcBackupRestoreEnabled, |
| 335 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 336 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), |
| 337 nullptr); |
| 338 UpdatePolicy(policy); |
| 339 |
| 340 // The pref is disabled and managed, and the corresponding broadcast is sent |
| 341 // at least once. |
| 342 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
| 343 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled)); |
| 344 base::DictionaryValue expected_broadcast_extras; |
| 345 expected_broadcast_extras.SetBoolean("enabled", false); |
| 346 expected_broadcast_extras.SetBoolean("managed", true); |
| 347 EXPECT_GE(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 348 kBackupBroadcastAction, &expected_broadcast_extras), |
| 349 1); |
| 350 |
| 351 fake_intent_helper_instance_->clear_broadcasts(); |
| 352 |
| 353 // The policy is set to true. |
| 354 policy.Set(policy::key::kArcBackupRestoreEnabled, |
| 355 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 356 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), |
| 357 nullptr); |
| 358 UpdatePolicy(policy); |
| 359 |
| 360 // The pref is enabled and managed, and the corresponding broadcast is sent at |
| 361 // least once. |
| 362 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
| 363 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled)); |
| 364 expected_broadcast_extras.SetBoolean("enabled", true); |
| 365 EXPECT_GE(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 366 kBackupBroadcastAction, &expected_broadcast_extras), |
| 367 1); |
| 368 |
| 369 fake_intent_helper_instance_->clear_broadcasts(); |
| 370 |
| 371 // The policy is unset. |
| 372 policy.Erase(policy::key::kArcBackupRestoreEnabled); |
| 373 UpdatePolicy(policy); |
| 374 |
| 375 // The pref is disabled and unmanaged, and the corresponding broadcast is |
| 376 // sent. |
| 377 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
| 378 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled)); |
| 379 expected_broadcast_extras.SetBoolean("enabled", false); |
| 380 expected_broadcast_extras.SetBoolean("managed", false); |
| 381 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 382 kBackupBroadcastAction, &expected_broadcast_extras), |
| 383 1); |
| 384 } |
| 385 |
| 386 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, LocationServicePolicyTest) { |
| 387 PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 388 |
| 389 // Set the user pref as initially enabled. |
| 390 prefs->SetBoolean(prefs::kArcLocationServiceEnabled, true); |
| 391 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); |
| 392 |
| 393 fake_intent_helper_instance_->clear_broadcasts(); |
| 394 |
| 395 // The policy is set to false. |
| 324 policy::PolicyMap policy; | 396 policy::PolicyMap policy; |
| 325 policy.Set(policy::key::kArcLocationServiceEnabled, | 397 policy.Set(policy::key::kArcLocationServiceEnabled, |
| 326 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 398 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 327 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), | 399 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), |
| 328 nullptr); | 400 nullptr); |
| 329 UpdatePolicy(policy); | 401 UpdatePolicy(policy); |
| 330 | 402 |
| 331 // The broadcast is sent which says that the pref is disabled and managed. | 403 // The pref is disabled and managed, and the corresponding broadcast is sent |
| 404 // at least once. |
| 405 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); |
| 406 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)); |
| 332 base::DictionaryValue expected_broadcast_extras; | 407 base::DictionaryValue expected_broadcast_extras; |
| 333 expected_broadcast_extras.SetBoolean("enabled", false); | 408 expected_broadcast_extras.SetBoolean("enabled", false); |
| 334 expected_broadcast_extras.SetBoolean("managed", true); | 409 expected_broadcast_extras.SetBoolean("managed", true); |
| 335 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), | 410 EXPECT_GE(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 336 kLocationServiceBroadcastAction, | 411 kLocationServiceBroadcastAction, |
| 337 &expected_broadcast_extras), | 412 &expected_broadcast_extras), |
| 338 1); | 413 1); |
| 339 | 414 |
| 340 fake_intent_helper_instance_->clear_broadcasts(); | 415 fake_intent_helper_instance_->clear_broadcasts(); |
| 341 | 416 |
| 342 // The policy is set to true. | 417 // The policy is set to true. |
| 343 policy.Set(policy::key::kArcLocationServiceEnabled, | 418 policy.Set(policy::key::kArcLocationServiceEnabled, |
| 344 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 419 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 345 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), | 420 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), |
| 346 nullptr); | 421 nullptr); |
| 347 UpdatePolicy(policy); | 422 UpdatePolicy(policy); |
| 348 | 423 |
| 349 // The broadcast is sent which says that the pref is enabled and managed. | 424 // The pref is enabled and managed, and the corresponding broadcast is sent at |
| 425 // least once. |
| 426 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); |
| 427 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)); |
| 350 expected_broadcast_extras.SetBoolean("enabled", true); | 428 expected_broadcast_extras.SetBoolean("enabled", true); |
| 429 EXPECT_GE(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 430 kLocationServiceBroadcastAction, |
| 431 &expected_broadcast_extras), |
| 432 1); |
| 433 |
| 434 fake_intent_helper_instance_->clear_broadcasts(); |
| 435 |
| 436 // The policy is unset. |
| 437 policy.Erase(policy::key::kArcLocationServiceEnabled); |
| 438 UpdatePolicy(policy); |
| 439 |
| 440 // The pref is disabled and unmanaged, and the corresponding broadcast is |
| 441 // sent. |
| 442 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); |
| 443 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)); |
| 444 expected_broadcast_extras.SetBoolean("enabled", false); |
| 445 expected_broadcast_extras.SetBoolean("managed", false); |
| 351 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), | 446 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 352 kLocationServiceBroadcastAction, | 447 kLocationServiceBroadcastAction, |
| 353 &expected_broadcast_extras), | 448 &expected_broadcast_extras), |
| 354 1); | 449 1); |
| 355 } | 450 } |
| 356 | 451 |
| 357 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { | 452 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { |
| 358 fake_intent_helper_instance_->clear_broadcasts(); | 453 fake_intent_helper_instance_->clear_broadcasts(); |
| 359 | 454 |
| 360 policy::PolicyMap policy; | 455 policy::PolicyMap policy; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 ProxyPrefs::kFixedServersProxyModeName); | 669 ProxyPrefs::kFixedServersProxyModeName); |
| 575 expected_proxy_config->SetString("host", "proxy-n300"); | 670 expected_proxy_config->SetString("host", "proxy-n300"); |
| 576 expected_proxy_config->SetInteger("port", 3000); | 671 expected_proxy_config->SetInteger("port", 3000); |
| 577 | 672 |
| 578 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | 673 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
| 579 expected_proxy_config.get()), | 674 expected_proxy_config.get()), |
| 580 1); | 675 1); |
| 581 } | 676 } |
| 582 | 677 |
| 583 } // namespace arc | 678 } // namespace arc |
| OLD | NEW |