OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <cstring> | 5 #include <cstring> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "components/policy/core/common/policy_details.h" | 11 #include "components/policy/core/common/policy_details.h" |
12 #include "components/policy/core/common/schema.h" | 12 #include "components/policy/core/common/schema.h" |
13 #include "policy/policy_constants.h" | 13 #include "policy/policy_constants.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 // This unittest tests the code generated by | 16 // This unittest tests the code generated by |
17 // chrome/tools/build/generate_policy_source.py. | 17 // chrome/tools/build/generate_policy_source.py. |
18 | 18 |
19 namespace policy { | 19 namespace policy { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
| 23 #if defined(OS_CHROMEOS) |
23 // Checks if two schemas are the same or not. Note that this function doesn't | 24 // Checks if two schemas are the same or not. Note that this function doesn't |
24 // consider restrictions on integers and strings nor pattern properties. | 25 // consider restrictions on integers and strings nor pattern properties. |
25 bool IsSameSchema(Schema a, Schema b) { | 26 bool IsSameSchema(Schema a, Schema b) { |
26 if (a.valid() != b.valid()) | 27 if (a.valid() != b.valid()) |
27 return false; | 28 return false; |
28 if (!a.valid()) | 29 if (!a.valid()) |
29 return true; | 30 return true; |
30 if (a.type() != b.type()) | 31 if (a.type() != b.type()) |
31 return false; | 32 return false; |
32 if (a.type() == base::Value::TYPE_LIST) | 33 if (a.type() == base::Value::TYPE_LIST) |
33 return IsSameSchema(a.GetItems(), b.GetItems()); | 34 return IsSameSchema(a.GetItems(), b.GetItems()); |
34 if (a.type() != base::Value::TYPE_DICTIONARY) | 35 if (a.type() != base::Value::TYPE_DICTIONARY) |
35 return true; | 36 return true; |
36 Schema::Iterator a_it = a.GetPropertiesIterator(); | 37 Schema::Iterator a_it = a.GetPropertiesIterator(); |
37 Schema::Iterator b_it = b.GetPropertiesIterator(); | 38 Schema::Iterator b_it = b.GetPropertiesIterator(); |
38 while (!a_it.IsAtEnd()) { | 39 while (!a_it.IsAtEnd()) { |
39 if (b_it.IsAtEnd()) | 40 if (b_it.IsAtEnd()) |
40 return false; | 41 return false; |
41 if (strcmp(a_it.key(), b_it.key()) != 0) | 42 if (strcmp(a_it.key(), b_it.key()) != 0) |
42 return false; | 43 return false; |
43 if (!IsSameSchema(a_it.schema(), b_it.schema())) | 44 if (!IsSameSchema(a_it.schema(), b_it.schema())) |
44 return false; | 45 return false; |
45 a_it.Advance(); | 46 a_it.Advance(); |
46 b_it.Advance(); | 47 b_it.Advance(); |
47 } | 48 } |
48 if (!b_it.IsAtEnd()) | 49 if (!b_it.IsAtEnd()) |
49 return false; | 50 return false; |
50 return IsSameSchema(a.GetAdditionalProperties(), b.GetAdditionalProperties()); | 51 return IsSameSchema(a.GetAdditionalProperties(), b.GetAdditionalProperties()); |
51 } | 52 } |
| 53 #endif |
52 | 54 |
53 } // namespace | 55 } // namespace |
54 | 56 |
55 TEST(GeneratePolicySource, ChromeSchemaData) { | 57 TEST(GeneratePolicySource, ChromeSchemaData) { |
56 Schema schema = Schema::Wrap(GetChromeSchemaData()); | 58 Schema schema = Schema::Wrap(GetChromeSchemaData()); |
57 ASSERT_TRUE(schema.valid()); | 59 ASSERT_TRUE(schema.valid()); |
58 EXPECT_EQ(base::Value::TYPE_DICTIONARY, schema.type()); | 60 EXPECT_EQ(base::Value::TYPE_DICTIONARY, schema.type()); |
59 | 61 |
60 Schema subschema = schema.GetAdditionalProperties(); | 62 Schema subschema = schema.GetAdditionalProperties(); |
61 EXPECT_FALSE(subschema.valid()); | 63 EXPECT_FALSE(subschema.valid()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_TRUE(details->is_device_policy); | 167 EXPECT_TRUE(details->is_device_policy); |
166 EXPECT_EQ(90, details->id); | 168 EXPECT_EQ(90, details->id); |
167 EXPECT_EQ(0u, details->max_external_data_size); | 169 EXPECT_EQ(0u, details->max_external_data_size); |
168 #endif | 170 #endif |
169 | 171 |
170 // TODO(bartfab): add a test that verifies a max_external_data_size larger | 172 // TODO(bartfab): add a test that verifies a max_external_data_size larger |
171 // than 0, once a type 'external' policy is added. | 173 // than 0, once a type 'external' policy is added. |
172 } | 174 } |
173 | 175 |
174 } // namespace policy | 176 } // namespace policy |
OLD | NEW |