| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/chromeos/arc/arc_util.h" | 5 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/test/scoped_command_line.h" | 13 #include "base/test/scoped_command_line.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 15 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 16 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow
.h" | 16 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow
.h" |
| 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 22 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 23 #include "chrome/browser/chromeos/settings/install_attributes.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 27 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 24 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
| 25 #include "components/prefs/testing_pref_service.h" | 29 #include "components/prefs/testing_pref_service.h" |
| 26 #include "components/signin/core/account_id/account_id.h" | 30 #include "components/signin/core/account_id/account_id.h" |
| 27 #include "components/sync_preferences/testing_pref_service_syncable.h" | 31 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 28 #include "components/user_manager/known_user.h" | 32 #include "components/user_manager/known_user.h" |
| 29 #include "components/user_manager/user_manager.h" | 33 #include "components/user_manager/user_manager.h" |
| 30 #include "components/user_manager/user_names.h" | 34 #include "components/user_manager/user_names.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 35 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 37 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 85 } |
| 82 | 86 |
| 83 void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); } | 87 void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); } |
| 84 | 88 |
| 85 chromeos::FakeChromeUserManager* fake_user_manager_; | 89 chromeos::FakeChromeUserManager* fake_user_manager_; |
| 86 const AccountId account_id_; | 90 const AccountId account_id_; |
| 87 | 91 |
| 88 DISALLOW_COPY_AND_ASSIGN(ScopedLogIn); | 92 DISALLOW_COPY_AND_ASSIGN(ScopedLogIn); |
| 89 }; | 93 }; |
| 90 | 94 |
| 95 class FakeInstallAttributesManaged : public chromeos::InstallAttributes { |
| 96 public: |
| 97 FakeInstallAttributesManaged() : chromeos::InstallAttributes(nullptr) { |
| 98 device_locked_ = true; |
| 99 } |
| 100 |
| 101 ~FakeInstallAttributesManaged() { |
| 102 policy::BrowserPolicyConnectorChromeOS::RemoveInstallAttributesForTesting(); |
| 103 } |
| 104 |
| 105 void SetIsManaged(bool is_managed) { |
| 106 registration_mode_ = is_managed ? policy::DEVICE_MODE_ENTERPRISE |
| 107 : policy::DEVICE_MODE_CONSUMER; |
| 108 } |
| 109 }; |
| 110 |
| 91 class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager { | 111 class FakeUserManagerWithLocalState : public chromeos::FakeChromeUserManager { |
| 92 public: | 112 public: |
| 93 FakeUserManagerWithLocalState() | 113 FakeUserManagerWithLocalState() |
| 94 : test_local_state_(base::MakeUnique<TestingPrefServiceSimple>()) { | 114 : test_local_state_(base::MakeUnique<TestingPrefServiceSimple>()) { |
| 95 RegisterPrefs(test_local_state_->registry()); | 115 RegisterPrefs(test_local_state_->registry()); |
| 96 } | 116 } |
| 97 | 117 |
| 98 PrefService* GetLocalState() const override { | 118 PrefService* GetLocalState() const override { |
| 99 return test_local_state_.get(); | 119 return test_local_state_.get(); |
| 100 } | 120 } |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 503 } |
| 484 | 504 |
| 485 // Test the IsActiveDirectoryUserForProfile() function for AD accounts. | 505 // Test the IsActiveDirectoryUserForProfile() function for AD accounts. |
| 486 TEST_F(ChromeArcUtilTest, IsActiveDirectoryUserForProfile_AD) { | 506 TEST_F(ChromeArcUtilTest, IsActiveDirectoryUserForProfile_AD) { |
| 487 ScopedLogIn login(GetFakeUserManager(), | 507 ScopedLogIn login(GetFakeUserManager(), |
| 488 AccountId::AdFromUserEmailObjGuid( | 508 AccountId::AdFromUserEmailObjGuid( |
| 489 profile()->GetProfileUserName(), kTestGaiaId)); | 509 profile()->GetProfileUserName(), kTestGaiaId)); |
| 490 EXPECT_TRUE(IsActiveDirectoryUserForProfile(profile())); | 510 EXPECT_TRUE(IsActiveDirectoryUserForProfile(profile())); |
| 491 } | 511 } |
| 492 | 512 |
| 513 class ArcMigrationTest : public testing::Test { |
| 514 protected: |
| 515 ArcMigrationTest() { |
| 516 auto attributes = base::MakeUnique<FakeInstallAttributesManaged>(); |
| 517 attributes_ = attributes.get(); |
| 518 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( |
| 519 attributes.release()); |
| 520 } |
| 521 ~ArcMigrationTest() override {} |
| 522 |
| 523 void SetUp() override { chromeos::DeviceSettingsService::Initialize(); } |
| 524 |
| 525 void TearDown() override { chromeos::DeviceSettingsService::Shutdown(); } |
| 526 |
| 527 void SetDeviceIsEnterpriseManaged(bool is_managed) { |
| 528 attributes_->SetIsManaged(is_managed); |
| 529 } |
| 530 |
| 531 FakeInstallAttributesManaged* attributes_; |
| 532 }; |
| 533 |
| 534 TEST_F(ArcMigrationTest, IsMigrationAllowedConsumerOwned) { |
| 535 ResetArcMigrationAllowedForTesting(); |
| 536 auto* const command_line = base::CommandLine::ForCurrentProcess(); |
| 537 command_line->InitFromArgv({"", "--need-arc-migration-policy-check", |
| 538 "--arc-availability=officially-supported"}); |
| 539 SetDeviceIsEnterpriseManaged(false); |
| 540 EXPECT_TRUE(IsArcMigrationAllowed()); |
| 541 } |
| 542 |
| 543 TEST_F(ArcMigrationTest, IsMigrationAllowedNoPolicy) { |
| 544 ResetArcMigrationAllowedForTesting(); |
| 545 auto* const command_line = base::CommandLine::ForCurrentProcess(); |
| 546 command_line->InitFromArgv({"", "--need-arc-migration-policy-check", |
| 547 "--arc-availability=officially-supported"}); |
| 548 SetDeviceIsEnterpriseManaged(true); |
| 549 EXPECT_FALSE(IsArcMigrationAllowed()); |
| 550 } |
| 551 |
| 493 } // namespace util | 552 } // namespace util |
| 494 } // namespace arc | 553 } // namespace arc |
| OLD | NEW |