Chromium Code Reviews| 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..b2d7c42eee73a13bed237b0ac25cd48b4d651f58 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 { |
| + |
| +// Check if two schema is same or not. Pay attention that this function didn't |
| +// consider restriction on integer or string, as well as pattern properties. |
|
Joao da Silva
2014/04/09 12:34:55
Suggested improvement:
"Checks if two schemas are
binjin
2014/04/09 14:09:59
Done.
|
| +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) { |