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

Unified Diff: components/policy/core/common/generate_policy_source_unittest.cc

Issue 228423002: Add $ref support to policy schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@policy-schema-regex
Patch Set: fixes Created 6 years, 8 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
« no previous file with comments | « no previous file | components/policy/resources/policy_templates.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/core/common/generate_policy_source_unittest.cc
diff --git a/components/policy/core/common/generate_policy_source_unittest.cc b/components/policy/core/common/generate_policy_source_unittest.cc
index a2b14624690e970f207c620e0d92928dd708268f..108b5687425cdc774a7a4811e98a45c190c8a803 100644
--- a/components/policy/core/common/generate_policy_source_unittest.cc
+++ b/components/policy/core/common/generate_policy_source_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <cstring>
#include <string>
#include "base/memory/scoped_ptr.h"
@@ -17,6 +18,40 @@
namespace policy {
+namespace {
+
+// Checks if two schemas are the same or not. Note that this function doesn't
+// consider restrictions on integers and strings nor pattern properties.
+bool IsSameSchema(Schema a, Schema b) {
+ if (a.valid() != b.valid())
+ return false;
+ if (!a.valid())
+ return true;
+ if (a.type() != b.type())
+ return false;
+ if (a.type() == base::Value::TYPE_LIST)
+ return IsSameSchema(a.GetItems(), b.GetItems());
+ if (a.type() != base::Value::TYPE_DICTIONARY)
+ return true;
+ Schema::Iterator a_it = a.GetPropertiesIterator();
+ Schema::Iterator b_it = b.GetPropertiesIterator();
+ while (!a_it.IsAtEnd()) {
+ if (b_it.IsAtEnd())
+ return false;
+ if (strcmp(a_it.key(), b_it.key()) != 0)
+ return false;
+ if (!IsSameSchema(a_it.schema(), b_it.schema()))
+ return false;
+ a_it.Advance();
+ b_it.Advance();
+ }
+ if (!b_it.IsAtEnd())
+ return false;
+ return IsSameSchema(a.GetAdditionalProperties(), b.GetAdditionalProperties());
+}
+
+} // namespace
+
TEST(GeneratePolicySource, ChromeSchemaData) {
Schema schema = Schema::Wrap(GetChromeSchemaData());
ASSERT_TRUE(schema.valid());
@@ -83,6 +118,20 @@ TEST(GeneratePolicySource, ChromeSchemaData) {
EXPECT_EQ(base::Value::TYPE_STRING, it.schema().type());
}
EXPECT_TRUE(*next == NULL);
+
+#if defined(OS_CHROMEOS)
+ subschema = schema.GetKnownProperty(key::kPowerManagementIdleSettings);
+ ASSERT_TRUE(subschema.valid());
+
+ EXPECT_TRUE(IsSameSchema(subschema.GetKnownProperty("AC"),
+ subschema.GetKnownProperty("Battery")));
+
+ subschema = schema.GetKnownProperty(key::kDeviceLoginScreenPowerManagement);
+ ASSERT_TRUE(subschema.valid());
+
+ EXPECT_TRUE(IsSameSchema(subschema.GetKnownProperty("AC"),
+ subschema.GetKnownProperty("Battery")));
+#endif
}
TEST(GeneratePolicySource, PolicyDetails) {
« no previous file with comments | « no previous file | components/policy/resources/policy_templates.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698