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

Unified Diff: chrome/browser/profiles/guest_mode_policy_handler_unittest.cc

Issue 2530943002: Disable guest mode by default if force sign in is enabled. (Closed)
Patch Set: fix presubmit warning Created 4 years, 1 month 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/profiles/guest_mode_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/profiles/guest_mode_policy_handler_unittest.cc
diff --git a/chrome/browser/profiles/guest_mode_policy_handler_unittest.cc b/chrome/browser/profiles/guest_mode_policy_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4b6e81c0a787731bae310e7362b39dd65ec9aee9
--- /dev/null
+++ b/chrome/browser/profiles/guest_mode_policy_handler_unittest.cc
@@ -0,0 +1,89 @@
+// 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/profiles/guest_mode_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 GuestModePolicyHandlerTest : public ::testing::Test {
+ public:
+ void SetUp() override {
+ prefs_.Clear();
+ policies_.Clear();
+ }
+
+ protected:
+ void SetUpPolicy(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);
+ }
+
+ void SetUpPolicy(const char* policy_name, int value) {
+ policies_.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
+ POLICY_SOURCE_PLATFORM,
+ base::MakeUnique<base::FundamentalValue>(value), nullptr);
+ }
+
+ PolicyMap policies_;
+ PrefValueMap prefs_;
+ GuestModePolicyHandler handler_;
+};
+
+TEST_F(GuestModePolicyHandlerTest, ForceSigninNotSet) {
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_FALSE(prefs_.GetValue(prefs::kBrowserGuestModeEnabled, nullptr));
+}
+
+TEST_F(GuestModePolicyHandlerTest, ForceSigninDisabled) {
+ SetUpPolicy(key::kForceBrowserSignin, false);
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_FALSE(prefs_.GetValue(prefs::kBrowserGuestModeEnabled, nullptr));
+
+ SetUpPolicy(key::kForceBrowserSignin, 0); // Invalid format
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_FALSE(prefs_.GetValue(prefs::kBrowserGuestModeEnabled, nullptr));
+}
+
+TEST_F(GuestModePolicyHandlerTest, GuestModeDisabledByDefault) {
+ bool value;
+ SetUpPolicy(key::kForceBrowserSignin, true);
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
+ EXPECT_FALSE(value);
+}
+
+TEST_F(GuestModePolicyHandlerTest,
+ GuestModeDisabledByDefaultWithInvalidFormat) {
+ bool value;
+ SetUpPolicy(key::kForceBrowserSignin, true);
+ SetUpPolicy(key::kBrowserGuestModeEnabled, 0);
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
+ EXPECT_FALSE(value);
+}
+
+TEST_F(GuestModePolicyHandlerTest, GuestModeSet) {
+ bool value;
+ SetUpPolicy(key::kForceBrowserSignin, true);
+ SetUpPolicy(key::kBrowserGuestModeEnabled, true);
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
+ EXPECT_TRUE(value);
+
+ SetUpPolicy(key::kBrowserGuestModeEnabled, false);
+ handler_.ApplyPolicySettings(policies_, &prefs_);
+ EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
+ EXPECT_FALSE(value);
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/profiles/guest_mode_policy_handler.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698