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

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

Issue 2890843002: Policy implementation for encryptfs to ext4 migration strategy (Closed)
Patch Set: Fixed the test Created 3 years, 6 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 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
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 profile()->GetTestingPrefService()->SetManagedPref( 487 profile()->GetTestingPrefService()->SetManagedPref(
468 prefs::kArcLocationServiceEnabled, base::MakeUnique<base::Value>(false)); 488 prefs::kArcLocationServiceEnabled, base::MakeUnique<base::Value>(false));
469 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile())); 489 EXPECT_FALSE(AreArcAllOptInPreferencesManagedForProfile(profile()));
470 490
471 // Both OptIn prefs are set to managed values, and the function returns true. 491 // Both OptIn prefs are set to managed values, and the function returns true.
472 profile()->GetTestingPrefService()->SetManagedPref( 492 profile()->GetTestingPrefService()->SetManagedPref(
473 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false)); 493 prefs::kArcBackupRestoreEnabled, base::MakeUnique<base::Value>(false));
474 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile())); 494 EXPECT_TRUE(AreArcAllOptInPreferencesManagedForProfile(profile()));
475 } 495 }
476 496
497 class ArcMigrationTest : public testing::Test {
498 protected:
499 ArcMigrationTest() {
500 auto attributes = base::MakeUnique<FakeInstallAttributesManaged>();
501 attributes_ = attributes.get();
502 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
503 attributes.release());
504 }
505 ~ArcMigrationTest() override {}
506
507 void SetUp() override { chromeos::DeviceSettingsService::Initialize(); }
508
509 void TearDown() override { chromeos::DeviceSettingsService::Shutdown(); }
510
511 void SetDeviceIsEnterpriseManaged(bool is_managed) {
512 attributes_->SetIsManaged(is_managed);
513 }
514
515 FakeInstallAttributesManaged* attributes_;
516 };
517
518 TEST_F(ArcMigrationTest, IsMigrationAllowedConsumerOwned) {
519 ResetArcMigrationAllowedForTesting();
520 auto* const command_line = base::CommandLine::ForCurrentProcess();
521 command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
522 "--arc-availability=officially-supported"});
523 SetDeviceIsEnterpriseManaged(false);
524 EXPECT_TRUE(IsArcMigrationAllowed());
525 }
526
527 TEST_F(ArcMigrationTest, IsMigrationAllowedNoPolicy) {
bartfab (slow) 2017/06/21 21:31:16 You used to have tests for policy set to disallow/
igorcov 2017/06/22 09:31:23 Yes, I've removed the tests that involved the poli
528 ResetArcMigrationAllowedForTesting();
529 auto* const command_line = base::CommandLine::ForCurrentProcess();
530 command_line->InitFromArgv({"", "--need-arc-migration-policy-check",
531 "--arc-availability=officially-supported"});
532 SetDeviceIsEnterpriseManaged(true);
533 EXPECT_FALSE(IsArcMigrationAllowed());
534 }
535
477 } // namespace util 536 } // namespace util
478 } // namespace arc 537 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_util.cc ('k') | chrome/browser/chromeos/login/existing_user_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698