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" | |
19 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
21 #include "chromeos/dbus/shill_profile_client.h" | 20 #include "chromeos/dbus/shill_profile_client.h" |
22 #include "chromeos/dbus/shill_service_client.h" | 21 #include "chromeos/dbus/shill_service_client.h" |
23 #include "chromeos/network/network_handler.h" | 22 #include "chromeos/network/network_handler.h" |
24 #include "chromeos/network/network_state.h" | 23 #include "chromeos/network/network_state.h" |
25 #include "chromeos/network/network_state_handler.h" | 24 #include "chromeos/network/network_state_handler.h" |
26 #include "chromeos/network/proxy/proxy_config_handler.h" | 25 #include "chromeos/network/proxy/proxy_config_handler.h" |
27 #include "components/arc/arc_bridge_service.h" | 26 #include "components/arc/arc_bridge_service.h" |
28 #include "components/arc/arc_service_manager.h" | 27 #include "components/arc/arc_service_manager.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 constexpr char kWifi0ServicePath[] = "stub_wifi0"; | 167 constexpr char kWifi0ServicePath[] = "stub_wifi0"; |
169 constexpr char kWifi0Ssid[] = "wifi0"; | 168 constexpr char kWifi0Ssid[] = "wifi0"; |
170 constexpr char kWifi0Guid[] = "{wifi0_guid}"; | 169 constexpr char kWifi0Guid[] = "{wifi0_guid}"; |
171 | 170 |
172 constexpr char kWifi1ServicePath[] = "stub_wifi1"; | 171 constexpr char kWifi1ServicePath[] = "stub_wifi1"; |
173 constexpr char kWifi1Ssid[] = "wifi1"; | 172 constexpr char kWifi1Ssid[] = "wifi1"; |
174 constexpr char kWifi1Guid[] = "{wifi1_guid}"; | 173 constexpr char kWifi1Guid[] = "{wifi1_guid}"; |
175 | 174 |
176 constexpr char kONCPacUrl[] = "http://domain.com/x"; | 175 constexpr char kONCPacUrl[] = "http://domain.com/x"; |
177 | 176 |
178 constexpr char kBackupBroadcastAction[] = | |
179 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED"; | |
180 constexpr char kLocationServiceBroadcastAction[] = | 177 constexpr char kLocationServiceBroadcastAction[] = |
181 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED"; | 178 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED"; |
182 constexpr char kSetProxyBroadcastAction[] = | 179 constexpr char kSetProxyBroadcastAction[] = |
183 "org.chromium.arc.intent_helper.SET_PROXY"; | 180 "org.chromium.arc.intent_helper.SET_PROXY"; |
184 | 181 |
185 // Returns the number of |broadcasts| having the |action| action, and checks | 182 // Returns the number of |broadcasts| having the |action| action, and checks |
186 // that all their extras match with |extras|. | 183 // that all their extras match with |extras|. |
187 int CountBroadcasts( | 184 int CountBroadcasts( |
188 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, | 185 const std::vector<FakeIntentHelperInstance::Broadcast>& broadcasts, |
189 const std::string& action, | 186 const std::string& action, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 service_test->SetServiceProperty(kDefaultServicePath, | 310 service_test->SetServiceProperty(kDefaultServicePath, |
314 shill::kProfileProperty, | 311 shill::kProfileProperty, |
315 base::StringValue(kUserProfilePath)); | 312 base::StringValue(kUserProfilePath)); |
316 } | 313 } |
317 | 314 |
318 policy::MockConfigurationPolicyProvider provider_; | 315 policy::MockConfigurationPolicyProvider provider_; |
319 | 316 |
320 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); | 317 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceTest); |
321 }; | 318 }; |
322 | 319 |
323 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, BackupRestorePolicyTest) { | 320 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, LocationServicePolicyTest) { |
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 | |
330 fake_intent_helper_instance_->clear_broadcasts(); | 321 fake_intent_helper_instance_->clear_broadcasts(); |
331 | 322 |
332 // The policy is set to false. | 323 // 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. | |
396 policy::PolicyMap policy; | 324 policy::PolicyMap policy; |
397 policy.Set(policy::key::kArcLocationServiceEnabled, | 325 policy.Set(policy::key::kArcLocationServiceEnabled, |
398 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 326 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
399 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), | 327 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), |
400 nullptr); | 328 nullptr); |
401 UpdatePolicy(policy); | 329 UpdatePolicy(policy); |
402 | 330 |
403 // The pref is disabled and managed, and the corresponding broadcast is sent | 331 // The broadcast is sent which says that the pref is disabled and managed. |
404 // at least once. | |
405 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
406 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)); | |
407 base::DictionaryValue expected_broadcast_extras; | 332 base::DictionaryValue expected_broadcast_extras; |
408 expected_broadcast_extras.SetBoolean("enabled", false); | 333 expected_broadcast_extras.SetBoolean("enabled", false); |
409 expected_broadcast_extras.SetBoolean("managed", true); | 334 expected_broadcast_extras.SetBoolean("managed", true); |
410 EXPECT_GE(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), | 335 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
411 kLocationServiceBroadcastAction, | 336 kLocationServiceBroadcastAction, |
412 &expected_broadcast_extras), | 337 &expected_broadcast_extras), |
413 1); | 338 1); |
414 | 339 |
415 fake_intent_helper_instance_->clear_broadcasts(); | 340 fake_intent_helper_instance_->clear_broadcasts(); |
416 | 341 |
417 // The policy is set to true. | 342 // The policy is set to true. |
418 policy.Set(policy::key::kArcLocationServiceEnabled, | 343 policy.Set(policy::key::kArcLocationServiceEnabled, |
419 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 344 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
420 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), | 345 policy::POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), |
421 nullptr); | 346 nullptr); |
422 UpdatePolicy(policy); | 347 UpdatePolicy(policy); |
423 | 348 |
424 // The pref is enabled and managed, and the corresponding broadcast is sent at | 349 // The broadcast is sent which says that the pref is enabled and managed. |
425 // least once. | |
426 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
427 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)); | |
428 expected_broadcast_extras.SetBoolean("enabled", true); | 350 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); | |
446 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), | 351 EXPECT_EQ(CountBroadcasts(fake_intent_helper_instance_->broadcasts(), |
447 kLocationServiceBroadcastAction, | 352 kLocationServiceBroadcastAction, |
448 &expected_broadcast_extras), | 353 &expected_broadcast_extras), |
449 1); | 354 1); |
450 } | 355 } |
451 | 356 |
452 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { | 357 IN_PROC_BROWSER_TEST_F(ArcSettingsServiceTest, ProxyModePolicyTest) { |
453 fake_intent_helper_instance_->clear_broadcasts(); | 358 fake_intent_helper_instance_->clear_broadcasts(); |
454 | 359 |
455 policy::PolicyMap policy; | 360 policy::PolicyMap policy; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 ProxyPrefs::kFixedServersProxyModeName); | 574 ProxyPrefs::kFixedServersProxyModeName); |
670 expected_proxy_config->SetString("host", "proxy-n300"); | 575 expected_proxy_config->SetString("host", "proxy-n300"); |
671 expected_proxy_config->SetInteger("port", 3000); | 576 expected_proxy_config->SetInteger("port", 3000); |
672 | 577 |
673 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), | 578 EXPECT_EQ(CountProxyBroadcasts(fake_intent_helper_instance_->broadcasts(), |
674 expected_proxy_config.get()), | 579 expected_proxy_config.get()), |
675 1); | 580 1); |
676 } | 581 } |
677 | 582 |
678 } // namespace arc | 583 } // namespace arc |
OLD | NEW |