OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/javascript_policy_handler.h" | 5 #include "chrome/browser/policy/javascript_policy_handler.h" |
6 #include "chrome/common/pref_names.h" | 6 #include "chrome/common/pref_names.h" |
7 #include "components/content_settings/core/common/content_settings.h" | 7 #include "components/content_settings/core/common/content_settings.h" |
8 #include "components/policy/core/browser/configuration_policy_pref_store.h" | 8 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
9 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" | 9 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" |
10 #include "components/policy/core/browser/policy_error_map.h" | 10 #include "components/policy/core/browser/policy_error_map.h" |
11 #include "components/policy/core/common/policy_map.h" | 11 #include "components/policy/core/common/policy_map.h" |
12 #include "components/policy/core/common/policy_types.h" | |
13 #include "policy/policy_constants.h" | 12 #include "policy/policy_constants.h" |
14 | 13 |
15 namespace policy { | 14 namespace policy { |
16 | 15 |
17 class JavascriptPolicyHandlerTest : public ConfigurationPolicyPrefStoreTest { | 16 class JavascriptPolicyHandlerTest : public ConfigurationPolicyPrefStoreTest { |
18 void SetUp() override { | 17 void SetUp() override { |
19 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( | 18 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( |
20 new JavascriptPolicyHandler)); | 19 new JavascriptPolicyHandler)); |
21 } | 20 } |
22 }; | 21 }; |
23 | 22 |
24 TEST_F(JavascriptPolicyHandlerTest, JavascriptEnabled) { | 23 TEST_F(JavascriptPolicyHandlerTest, JavascriptEnabled) { |
25 // This is a boolean policy, but affects an integer preference. | 24 // This is a boolean policy, but affects an integer preference. |
26 EXPECT_FALSE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL)); | 25 EXPECT_FALSE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL)); |
27 PolicyMap policy; | 26 PolicyMap policy; |
28 policy.Set(key::kJavascriptEnabled, | 27 policy.Set(key::kJavascriptEnabled, |
29 POLICY_LEVEL_MANDATORY, | 28 POLICY_LEVEL_MANDATORY, |
30 POLICY_SCOPE_USER, | 29 POLICY_SCOPE_USER, |
31 POLICY_SOURCE_CLOUD, | |
32 new base::FundamentalValue(true), | 30 new base::FundamentalValue(true), |
33 NULL); | 31 NULL); |
34 UpdateProviderPolicy(policy); | 32 UpdateProviderPolicy(policy); |
35 EXPECT_FALSE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL)); | 33 EXPECT_FALSE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL)); |
36 policy.Set(key::kJavascriptEnabled, | 34 policy.Set(key::kJavascriptEnabled, |
37 POLICY_LEVEL_MANDATORY, | 35 POLICY_LEVEL_MANDATORY, |
38 POLICY_SCOPE_USER, | 36 POLICY_SCOPE_USER, |
39 POLICY_SOURCE_CLOUD, | |
40 new base::FundamentalValue(false), | 37 new base::FundamentalValue(false), |
41 NULL); | 38 NULL); |
42 UpdateProviderPolicy(policy); | 39 UpdateProviderPolicy(policy); |
43 const base::Value* value = NULL; | 40 const base::Value* value = NULL; |
44 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, | 41 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, |
45 &value)); | 42 &value)); |
46 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK).Equals(value)); | 43 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK).Equals(value)); |
47 } | 44 } |
48 | 45 |
49 TEST_F(JavascriptPolicyHandlerTest, JavascriptEnabledOverridden) { | 46 TEST_F(JavascriptPolicyHandlerTest, JavascriptEnabledOverridden) { |
50 EXPECT_FALSE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL)); | 47 EXPECT_FALSE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL)); |
51 PolicyMap policy; | 48 PolicyMap policy; |
52 policy.Set(key::kJavascriptEnabled, | 49 policy.Set(key::kJavascriptEnabled, |
53 POLICY_LEVEL_MANDATORY, | 50 POLICY_LEVEL_MANDATORY, |
54 POLICY_SCOPE_USER, | 51 POLICY_SCOPE_USER, |
55 POLICY_SOURCE_CLOUD, | |
56 new base::FundamentalValue(false), | 52 new base::FundamentalValue(false), |
57 NULL); | 53 NULL); |
58 UpdateProviderPolicy(policy); | 54 UpdateProviderPolicy(policy); |
59 const base::Value* value = NULL; | 55 const base::Value* value = NULL; |
60 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, | 56 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, |
61 &value)); | 57 &value)); |
62 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK).Equals(value)); | 58 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK).Equals(value)); |
63 // DefaultJavaScriptSetting overrides JavascriptEnabled. | 59 // DefaultJavaScriptSetting overrides JavascriptEnabled. |
64 policy.Set(key::kDefaultJavaScriptSetting, | 60 policy.Set(key::kDefaultJavaScriptSetting, |
65 POLICY_LEVEL_MANDATORY, | 61 POLICY_LEVEL_MANDATORY, |
66 POLICY_SCOPE_USER, | 62 POLICY_SCOPE_USER, |
67 POLICY_SOURCE_CLOUD, | |
68 new base::FundamentalValue(CONTENT_SETTING_ALLOW), | 63 new base::FundamentalValue(CONTENT_SETTING_ALLOW), |
69 NULL); | 64 NULL); |
70 UpdateProviderPolicy(policy); | 65 UpdateProviderPolicy(policy); |
71 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, | 66 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, |
72 &value)); | 67 &value)); |
73 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_ALLOW).Equals(value)); | 68 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_ALLOW).Equals(value)); |
74 } | 69 } |
75 | 70 |
76 } // namespace policy | 71 } // namespace policy |
OLD | NEW |