OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "build/build_config.h" | |
9 #include "components/policy/core/common/schema.h" | 10 #include "components/policy/core/common/schema.h" |
10 #include "policy/policy_constants.h" | 11 #include "policy/policy_constants.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 // This unittest tests the code generated by | 14 // This unittest tests the code generated by |
14 // chrome/tools/build/generate_policy_source.py. | 15 // chrome/tools/build/generate_policy_source.py. |
15 | 16 |
16 namespace policy { | 17 namespace policy { |
17 | 18 |
18 TEST(GeneratePolicySource, ChromeSchemaData) { | 19 TEST(GeneratePolicySource, ChromeSchemaData) { |
(...skipping 29 matching lines...) Expand all Loading... | |
48 ASSERT_TRUE(subschema.valid()); | 49 ASSERT_TRUE(subschema.valid()); |
49 EXPECT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); | 50 EXPECT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); |
50 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); | 51 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); |
51 EXPECT_FALSE(subschema.GetProperty("no such proxy key exists").valid()); | 52 EXPECT_FALSE(subschema.GetProperty("no such proxy key exists").valid()); |
52 ASSERT_TRUE(subschema.GetProperty(key::kProxyMode).valid()); | 53 ASSERT_TRUE(subschema.GetProperty(key::kProxyMode).valid()); |
53 ASSERT_TRUE(subschema.GetProperty(key::kProxyServer).valid()); | 54 ASSERT_TRUE(subschema.GetProperty(key::kProxyServer).valid()); |
54 ASSERT_TRUE(subschema.GetProperty(key::kProxyServerMode).valid()); | 55 ASSERT_TRUE(subschema.GetProperty(key::kProxyServerMode).valid()); |
55 ASSERT_TRUE(subschema.GetProperty(key::kProxyPacUrl).valid()); | 56 ASSERT_TRUE(subschema.GetProperty(key::kProxyPacUrl).valid()); |
56 ASSERT_TRUE(subschema.GetProperty(key::kProxyBypassList).valid()); | 57 ASSERT_TRUE(subschema.GetProperty(key::kProxyBypassList).valid()); |
57 | 58 |
59 // Verify that all the Chrome policies are there. | |
60 for (Schema::Iterator it = schema.GetPropertiesIterator(); | |
61 !it.IsAtEnd(); it.Advance()) { | |
62 EXPECT_TRUE(it.key()); | |
63 EXPECT_FALSE(std::string(it.key()).empty()); | |
64 EXPECT_TRUE(GetChromePolicyDetails(it.key())); | |
65 } | |
66 | |
58 // The properties are iterated in order. | 67 // The properties are iterated in order. |
59 const char* kExpectedProperties[] = { | 68 const char* kExpectedProperties[] = { |
60 key::kProxyBypassList, | 69 key::kProxyBypassList, |
61 key::kProxyMode, | 70 key::kProxyMode, |
62 key::kProxyPacUrl, | 71 key::kProxyPacUrl, |
63 key::kProxyServer, | 72 key::kProxyServer, |
64 key::kProxyServerMode, | 73 key::kProxyServerMode, |
65 NULL, | 74 NULL, |
66 }; | 75 }; |
67 const char** next = kExpectedProperties; | 76 const char** next = kExpectedProperties; |
68 for (Schema::Iterator it(subschema.GetPropertiesIterator()); | 77 for (Schema::Iterator it(subschema.GetPropertiesIterator()); |
69 !it.IsAtEnd(); it.Advance(), ++next) { | 78 !it.IsAtEnd(); it.Advance(), ++next) { |
70 ASSERT_TRUE(*next != NULL); | 79 ASSERT_TRUE(*next != NULL); |
71 EXPECT_STREQ(*next, it.key()); | 80 EXPECT_STREQ(*next, it.key()); |
72 ASSERT_TRUE(it.schema().valid()); | 81 ASSERT_TRUE(it.schema().valid()); |
73 EXPECT_EQ(base::Value::TYPE_STRING, it.schema().type()); | 82 EXPECT_EQ(base::Value::TYPE_STRING, it.schema().type()); |
74 } | 83 } |
75 EXPECT_TRUE(*next == NULL); | 84 EXPECT_TRUE(*next == NULL); |
76 } | 85 } |
77 | 86 |
87 TEST(GeneratePolicySource, PolicyDetails) { | |
88 EXPECT_FALSE(GetChromePolicyDetails("")); | |
89 EXPECT_FALSE(GetChromePolicyDetails("no such policy")); | |
90 EXPECT_FALSE(GetChromePolicyDetails("AlternateErrorPagesEnable")); | |
91 EXPECT_FALSE(GetChromePolicyDetails("alternateErrorPagesEnabled")); | |
92 EXPECT_FALSE(GetChromePolicyDetails("AAlternateErrorPagesEnabled")); | |
93 | |
94 const PolicyDetails* details = | |
95 GetChromePolicyDetails(key::kAlternateErrorPagesEnabled); | |
96 ASSERT_TRUE(details); | |
97 EXPECT_FALSE(details->is_deprecated); | |
98 EXPECT_FALSE(details->is_device_policy); | |
99 EXPECT_EQ(5, details->id); | |
100 EXPECT_EQ(0u, details->max_external_data_size); | |
101 | |
102 details = GetChromePolicyDetails(key::kJavascriptEnabled); | |
103 ASSERT_TRUE(details); | |
104 EXPECT_TRUE(details->is_deprecated); | |
105 EXPECT_FALSE(details->is_device_policy); | |
106 EXPECT_EQ(9, details->id); | |
107 EXPECT_EQ(0u, details->max_external_data_size); | |
108 | |
109 #if defined(OS_CHROMEOS) | |
110 details = GetChromePolicyDetails(key::kDevicePolicyRefreshRate); | |
111 ASSERT_TRUE(details); | |
112 EXPECT_FALSE(details->is_deprecated); | |
113 EXPECT_TRUE(details->is_device_policy); | |
114 EXPECT_EQ(90, details->id); | |
115 EXPECT_EQ(0u, details->max_external_data_size); | |
116 #endif | |
117 | |
118 // TODO(joaodasilva): add a test that verifies a max_external_data_size larger | |
bartfab (slow)
2013/11/05 18:18:33
You can mark that as TODO(bartfab).
Joao da Silva
2013/11/07 20:27:27
Great! Done :-)
| |
119 // than 0, once a type 'external' policy is added. | |
120 } | |
121 | |
78 } // namespace policy | 122 } // namespace policy |
OLD | NEW |