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

Unified 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 7 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/native_messaging_policy_handler_unittest.cc
diff --git a/chrome/browser/extensions/api/messaging/native_messaging_policy_handler_unittest.cc b/chrome/browser/extensions/api/messaging/native_messaging_policy_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..04cfcfcfb4f2b57c63630e0c6c64edaa010c1098
--- /dev/null
+++ b/chrome/browser/extensions/api/messaging/native_messaging_policy_handler_unittest.cc
@@ -0,0 +1,103 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/messaging/native_messaging_policy_handler.h"
+
+#include "base/prefs/pref_value_map.h"
+#include "chrome/browser/extensions/policy_handlers.h"
+#include "chrome/common/pref_names.h"
+#include "components/policy/core/browser/policy_error_map.h"
+#include "components/policy/core/common/policy_map.h"
+#include "policy/policy_constants.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+const char kTestPref[] = "unit_test.test_pref";
+
+TEST(NativeMessagingHostListPolicyHandlerTest, CheckPolicySettings) {
+ base::ListValue list;
+ policy::PolicyMap policy_map;
+ policy::PolicyErrorMap errors;
+ NativeMessagingHostListPolicyHandler handler(
+ policy::key::kNativeMessagingBlacklist, kTestPref, true);
+
+ policy_map.Set(policy::key::kNativeMessagingBlacklist,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER,
+ list.DeepCopy(),
+ NULL);
+ errors.Clear();
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ 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.
+
+ list.Append(
+ base::Value::CreateStringValue("test.a.b"));
+ policy_map.Set(policy::key::kNativeMessagingBlacklist,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER,
+ list.DeepCopy(),
+ NULL);
+ errors.Clear();
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ list.Append(base::Value::CreateStringValue("*"));
+ policy_map.Set(policy::key::kNativeMessagingBlacklist,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER,
+ list.DeepCopy(),
+ NULL);
+ errors.Clear();
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ list.Append(base::Value::CreateStringValue("invalid Name"));
+ policy_map.Set(policy::key::kNativeMessagingBlacklist,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER,
+ list.DeepCopy(),
+ NULL);
+ errors.Clear();
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_FALSE(errors.empty());
+ EXPECT_FALSE(
+ 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
+}
+
+TEST(NativeMessagingHostListPolicyHandlerTest, ApplyPolicySettings) {
+ base::ListValue policy;
+ base::ListValue expected;
+ policy::PolicyMap policy_map;
+ PrefValueMap prefs;
+ base::Value* value = NULL;
+ NativeMessagingHostListPolicyHandler handler(
+ policy::key::kNativeMessagingBlacklist, kTestPref, false);
+
+ policy.Append(
+ base::Value::CreateStringValue("com.example.test"));
+ expected.Append(
+ 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.
+
+ policy_map.Set(policy::key::kNativeMessagingBlacklist,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER,
+ policy.DeepCopy(),
+ NULL);
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
+ EXPECT_TRUE(base::Value::Equals(&expected, value));
+
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.
+ policy.Append(base::Value::CreateStringValue("invalid Name"));
+ policy_map.Set(policy::key::kNativeMessagingBlacklist,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_USER,
+ policy.DeepCopy(),
+ NULL);
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
+ EXPECT_TRUE(base::Value::Equals(&expected, value));
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698