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

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

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/extensions/api/messaging/native_messaging_policy_handle r.h" 5 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handle r.h"
6 6
7 #include "base/prefs/pref_value_map.h" 7 #include "base/prefs/pref_value_map.h"
8 #include "chrome/browser/extensions/policy_handlers.h" 8 #include "chrome/browser/extensions/policy_handlers.h"
9 #include "components/policy/core/browser/policy_error_map.h" 9 #include "components/policy/core/browser/policy_error_map.h"
10 #include "components/policy/core/common/policy_map.h" 10 #include "components/policy/core/common/policy_map.h"
11 #include "components/policy/core/common/policy_types.h"
11 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 const char kTestPref[] = "unit_test.test_pref"; 17 const char kTestPref[] = "unit_test.test_pref";
17 18
18 TEST(NativeMessagingHostListPolicyHandlerTest, CheckPolicySettings) { 19 TEST(NativeMessagingHostListPolicyHandlerTest, CheckPolicySettings) {
19 base::ListValue list; 20 base::ListValue list;
20 policy::PolicyMap policy_map; 21 policy::PolicyMap policy_map;
21 NativeMessagingHostListPolicyHandler handler( 22 NativeMessagingHostListPolicyHandler handler(
22 policy::key::kNativeMessagingBlacklist, kTestPref, true); 23 policy::key::kNativeMessagingBlacklist, kTestPref, true);
23 24
24 policy_map.Set(policy::key::kNativeMessagingBlacklist, 25 policy_map.Set(policy::key::kNativeMessagingBlacklist,
25 policy::POLICY_LEVEL_MANDATORY, 26 policy::POLICY_LEVEL_MANDATORY,
26 policy::POLICY_SCOPE_USER, 27 policy::POLICY_SCOPE_USER,
28 policy::POLICY_SOURCE_CLOUD,
27 list.DeepCopy(), 29 list.DeepCopy(),
28 NULL); 30 NULL);
29 { 31 {
30 policy::PolicyErrorMap errors; 32 policy::PolicyErrorMap errors;
31 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 33 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
32 EXPECT_TRUE(errors.empty()); 34 EXPECT_TRUE(errors.empty());
33 } 35 }
34 36
35 list.Append(new base::StringValue("test.a.b")); 37 list.Append(new base::StringValue("test.a.b"));
36 policy_map.Set(policy::key::kNativeMessagingBlacklist, 38 policy_map.Set(policy::key::kNativeMessagingBlacklist,
37 policy::POLICY_LEVEL_MANDATORY, 39 policy::POLICY_LEVEL_MANDATORY,
38 policy::POLICY_SCOPE_USER, 40 policy::POLICY_SCOPE_USER,
41 policy::POLICY_SOURCE_CLOUD,
39 list.DeepCopy(), 42 list.DeepCopy(),
40 NULL); 43 NULL);
41 { 44 {
42 policy::PolicyErrorMap errors; 45 policy::PolicyErrorMap errors;
43 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 46 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
44 EXPECT_TRUE(errors.empty()); 47 EXPECT_TRUE(errors.empty());
45 } 48 }
46 49
47 list.Append(new base::StringValue("*")); 50 list.Append(new base::StringValue("*"));
48 policy_map.Set(policy::key::kNativeMessagingBlacklist, 51 policy_map.Set(policy::key::kNativeMessagingBlacklist,
49 policy::POLICY_LEVEL_MANDATORY, 52 policy::POLICY_LEVEL_MANDATORY,
50 policy::POLICY_SCOPE_USER, 53 policy::POLICY_SCOPE_USER,
54 policy::POLICY_SOURCE_CLOUD,
51 list.DeepCopy(), 55 list.DeepCopy(),
52 NULL); 56 NULL);
53 { 57 {
54 policy::PolicyErrorMap errors; 58 policy::PolicyErrorMap errors;
55 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 59 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
56 EXPECT_TRUE(errors.empty()); 60 EXPECT_TRUE(errors.empty());
57 } 61 }
58 62
59 list.Append(new base::StringValue("invalid Name")); 63 list.Append(new base::StringValue("invalid Name"));
60 policy_map.Set(policy::key::kNativeMessagingBlacklist, 64 policy_map.Set(policy::key::kNativeMessagingBlacklist,
61 policy::POLICY_LEVEL_MANDATORY, 65 policy::POLICY_LEVEL_MANDATORY,
62 policy::POLICY_SCOPE_USER, 66 policy::POLICY_SCOPE_USER,
67 policy::POLICY_SOURCE_CLOUD,
63 list.DeepCopy(), 68 list.DeepCopy(),
64 NULL); 69 NULL);
65 { 70 {
66 policy::PolicyErrorMap errors; 71 policy::PolicyErrorMap errors;
67 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 72 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
68 EXPECT_FALSE(errors.empty()); 73 EXPECT_FALSE(errors.empty());
69 EXPECT_FALSE( 74 EXPECT_FALSE(
70 errors.GetErrors(policy::key::kNativeMessagingBlacklist).empty()); 75 errors.GetErrors(policy::key::kNativeMessagingBlacklist).empty());
71 } 76 }
72 } 77 }
73 78
74 TEST(NativeMessagingHostListPolicyHandlerTest, ApplyPolicySettings) { 79 TEST(NativeMessagingHostListPolicyHandlerTest, ApplyPolicySettings) {
75 base::ListValue policy; 80 base::ListValue policy;
76 base::ListValue expected; 81 base::ListValue expected;
77 policy::PolicyMap policy_map; 82 policy::PolicyMap policy_map;
78 PrefValueMap prefs; 83 PrefValueMap prefs;
79 base::Value* value = NULL; 84 base::Value* value = NULL;
80 NativeMessagingHostListPolicyHandler handler( 85 NativeMessagingHostListPolicyHandler handler(
81 policy::key::kNativeMessagingBlacklist, kTestPref, true); 86 policy::key::kNativeMessagingBlacklist, kTestPref, true);
82 87
83 policy.Append(new base::StringValue("com.example.test")); 88 policy.Append(new base::StringValue("com.example.test"));
84 expected.Append(new base::StringValue("com.example.test")); 89 expected.Append(new base::StringValue("com.example.test"));
85 90
86 policy_map.Set(policy::key::kNativeMessagingBlacklist, 91 policy_map.Set(policy::key::kNativeMessagingBlacklist,
87 policy::POLICY_LEVEL_MANDATORY, 92 policy::POLICY_LEVEL_MANDATORY,
88 policy::POLICY_SCOPE_USER, 93 policy::POLICY_SCOPE_USER,
94 policy::POLICY_SOURCE_CLOUD,
89 policy.DeepCopy(), 95 policy.DeepCopy(),
90 NULL); 96 NULL);
91 handler.ApplyPolicySettings(policy_map, &prefs); 97 handler.ApplyPolicySettings(policy_map, &prefs);
92 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 98 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
93 EXPECT_TRUE(base::Value::Equals(&expected, value)); 99 EXPECT_TRUE(base::Value::Equals(&expected, value));
94 100
95 policy.Append(new base::StringValue("*")); 101 policy.Append(new base::StringValue("*"));
96 expected.Append(new base::StringValue("*")); 102 expected.Append(new base::StringValue("*"));
97 103
98 policy_map.Set(policy::key::kNativeMessagingBlacklist, 104 policy_map.Set(policy::key::kNativeMessagingBlacklist,
99 policy::POLICY_LEVEL_MANDATORY, 105 policy::POLICY_LEVEL_MANDATORY,
100 policy::POLICY_SCOPE_USER, 106 policy::POLICY_SCOPE_USER,
107 policy::POLICY_SOURCE_CLOUD,
101 policy.DeepCopy(), 108 policy.DeepCopy(),
102 NULL); 109 NULL);
103 handler.ApplyPolicySettings(policy_map, &prefs); 110 handler.ApplyPolicySettings(policy_map, &prefs);
104 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 111 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
105 EXPECT_TRUE(base::Value::Equals(&expected, value)); 112 EXPECT_TRUE(base::Value::Equals(&expected, value));
106 113
107 policy.Append(new base::StringValue("invalid Name")); 114 policy.Append(new base::StringValue("invalid Name"));
108 policy_map.Set(policy::key::kNativeMessagingBlacklist, 115 policy_map.Set(policy::key::kNativeMessagingBlacklist,
109 policy::POLICY_LEVEL_MANDATORY, 116 policy::POLICY_LEVEL_MANDATORY,
110 policy::POLICY_SCOPE_USER, 117 policy::POLICY_SCOPE_USER,
118 policy::POLICY_SOURCE_CLOUD,
111 policy.DeepCopy(), 119 policy.DeepCopy(),
112 NULL); 120 NULL);
113 handler.ApplyPolicySettings(policy_map, &prefs); 121 handler.ApplyPolicySettings(policy_map, &prefs);
114 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 122 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
115 EXPECT_TRUE(base::Value::Equals(&expected, value)); 123 EXPECT_TRUE(base::Value::Equals(&expected, value));
116 } 124 }
117 125
118 } // namespace extensions 126 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698