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

Side by Side 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 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
« no previous file with comments | « chrome/browser/profiles/guest_mode_policy_handler.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/profiles/guest_mode_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 GuestModePolicyHandlerTest : public ::testing::Test {
18 public:
19 void SetUp() override {
20 prefs_.Clear();
21 policies_.Clear();
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 void SetUpPolicy(const char* policy_name, int value) {
32 policies_.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
33 POLICY_SOURCE_PLATFORM,
34 base::MakeUnique<base::FundamentalValue>(value), nullptr);
35 }
36
37 PolicyMap policies_;
38 PrefValueMap prefs_;
39 GuestModePolicyHandler handler_;
40 };
41
42 TEST_F(GuestModePolicyHandlerTest, ForceSigninNotSet) {
43 handler_.ApplyPolicySettings(policies_, &prefs_);
44 EXPECT_FALSE(prefs_.GetValue(prefs::kBrowserGuestModeEnabled, nullptr));
45 }
46
47 TEST_F(GuestModePolicyHandlerTest, ForceSigninDisabled) {
48 SetUpPolicy(key::kForceBrowserSignin, false);
49 handler_.ApplyPolicySettings(policies_, &prefs_);
50 EXPECT_FALSE(prefs_.GetValue(prefs::kBrowserGuestModeEnabled, nullptr));
51
52 SetUpPolicy(key::kForceBrowserSignin, 0); // Invalid format
53 handler_.ApplyPolicySettings(policies_, &prefs_);
54 EXPECT_FALSE(prefs_.GetValue(prefs::kBrowserGuestModeEnabled, nullptr));
55 }
56
57 TEST_F(GuestModePolicyHandlerTest, GuestModeDisabledByDefault) {
58 bool value;
59 SetUpPolicy(key::kForceBrowserSignin, true);
60 handler_.ApplyPolicySettings(policies_, &prefs_);
61 EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
62 EXPECT_FALSE(value);
63 }
64
65 TEST_F(GuestModePolicyHandlerTest,
66 GuestModeDisabledByDefaultWithInvalidFormat) {
67 bool value;
68 SetUpPolicy(key::kForceBrowserSignin, true);
69 SetUpPolicy(key::kBrowserGuestModeEnabled, 0);
70 handler_.ApplyPolicySettings(policies_, &prefs_);
71 EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
72 EXPECT_FALSE(value);
73 }
74
75 TEST_F(GuestModePolicyHandlerTest, GuestModeSet) {
76 bool value;
77 SetUpPolicy(key::kForceBrowserSignin, true);
78 SetUpPolicy(key::kBrowserGuestModeEnabled, true);
79 handler_.ApplyPolicySettings(policies_, &prefs_);
80 EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
81 EXPECT_TRUE(value);
82
83 SetUpPolicy(key::kBrowserGuestModeEnabled, false);
84 handler_.ApplyPolicySettings(policies_, &prefs_);
85 EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
86 EXPECT_FALSE(value);
87 }
88
89 } // namespace policy
OLDNEW
« 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