Skip to content

Commit

Permalink
Merge Do not disable guest mode when BrowserSignin override ForceBrow…
Browse files Browse the repository at this point in the history
…esrSignin without a forced value.

Merge the patch into M71.

Bug: 894212
Change-Id: Icd4c7d9f8a79a9b57900366d4677b0e7023b8ca3
Reviewed-on: https://chromium-review.googlesource.com/c/1274196
Commit-Queue: Owen Min <[email protected]>
Reviewed-by: Mihai Sardarescu <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#599247}(cherry picked from commit df7614e)
Reviewed-on: https://chromium-review.googlesource.com/c/1284729
Reviewed-by: Owen Min <[email protected]>
Cr-Commit-Position: refs/branch-heads/3578@{#66}
Cr-Branched-From: 4226ddf-refs/heads/master@{#599034}
  • Loading branch information
Owen Min committed Oct 16, 2018
1 parent d1f593a commit fba7803
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions chrome/browser/profiles/guest_mode_policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ void GuestModePolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
const base::Value* browser_signin_value =
policies.GetValue(key::kBrowserSignin);
int int_browser_signin_value;
if (browser_signin_value &&
browser_signin_value->GetAsInteger(&int_browser_signin_value) &&
bool is_browser_signin_policy_set =
(browser_signin_value &&
browser_signin_value->GetAsInteger(&int_browser_signin_value));
if (is_browser_signin_policy_set &&
static_cast<BrowserSigninMode>(int_browser_signin_value) ==
BrowserSigninMode::kForced) {
prefs->SetBoolean(prefs::kBrowserGuestModeEnabled, false);
Expand All @@ -43,7 +45,7 @@ void GuestModePolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
const base::Value* force_signin_value =
policies.GetValue(key::kForceBrowserSignin);
bool is_force_signin_enabled;
if (force_signin_value &&
if (!is_browser_signin_policy_set && force_signin_value &&
force_signin_value->GetAsBoolean(&is_force_signin_enabled) &&
is_force_signin_enabled) {
prefs->SetBoolean(prefs::kBrowserGuestModeEnabled, false);
Expand Down
36 changes: 36 additions & 0 deletions chrome/browser/profiles/guest_mode_policy_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/profiles/guest_mode_policy_handler.h"

#include "base/values.h"
#include "chrome/browser/policy/browser_signin_policy_handler.h"
#include "chrome/common/pref_names.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
Expand Down Expand Up @@ -85,4 +86,39 @@ TEST_F(GuestModePolicyHandlerTest, GuestModeSet) {
EXPECT_FALSE(value);
}

TEST_F(GuestModePolicyHandlerTest, GuestModeDisabledWhenBrowserSigninIsForced) {
SetUpPolicy(key::kBrowserSignin,
static_cast<int>(BrowserSigninMode::kForced));
handler_.ApplyPolicySettings(policies_, &prefs_);
bool value = true;
EXPECT_TRUE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
EXPECT_FALSE(value);
}

TEST_F(GuestModePolicyHandlerTest,
GuestModeIsNotSetWhenBrowserSigninIsNotForced) {
bool value = false;
SetUpPolicy(key::kBrowserSignin,
static_cast<int>(BrowserSigninMode::kEnabled));
handler_.ApplyPolicySettings(policies_, &prefs_);
EXPECT_FALSE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));

SetUpPolicy(key::kBrowserSignin,
static_cast<int>(BrowserSigninMode::kDisabled));
handler_.ApplyPolicySettings(policies_, &prefs_);
EXPECT_FALSE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));

// Invalid format
SetUpPolicy(key::kBrowserSignin, false);
handler_.ApplyPolicySettings(policies_, &prefs_);
EXPECT_FALSE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));

// Even with forceBrowserSignin enable.
SetUpPolicy(key::kBrowserSignin,
static_cast<int>(BrowserSigninMode::kEnabled));
SetUpPolicy(key::kForceBrowserSignin, true);
handler_.ApplyPolicySettings(policies_, &prefs_);
EXPECT_FALSE(prefs_.GetBoolean(prefs::kBrowserGuestModeEnabled, &value));
}

} // namespace policy

0 comments on commit fba7803

Please sign in to comment.