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

Unified Diff: chrome/browser/policy/policy_domain_descriptor_unittest.cc

Issue 15061007: Added a PolicyDomainDescriptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments, rebase on new PolicySchema Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/policy_domain_descriptor_unittest.cc
diff --git a/chrome/browser/policy/policy_domain_descriptor_unittest.cc b/chrome/browser/policy/policy_domain_descriptor_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3ff6326a4d08a39d57f4ee44cafc09bc257fa63c
--- /dev/null
+++ b/chrome/browser/policy/policy_domain_descriptor_unittest.cc
@@ -0,0 +1,120 @@
+// Copyright (c) 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/policy/policy_domain_descriptor.h"
+
+#include "chrome/browser/policy/policy_bundle.h"
+#include "chrome/browser/policy/policy_schema.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace policy {
+
+TEST(PolicyDomainDescriptor, FilterBundle) {
+ scoped_refptr<PolicyDomainDescriptor> descriptor =
+ new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS);
+ EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain());
+ EXPECT_TRUE(descriptor->components().empty());
+
+ std::string error;
+ scoped_ptr<PolicySchema> schema = PolicySchema::Parse(
+ "{"
+ " \"$schema\":\"http://json-schema.org/draft-03/schema#\","
+ " \"type\":\"object\","
+ " \"properties\": {"
+ " \"Array\": {"
+ " \"type\": \"array\","
+ " \"items\": { \"type\": \"string\" }"
+ " },"
+ " \"Boolean\": { \"type\": \"boolean\" },"
+ " \"Integer\": { \"type\": \"integer\" },"
+ " \"Null\": { \"type\": \"null\" },"
+ " \"Number\": { \"type\": \"number\" },"
+ " \"Object\": {"
+ " \"type\": \"object\","
+ " \"properties\": {"
+ " \"a\": { \"type\": \"string\" },"
+ " \"b\": { \"type\": \"integer\" }"
+ " }"
+ " },"
+ " \"String\": { \"type\": \"string\" }"
+ " }"
+ "}", &error);
+ ASSERT_TRUE(schema) << error;
+
+ descriptor->SetComponent("abc", schema.Pass());
+
+ EXPECT_EQ(1u, descriptor->components().size());
+ EXPECT_NE(descriptor->components().end(),
+ descriptor->components().find("abc"));
+
+ PolicyBundle bundle;
+ descriptor->FilterBundle(&bundle);
+ const PolicyBundle empty_bundle;
+ EXPECT_TRUE(bundle.Equals(empty_bundle));
+
+ // Other namespace aren't filtered.
bartfab (slow) 2013/05/21 12:10:56 Nit: This part of the test only verifies that POLI
Joao da Silva 2013/05/21 17:50:14 Ah, but it's not left alone :-) Undeclared compone
+ PolicyBundle expected_bundle;
+ PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
+ expected_bundle.Get(chrome_ns).Set("ChromePolicy",
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateStringValue("value"));
bartfab (slow) 2013/05/21 12:10:56 #include "base/values.h"
Joao da Silva 2013/05/21 17:50:14 Done.
+ bundle.CopyFrom(expected_bundle);
+ descriptor->FilterBundle(&bundle);
+ EXPECT_TRUE(bundle.Equals(expected_bundle));
+
+ PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "abc");
+ PolicyMap& map = expected_bundle.Get(extension_ns);
bartfab (slow) 2013/05/21 12:10:56 #include "chrome/browser/policy/policy_map.h"
Joao da Silva 2013/05/21 17:50:14 Done.
+ base::ListValue list;
+ list.AppendString("a");
+ list.AppendString("b");
+ map.Set("Array", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ list.DeepCopy());
+ map.Set("Boolean", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(true));
+ map.Set("Integer", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(1));
+ map.Set("Null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateNullValue());
+ map.Set("Number", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateDoubleValue(1.2));
+ base::DictionaryValue dict;
+ dict.SetString("a", "b");
+ dict.SetInteger("b", 2);
+ map.Set("Object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, dict.DeepCopy());
+ map.Set("String", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateStringValue("value"));
+
+ bundle.MergeFrom(expected_bundle);
+ bundle.Get(extension_ns).Set("Unexpected",
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateStringValue("to-be-removed"));
+
+ descriptor->FilterBundle(&bundle);
+ EXPECT_TRUE(bundle.Equals(expected_bundle));
+
+ // Mismatched types are also removed.
+ bundle.Clear();
+ PolicyMap& badmap = bundle.Get(extension_ns);
+ badmap.Set("Array", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false));
+ badmap.Set("Boolean", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(0));
+ badmap.Set("Integer", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false));
+ badmap.Set("Null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false));
+ badmap.Set("Number", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false));
+ badmap.Set("Object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false));
+ badmap.Set("String", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false));
+
+ descriptor->FilterBundle(&bundle);
+ EXPECT_TRUE(bundle.Equals(empty_bundle));
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698