Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / messaging / native_messaging_policy_handler_unittest.cc
blob3e2902a7704f769381c7738ed84b15864eeb0544
1 // Copyright 2014 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/extensions/api/messaging/native_messaging_policy_handler.h"
7 #include "base/prefs/pref_value_map.h"
8 #include "chrome/browser/extensions/policy_handlers.h"
9 #include "components/policy/core/browser/policy_error_map.h"
10 #include "components/policy/core/common/policy_map.h"
11 #include "policy/policy_constants.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace extensions {
16 const char kTestPref[] = "unit_test.test_pref";
18 TEST(NativeMessagingHostListPolicyHandlerTest, CheckPolicySettings) {
19 base::ListValue list;
20 policy::PolicyMap policy_map;
21 NativeMessagingHostListPolicyHandler handler(
22 policy::key::kNativeMessagingBlacklist, kTestPref, true);
24 policy_map.Set(policy::key::kNativeMessagingBlacklist,
25 policy::POLICY_LEVEL_MANDATORY,
26 policy::POLICY_SCOPE_USER,
27 list.DeepCopy(),
28 NULL);
30 policy::PolicyErrorMap errors;
31 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
32 EXPECT_TRUE(errors.empty());
35 list.Append(new base::StringValue("test.a.b"));
36 policy_map.Set(policy::key::kNativeMessagingBlacklist,
37 policy::POLICY_LEVEL_MANDATORY,
38 policy::POLICY_SCOPE_USER,
39 list.DeepCopy(),
40 NULL);
42 policy::PolicyErrorMap errors;
43 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
44 EXPECT_TRUE(errors.empty());
47 list.Append(new base::StringValue("*"));
48 policy_map.Set(policy::key::kNativeMessagingBlacklist,
49 policy::POLICY_LEVEL_MANDATORY,
50 policy::POLICY_SCOPE_USER,
51 list.DeepCopy(),
52 NULL);
54 policy::PolicyErrorMap errors;
55 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
56 EXPECT_TRUE(errors.empty());
59 list.Append(new base::StringValue("invalid Name"));
60 policy_map.Set(policy::key::kNativeMessagingBlacklist,
61 policy::POLICY_LEVEL_MANDATORY,
62 policy::POLICY_SCOPE_USER,
63 list.DeepCopy(),
64 NULL);
66 policy::PolicyErrorMap errors;
67 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
68 EXPECT_FALSE(errors.empty());
69 EXPECT_FALSE(
70 errors.GetErrors(policy::key::kNativeMessagingBlacklist).empty());
74 TEST(NativeMessagingHostListPolicyHandlerTest, ApplyPolicySettings) {
75 base::ListValue policy;
76 base::ListValue expected;
77 policy::PolicyMap policy_map;
78 PrefValueMap prefs;
79 base::Value* value = NULL;
80 NativeMessagingHostListPolicyHandler handler(
81 policy::key::kNativeMessagingBlacklist, kTestPref, true);
83 policy.Append(new base::StringValue("com.example.test"));
84 expected.Append(new base::StringValue("com.example.test"));
86 policy_map.Set(policy::key::kNativeMessagingBlacklist,
87 policy::POLICY_LEVEL_MANDATORY,
88 policy::POLICY_SCOPE_USER,
89 policy.DeepCopy(),
90 NULL);
91 handler.ApplyPolicySettings(policy_map, &prefs);
92 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
93 EXPECT_TRUE(base::Value::Equals(&expected, value));
95 policy.Append(new base::StringValue("*"));
96 expected.Append(new base::StringValue("*"));
98 policy_map.Set(policy::key::kNativeMessagingBlacklist,
99 policy::POLICY_LEVEL_MANDATORY,
100 policy::POLICY_SCOPE_USER,
101 policy.DeepCopy(),
102 NULL);
103 handler.ApplyPolicySettings(policy_map, &prefs);
104 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
105 EXPECT_TRUE(base::Value::Equals(&expected, value));
107 policy.Append(new base::StringValue("invalid Name"));
108 policy_map.Set(policy::key::kNativeMessagingBlacklist,
109 policy::POLICY_LEVEL_MANDATORY,
110 policy::POLICY_SCOPE_USER,
111 policy.DeepCopy(),
112 NULL);
113 handler.ApplyPolicySettings(policy_map, &prefs);
114 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
115 EXPECT_TRUE(base::Value::Equals(&expected, value));
118 } // namespace extensions