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

Unified Diff: chrome/browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc

Issue 2551373002: Disable supervised user creation when force sign in is enabled. (Closed)
Patch Set: merge from master Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_creation_policy_handler.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc
diff --git a/chrome/browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc b/chrome/browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6915e3a193571f36f956fc4444a1be4fd09f745c
--- /dev/null
+++ b/chrome/browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc
@@ -0,0 +1,92 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/supervised_user/supervised_user_creation_policy_handler.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
+#include "chrome/common/pref_names.h"
+#include "components/policy/core/common/policy_map.h"
+#include "components/policy/policy_constants.h"
+#include "components/prefs/pref_value_map.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace policy {
+
+class SupervisedUserCreationPolicyHandlerTest : public ::testing::Test {
+ protected:
+ void SetUpPolicyAndApply(const char* policy_name, bool value) {
+ policies_.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
+ POLICY_SOURCE_PLATFORM,
+ base::MakeUnique<base::FundamentalValue>(value), nullptr);
+ ApplyPolicySettings();
+ }
+
+ void ApplyPolicySettings() {
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ }
+
+ PrefValueMap* prefs() { return &prefs_; }
+
+ private:
+ PolicyMap policies_;
+ PrefValueMap prefs_;
+ SupervisedUserCreationPolicyHandler handler_;
+};
+
+TEST_F(SupervisedUserCreationPolicyHandlerTest, ForceSigninNotSet) {
+ ApplyPolicySettings();
+ EXPECT_FALSE(
+ prefs()->GetValue(prefs::kSupervisedUserCreationAllowed, nullptr));
+
+ bool value;
+ SetUpPolicyAndApply(key::kSupervisedUserCreationEnabled, true);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_TRUE(value);
+
+ SetUpPolicyAndApply(key::kSupervisedUserCreationEnabled, false);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_FALSE(value);
+}
+
+TEST_F(SupervisedUserCreationPolicyHandlerTest, ForceSigninDisabled) {
+ SetUpPolicyAndApply(key::kForceBrowserSignin, false);
+ EXPECT_FALSE(
+ prefs()->GetValue(prefs::kSupervisedUserCreationAllowed, nullptr));
+
+ bool value;
+ SetUpPolicyAndApply(key::kSupervisedUserCreationEnabled, true);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_TRUE(value);
+
+ SetUpPolicyAndApply(key::kSupervisedUserCreationEnabled, false);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_FALSE(value);
+}
+
+TEST_F(SupervisedUserCreationPolicyHandlerTest, ForceSigninEnabled) {
+ bool value;
+ SetUpPolicyAndApply(key::kForceBrowserSignin, true);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_FALSE(value);
+
+ // When force sign in is enabled, the supervised user creation will be
+ // disabled even if the policy is set to true.
+ SetUpPolicyAndApply(key::kSupervisedUserCreationEnabled, true);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_FALSE(value);
+
+ SetUpPolicyAndApply(key::kSupervisedUserCreationEnabled, false);
+ EXPECT_TRUE(
+ prefs()->GetBoolean(prefs::kSupervisedUserCreationAllowed, &value));
+ EXPECT_FALSE(value);
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_creation_policy_handler.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698