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