| 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
 | 
| 
 |