Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/supervised_user/supervised_user_creation_policy_handler .h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/common/pref_names.h" | |
| 10 #include "components/policy/core/common/policy_map.h" | |
| 11 #include "components/policy/policy_constants.h" | |
| 12 #include "components/prefs/pref_value_map.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace policy { | |
| 16 | |
| 17 class SupervisedUserCreationPolicyHandlerTest : public ::testing::Test { | |
| 18 public: | |
| 19 void SetUp() override { | |
| 20 prefs_.Clear(); | |
| 21 policies_.Clear(); | |
|
Marc Treib
2016/12/06 09:28:37
I don't think this is necessary, these shouldn't s
zmin
2016/12/06 17:04:55
Removed.
| |
| 22 } | |
| 23 | |
| 24 protected: | |
| 25 void SetUpPolicy(const char* policy_name, bool value) { | |
| 26 policies_.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | |
| 27 POLICY_SOURCE_PLATFORM, | |
| 28 base::MakeUnique<base::FundamentalValue>(value), nullptr); | |
| 29 } | |
| 30 | |
| 31 PolicyMap policies_; | |
| 32 PrefValueMap prefs_; | |
| 33 SupervisedUserCreationPolicyHandler handler_; | |
| 34 }; | |
| 35 | |
| 36 TEST_F(SupervisedUserCreationPolicyHandlerTest, ForceSigninNotSet) { | |
| 37 handler_.ApplyPolicySettings(policies_, &prefs_); | |
|
Marc Treib
2016/12/06 09:28:36
Maybe make a helper method for this, and make poli
zmin
2016/12/06 17:04:55
Done.
| |
| 38 EXPECT_FALSE(prefs_.GetValue(prefs::kSupervisedUserCreationAllowed, nullptr)); | |
|
Marc Treib
2016/12/06 09:28:36
Should this also test that setting the key::kSuper
zmin
2016/12/06 17:04:55
Done.
| |
| 39 } | |
| 40 | |
| 41 TEST_F(SupervisedUserCreationPolicyHandlerTest, ForceSigninDisabled) { | |
| 42 SetUpPolicy(key::kForceBrowserSignin, false); | |
| 43 handler_.ApplyPolicySettings(policies_, &prefs_); | |
| 44 EXPECT_FALSE(prefs_.GetValue(prefs::kSupervisedUserCreationAllowed, nullptr)); | |
| 45 | |
| 46 bool value; | |
| 47 SetUpPolicy(key::kSupervisedUserCreationEnabled, true); | |
| 48 handler_.ApplyPolicySettings(policies_, &prefs_); | |
| 49 EXPECT_TRUE(prefs_.GetBoolean(prefs::kSupervisedUserCreationAllowed, &value)); | |
| 50 EXPECT_TRUE(value); | |
| 51 | |
| 52 SetUpPolicy(key::kSupervisedUserCreationEnabled, false); | |
| 53 handler_.ApplyPolicySettings(policies_, &prefs_); | |
| 54 EXPECT_TRUE(prefs_.GetBoolean(prefs::kSupervisedUserCreationAllowed, &value)); | |
| 55 EXPECT_FALSE(value); | |
| 56 } | |
| 57 | |
| 58 TEST_F(SupervisedUserCreationPolicyHandlerTest, ForceSigninEnabled) { | |
| 59 bool value; | |
| 60 SetUpPolicy(key::kForceBrowserSignin, true); | |
| 61 handler_.ApplyPolicySettings(policies_, &prefs_); | |
| 62 EXPECT_TRUE(prefs_.GetBoolean(prefs::kSupervisedUserCreationAllowed, &value)); | |
| 63 EXPECT_FALSE(value); | |
| 64 | |
| 65 SetUpPolicy(key::kSupervisedUserCreationEnabled, true); | |
| 66 handler_.ApplyPolicySettings(policies_, &prefs_); | |
| 67 EXPECT_TRUE(prefs_.GetBoolean(prefs::kSupervisedUserCreationAllowed, &value)); | |
| 68 EXPECT_FALSE(value); | |
|
Marc Treib
2016/12/06 09:28:37
IMO this deserves a comment.
zmin
2016/12/06 17:04:55
Done.
| |
| 69 | |
| 70 SetUpPolicy(key::kSupervisedUserCreationEnabled, false); | |
| 71 handler_.ApplyPolicySettings(policies_, &prefs_); | |
| 72 EXPECT_TRUE(prefs_.GetBoolean(prefs::kSupervisedUserCreationAllowed, &value)); | |
| 73 EXPECT_FALSE(value); | |
| 74 } | |
| 75 | |
| 76 } // namespace policy | |
| 77 | |
| OLD | NEW |