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/policy/javascript_policy_handler.h"
6 #include "chrome/common/pref_names.h"
7 #include "components/content_settings/core/common/content_settings.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 "components/policy/core/browser/policy_error_map.h"
11 #include "components/policy/core/common/policy_map.h"
12 #include "policy/policy_constants.h"
16 class JavascriptPolicyHandlerTest
: public ConfigurationPolicyPrefStoreTest
{
17 void SetUp() override
{
18 handler_list_
.AddHandler(make_scoped_ptr
<ConfigurationPolicyHandler
>(
19 new JavascriptPolicyHandler
));
23 TEST_F(JavascriptPolicyHandlerTest
, JavascriptEnabled
) {
24 // This is a boolean policy, but affects an integer preference.
25 EXPECT_FALSE(store_
->GetValue(prefs::kManagedDefaultJavaScriptSetting
, NULL
));
27 policy
.Set(key::kJavascriptEnabled
,
28 POLICY_LEVEL_MANDATORY
,
30 new base::FundamentalValue(true),
32 UpdateProviderPolicy(policy
);
33 EXPECT_FALSE(store_
->GetValue(prefs::kManagedDefaultJavaScriptSetting
, NULL
));
34 policy
.Set(key::kJavascriptEnabled
,
35 POLICY_LEVEL_MANDATORY
,
37 new base::FundamentalValue(false),
39 UpdateProviderPolicy(policy
);
40 const base::Value
* value
= NULL
;
41 EXPECT_TRUE(store_
->GetValue(prefs::kManagedDefaultJavaScriptSetting
,
43 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK
).Equals(value
));
46 TEST_F(JavascriptPolicyHandlerTest
, JavascriptEnabledOverridden
) {
47 EXPECT_FALSE(store_
->GetValue(prefs::kManagedDefaultJavaScriptSetting
, NULL
));
49 policy
.Set(key::kJavascriptEnabled
,
50 POLICY_LEVEL_MANDATORY
,
52 new base::FundamentalValue(false),
54 UpdateProviderPolicy(policy
);
55 const base::Value
* value
= NULL
;
56 EXPECT_TRUE(store_
->GetValue(prefs::kManagedDefaultJavaScriptSetting
,
58 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK
).Equals(value
));
59 // DefaultJavaScriptSetting overrides JavascriptEnabled.
60 policy
.Set(key::kDefaultJavaScriptSetting
,
61 POLICY_LEVEL_MANDATORY
,
63 new base::FundamentalValue(CONTENT_SETTING_ALLOW
),
65 UpdateProviderPolicy(policy
);
66 EXPECT_TRUE(store_
->GetValue(prefs::kManagedDefaultJavaScriptSetting
,
68 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_ALLOW
).Equals(value
));