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

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager_unittest.cc

Issue 2682833003: Skip ARC initial screen when everything is set up by policy (Closed)
Patch Set: Sync during managed->unmanaged transition Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/values.h"
18 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 20 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
19 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 21 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
20 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h" 22 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator .h"
21 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" 23 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h"
22 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r.h" 24 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r.h"
23 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r_observer.h" 25 #include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_acto r_observer.h"
24 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 26 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
25 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 27 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
26 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 28 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 29 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
28 #include "chrome/browser/chromeos/profiles/profile_helper.h" 30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
29 #include "chrome/browser/policy/profile_policy_connector.h" 31 #include "chrome/browser/policy/profile_policy_connector.h"
30 #include "chrome/browser/policy/profile_policy_connector_factory.h" 32 #include "chrome/browser/policy/profile_policy_connector_factory.h"
31 #include "chrome/browser/prefs/pref_service_syncable_util.h" 33 #include "chrome/browser/prefs/pref_service_syncable_util.h"
32 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 35 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 36 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
35 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
36 #include "chrome/test/base/testing_profile.h" 38 #include "chrome/test/base/testing_profile.h"
37 #include "chromeos/chromeos_switches.h" 39 #include "chromeos/chromeos_switches.h"
38 #include "chromeos/dbus/dbus_thread_manager.h" 40 #include "chromeos/dbus/dbus_thread_manager.h"
39 #include "chromeos/dbus/fake_session_manager_client.h" 41 #include "chromeos/dbus/fake_session_manager_client.h"
40 #include "components/arc/arc_service_manager.h" 42 #include "components/arc/arc_service_manager.h"
41 #include "components/arc/arc_session_runner.h" 43 #include "components/arc/arc_session_runner.h"
42 #include "components/arc/arc_util.h" 44 #include "components/arc/arc_util.h"
43 #include "components/arc/test/fake_arc_session.h" 45 #include "components/arc/test/fake_arc_session.h"
44 #include "components/prefs/pref_service.h" 46 #include "components/prefs/pref_service.h"
47 #include "components/prefs/testing_pref_service.h"
45 #include "components/signin/core/account_id/account_id.h" 48 #include "components/signin/core/account_id/account_id.h"
46 #include "components/sync/model/fake_sync_change_processor.h" 49 #include "components/sync/model/fake_sync_change_processor.h"
47 #include "components/sync/model/sync_error_factory_mock.h" 50 #include "components/sync/model/sync_error_factory_mock.h"
48 #include "components/sync_preferences/testing_pref_service_syncable.h" 51 #include "components/sync_preferences/testing_pref_service_syncable.h"
49 #include "components/user_manager/user_manager.h" 52 #include "components/user_manager/user_manager.h"
50 #include "components/user_manager/user_names.h" 53 #include "components/user_manager/user_names.h"
51 #include "content/public/browser/browser_thread.h" 54 #include "content/public/browser/browser_thread.h"
52 #include "content/public/test/test_browser_thread_bundle.h" 55 #include "content/public/test/test_browser_thread_bundle.h"
53 #include "google_apis/gaia/gaia_constants.h" 56 #include "google_apis/gaia/gaia_constants.h"
54 #include "google_apis/gaia/gaia_urls.h" 57 #include "google_apis/gaia/gaia_urls.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // On error, UI to send feedback is showing. In that case, 438 // On error, UI to send feedback is showing. In that case,
436 // the ARC is still necessary to run on background for gathering the logs. 439 // the ARC is still necessary to run on background for gathering the logs.
437 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 440 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
438 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 441 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
439 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 442 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
440 443
441 // Correctly stop service. 444 // Correctly stop service.
442 arc_session_manager()->Shutdown(); 445 arc_session_manager()->Shutdown();
443 } 446 }
444 447
448 TEST_F(ArcSessionManagerTest, SkippingTermsDueToPolicies) {
449 sync_preferences::TestingPrefServiceSyncable* const prefs =
450 profile()->GetTestingPrefService();
451
452 // Values of the ArcBackupRestoreEnabled pref to be tested.
453 const std::vector<base::Value> test_backup_pref_values = {
454 base::Value(), base::Value(false), base::Value(true)};
455 // Values of the ArcLocationServiceEnabled pref to be tested.
456 const std::vector<base::Value> test_location_pref_values = {
457 base::Value(), base::Value(false), base::Value(true)};
458
459 for (const auto& backup_pref_value : test_backup_pref_values) {
460 for (const auto& location_pref_value : test_location_pref_values) {
461 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
462 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcTermsAccepted));
463
464 // Set ARC to be managed.
465 prefs->SetManagedPref(prefs::kArcEnabled,
466 base::MakeUnique<base::Value>(true).release());
467
468 // Assign test values to the prefs.
469 if (backup_pref_value.is_bool()) {
470 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled,
471 backup_pref_value.DeepCopy());
472 } else {
473 prefs->RemoveManagedPref(prefs::kArcBackupRestoreEnabled);
474 }
475 if (location_pref_value.is_bool()) {
476 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled,
477 location_pref_value.DeepCopy());
478 } else {
479 prefs->RemoveManagedPref(prefs::kArcLocationServiceEnabled);
480 }
481
482 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
483 EXPECT_TRUE(arc_session_manager()->IsArcEnabled());
484 EXPECT_TRUE(arc_session_manager()->IsArcManaged());
485
486 // Terms of Service should be shown if either ArcBackupRestoreEnabled or
487 // ArcLocationServiceEnabled is unmanaged.
488 const ArcSessionManager::State expected_state =
489 backup_pref_value.is_bool() && location_pref_value.is_bool()
490 ? ArcSessionManager::State::ACTIVE
491 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE;
492 EXPECT_EQ(expected_state, arc_session_manager()->state())
493 << "ArcBackupRestoreEnabled pref is " << backup_pref_value
494 << "ArcLocationServiceEnabled pref is " << location_pref_value;
495
496 // Stop ARC and shutdown the service.
497 prefs->RemoveManagedPref(prefs::kArcEnabled);
498 WaitForDataRemoved(ArcSessionManager::State::STOPPED);
499 arc_session_manager()->Shutdown();
500 }
501 }
502 }
503
504 TEST_F(ArcSessionManagerTest, DefaultPreferences) {
505 sync_preferences::TestingPrefServiceSyncable* const prefs =
506 profile()->GetTestingPrefService();
507
508 // Backup-restore and location-service prefs are off by default.
509 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled));
510 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled));
511
512 // Set ARC to be managed, and assign managed test values to the prefs.
513 prefs->SetManagedPref(prefs::kArcEnabled,
514 base::MakeUnique<base::Value>(true).release());
515 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled,
516 base::MakeUnique<base::Value>(true).release());
517 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled,
518 base::MakeUnique<base::Value>(true).release());
519
520 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
521 EXPECT_TRUE(arc_session_manager()->IsArcEnabled());
522 EXPECT_TRUE(arc_session_manager()->IsArcManaged());
523
524 // Terms of Service are skipped.
525 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
526
527 // Unset managed values for the prefs.
528 prefs->RemoveManagedPref(prefs::kArcBackupRestoreEnabled);
529 prefs->RemoveManagedPref(prefs::kArcLocationServiceEnabled);
530
531 // Terms of Service don't get shown. The prefs return to the default false
532 // value.
533 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
534 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled));
535 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled));
536 }
537
445 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { 538 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) {
446 PrefService* const prefs = profile()->GetPrefs(); 539 PrefService* const prefs = profile()->GetPrefs();
447 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 540 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
448 prefs->SetBoolean(prefs::kArcEnabled, true); 541 prefs->SetBoolean(prefs::kArcEnabled, true);
449 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 542 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
450 arc_session_manager()->StartArc(); 543 arc_session_manager()->StartArc();
451 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 544 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
452 545
453 // Create device local account and set it as active. 546 // Create device local account and set it as active.
454 const std::string email = "device-local-account@fake-email.com"; 547 const std::string email = "device-local-account@fake-email.com";
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 MaybeWaitForDataRemoved(); 867 MaybeWaitForDataRemoved();
775 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 868 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
776 arc_session_manager()->state()); 869 arc_session_manager()->state());
777 CloseLoginDisplayHost(); 870 CloseLoginDisplayHost();
778 ReportActorDestroyed(); 871 ReportActorDestroyed();
779 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 872 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
780 EXPECT_FALSE(!IsManagedUser() && arc_session_manager()->IsArcEnabled()); 873 EXPECT_FALSE(!IsManagedUser() && arc_session_manager()->IsArcEnabled());
781 } 874 }
782 875
783 } // namespace arc 876 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698