Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/extensions/api/messaging/native_messaging_policy_handler_unittest.cc

Issue 118253005: Add managed policies for Native Messaging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handle r.h"
6
7 #include "base/prefs/pref_value_map.h"
8 #include "chrome/browser/extensions/policy_handlers.h"
9 #include "chrome/common/pref_names.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"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace extensions {
16
17 const char kTestPref[] = "unit_test.test_pref";
18
19 TEST(NativeMessagingHostListPolicyHandlerTest, CheckPolicySettings) {
20 base::ListValue list;
21 policy::PolicyMap policy_map;
22 policy::PolicyErrorMap errors;
23 NativeMessagingHostListPolicyHandler handler(
24 policy::key::kNativeMessagingBlacklist, kTestPref, true);
25
26 policy_map.Set(policy::key::kNativeMessagingBlacklist,
27 policy::POLICY_LEVEL_MANDATORY,
28 policy::POLICY_SCOPE_USER,
29 list.DeepCopy(),
30 NULL);
31 errors.Clear();
32 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
33 EXPECT_TRUE(errors.empty());
not at google - send to devlin 2013/12/28 04:55:51 fwiw, rather than this pattern of constantly clear
Sergey Ulanov 2014/01/06 23:21:55 Done.
34
35 list.Append(
36 base::Value::CreateStringValue("test.a.b"));
37 policy_map.Set(policy::key::kNativeMessagingBlacklist,
38 policy::POLICY_LEVEL_MANDATORY,
39 policy::POLICY_SCOPE_USER,
40 list.DeepCopy(),
41 NULL);
42 errors.Clear();
43 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
44 EXPECT_TRUE(errors.empty());
45
46 list.Append(base::Value::CreateStringValue("*"));
47 policy_map.Set(policy::key::kNativeMessagingBlacklist,
48 policy::POLICY_LEVEL_MANDATORY,
49 policy::POLICY_SCOPE_USER,
50 list.DeepCopy(),
51 NULL);
52 errors.Clear();
53 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
54 EXPECT_TRUE(errors.empty());
55
56 list.Append(base::Value::CreateStringValue("invalid Name"));
57 policy_map.Set(policy::key::kNativeMessagingBlacklist,
58 policy::POLICY_LEVEL_MANDATORY,
59 policy::POLICY_SCOPE_USER,
60 list.DeepCopy(),
61 NULL);
62 errors.Clear();
63 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
64 EXPECT_FALSE(errors.empty());
65 EXPECT_FALSE(
66 errors.GetErrors(policy::key::kNativeMessagingBlacklist).empty());
not at google - send to devlin 2013/12/28 04:55:51 can you actually assert that the content here is w
Sergey Ulanov 2014/01/06 23:21:55 The error message is localized, so I don't think i
67 }
68
69 TEST(NativeMessagingHostListPolicyHandlerTest, ApplyPolicySettings) {
70 base::ListValue policy;
71 base::ListValue expected;
72 policy::PolicyMap policy_map;
73 PrefValueMap prefs;
74 base::Value* value = NULL;
75 NativeMessagingHostListPolicyHandler handler(
76 policy::key::kNativeMessagingBlacklist, kTestPref, false);
77
78 policy.Append(
79 base::Value::CreateStringValue("com.example.test"));
80 expected.Append(
81 base::Value::CreateStringValue("com.example.test"));
not at google - send to devlin 2013/12/28 04:55:51 new StringValue
Sergey Ulanov 2014/01/06 23:21:55 Done.
82
83 policy_map.Set(policy::key::kNativeMessagingBlacklist,
84 policy::POLICY_LEVEL_MANDATORY,
85 policy::POLICY_SCOPE_USER,
86 policy.DeepCopy(),
87 NULL);
88 handler.ApplyPolicySettings(policy_map, &prefs);
89 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
90 EXPECT_TRUE(base::Value::Equals(&expected, value));
91
not at google - send to devlin 2013/12/28 04:55:51 would it be useful to test the wildcard in here so
Sergey Ulanov 2014/01/06 23:21:55 Done.
92 policy.Append(base::Value::CreateStringValue("invalid Name"));
93 policy_map.Set(policy::key::kNativeMessagingBlacklist,
94 policy::POLICY_LEVEL_MANDATORY,
95 policy::POLICY_SCOPE_USER,
96 policy.DeepCopy(),
97 NULL);
98 handler.ApplyPolicySettings(policy_map, &prefs);
99 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
100 EXPECT_TRUE(base::Value::Equals(&expected, value));
101 }
102
103 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698