Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / profiles / incognito_mode_policy_handler_unittest.cc
blobcd60671deb7f22605714d9f0112466b3ef3a5ef2
1 // Copyright 2013 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.
5 #include "chrome/browser/prefs/incognito_mode_prefs.h"
6 #include "chrome/browser/profiles/incognito_mode_policy_handler.h"
7 #include "chrome/common/pref_names.h"
8 #include "components/policy/core/browser/configuration_policy_pref_store.h"
9 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
10 #include "grit/generated_resources.h"
11 #include "policy/policy_constants.h"
13 namespace policy {
15 // Tests Incognito mode availability preference setting.
16 class IncognitoModePolicyHandlerTest
17 : public ConfigurationPolicyPrefStoreTest {
18 public:
19 virtual void SetUp() OVERRIDE {
20 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
21 new IncognitoModePolicyHandler));
23 protected:
24 static const int kIncognitoModeAvailabilityNotSet = -1;
26 enum ObsoleteIncognitoEnabledValue {
27 INCOGNITO_ENABLED_UNKNOWN,
28 INCOGNITO_ENABLED_TRUE,
29 INCOGNITO_ENABLED_FALSE
32 void SetPolicies(ObsoleteIncognitoEnabledValue incognito_enabled,
33 int availability) {
34 PolicyMap policy;
35 if (incognito_enabled != INCOGNITO_ENABLED_UNKNOWN) {
36 policy.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY,
37 POLICY_SCOPE_USER,
38 base::Value::CreateBooleanValue(
39 incognito_enabled == INCOGNITO_ENABLED_TRUE),
40 NULL);
42 if (availability >= 0) {
43 policy.Set(key::kIncognitoModeAvailability, POLICY_LEVEL_MANDATORY,
44 POLICY_SCOPE_USER,
45 base::Value::CreateIntegerValue(availability),
46 NULL);
48 UpdateProviderPolicy(policy);
51 void VerifyValues(IncognitoModePrefs::Availability availability) {
52 const base::Value* value = NULL;
53 EXPECT_TRUE(store_->GetValue(prefs::kIncognitoModeAvailability, &value));
54 EXPECT_TRUE(base::FundamentalValue(availability).Equals(value));
58 // The following testcases verify that if the obsolete IncognitoEnabled
59 // policy is not set, the IncognitoModeAvailability values should be copied
60 // from IncognitoModeAvailability policy to pref "as is".
61 TEST_F(IncognitoModePolicyHandlerTest,
62 NoObsoletePolicyAndIncognitoEnabled) {
63 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED);
64 VerifyValues(IncognitoModePrefs::ENABLED);
67 TEST_F(IncognitoModePolicyHandlerTest,
68 NoObsoletePolicyAndIncognitoDisabled) {
69 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::DISABLED);
70 VerifyValues(IncognitoModePrefs::DISABLED);
73 TEST_F(IncognitoModePolicyHandlerTest,
74 NoObsoletePolicyAndIncognitoForced) {
75 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::FORCED);
76 VerifyValues(IncognitoModePrefs::FORCED);
79 TEST_F(IncognitoModePolicyHandlerTest,
80 NoObsoletePolicyAndNoIncognitoAvailability) {
81 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, kIncognitoModeAvailabilityNotSet);
82 const base::Value* value = NULL;
83 EXPECT_FALSE(store_->GetValue(prefs::kIncognitoModeAvailability, &value));
86 // Checks that if the obsolete IncognitoEnabled policy is set, if sets
87 // the IncognitoModeAvailability preference only in case
88 // the IncognitoModeAvailability policy is not specified.
89 TEST_F(IncognitoModePolicyHandlerTest,
90 ObsoletePolicyDoesNotAffectAvailabilityEnabled) {
91 SetPolicies(INCOGNITO_ENABLED_FALSE, IncognitoModePrefs::ENABLED);
92 VerifyValues(IncognitoModePrefs::ENABLED);
95 TEST_F(IncognitoModePolicyHandlerTest,
96 ObsoletePolicyDoesNotAffectAvailabilityForced) {
97 SetPolicies(INCOGNITO_ENABLED_TRUE, IncognitoModePrefs::FORCED);
98 VerifyValues(IncognitoModePrefs::FORCED);
101 TEST_F(IncognitoModePolicyHandlerTest,
102 ObsoletePolicySetsPreferenceToEnabled) {
103 SetPolicies(INCOGNITO_ENABLED_TRUE, kIncognitoModeAvailabilityNotSet);
104 VerifyValues(IncognitoModePrefs::ENABLED);
107 TEST_F(IncognitoModePolicyHandlerTest,
108 ObsoletePolicySetsPreferenceToDisabled) {
109 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet);
110 VerifyValues(IncognitoModePrefs::DISABLED);
113 } // namespace policy