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 "chrome/browser/policy/policy_domain_descriptor.h" | 5 #include "chrome/browser/policy/policy_domain_descriptor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/policy/external_data_fetcher.h" | 12 #include "chrome/browser/policy/external_data_fetcher.h" |
13 #include "chrome/browser/policy/external_data_manager.h" | 13 #include "chrome/browser/policy/external_data_manager.h" |
14 #include "chrome/browser/policy/policy_bundle.h" | 14 #include "chrome/browser/policy/policy_bundle.h" |
15 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "policy/policy_constants.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace policy { | 19 namespace policy { |
19 | 20 |
20 class PolicyDomainDescriptorTest : public testing::Test { | 21 class PolicyDomainDescriptorTest : public testing::Test { |
21 protected: | 22 protected: |
22 scoped_ptr<ExternalDataFetcher> CreateExternalDataFetcher() const; | 23 scoped_ptr<ExternalDataFetcher> CreateExternalDataFetcher() const; |
23 }; | 24 }; |
24 | 25 |
25 scoped_ptr<ExternalDataFetcher> | 26 scoped_ptr<ExternalDataFetcher> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 bundle.Get(unknown_ns).Set("Surprise", | 209 bundle.Get(unknown_ns).Set("Surprise", |
209 POLICY_LEVEL_MANDATORY, | 210 POLICY_LEVEL_MANDATORY, |
210 POLICY_SCOPE_USER, | 211 POLICY_SCOPE_USER, |
211 base::Value::CreateStringValue("value 5"), | 212 base::Value::CreateStringValue("value 5"), |
212 NULL); | 213 NULL); |
213 | 214 |
214 descriptor->FilterBundle(&bundle); | 215 descriptor->FilterBundle(&bundle); |
215 EXPECT_TRUE(bundle.Equals(expected_bundle)); | 216 EXPECT_TRUE(bundle.Equals(expected_bundle)); |
216 } | 217 } |
217 | 218 |
| 219 TEST_F(PolicyDomainDescriptorTest, ChromePolicyDomainDescriptor) { |
| 220 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 221 POLICY_DOMAIN_CHROME); |
| 222 descriptor->RegisterComponent("", SchemaOwner::Wrap(GetChromeSchemaData())); |
| 223 |
| 224 EXPECT_EQ(POLICY_DOMAIN_CHROME, descriptor->domain()); |
| 225 ASSERT_EQ(1u, descriptor->components().size()); |
| 226 ASSERT_EQ("", descriptor->components().begin()->first); |
| 227 Schema schema = descriptor->components().begin()->second; |
| 228 ASSERT_TRUE(schema.valid()); |
| 229 |
| 230 EXPECT_EQ(base::Value::TYPE_DICTIONARY, schema.type()); |
| 231 |
| 232 Schema subschema = schema.GetAdditionalProperties(); |
| 233 EXPECT_FALSE(subschema.valid()); |
| 234 |
| 235 subschema = schema.GetProperty("no such policy exists"); |
| 236 EXPECT_FALSE(subschema.valid()); |
| 237 |
| 238 subschema = schema.GetProperty(key::kAlternateErrorPagesEnabled); |
| 239 ASSERT_TRUE(subschema.valid()); |
| 240 EXPECT_EQ(base::Value::TYPE_BOOLEAN, subschema.type()); |
| 241 |
| 242 subschema = schema.GetProperty(key::kIncognitoModeAvailability); |
| 243 ASSERT_TRUE(subschema.valid()); |
| 244 EXPECT_EQ(base::Value::TYPE_INTEGER, subschema.type()); |
| 245 |
| 246 subschema = schema.GetProperty(key::kProxyMode); |
| 247 ASSERT_TRUE(subschema.valid()); |
| 248 EXPECT_EQ(base::Value::TYPE_STRING, subschema.type()); |
| 249 |
| 250 subschema = schema.GetProperty(key::kCookiesAllowedForUrls); |
| 251 ASSERT_TRUE(subschema.valid()); |
| 252 EXPECT_EQ(base::Value::TYPE_LIST, subschema.type()); |
| 253 ASSERT_TRUE(subschema.GetItems().valid()); |
| 254 EXPECT_EQ(base::Value::TYPE_STRING, subschema.GetItems().type()); |
| 255 |
| 256 subschema = schema.GetProperty(key::kProxySettings); |
| 257 ASSERT_TRUE(subschema.valid()); |
| 258 EXPECT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); |
| 259 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); |
| 260 EXPECT_FALSE(subschema.GetProperty("no such proxy key exists").valid()); |
| 261 ASSERT_TRUE(subschema.GetProperty(key::kProxyMode).valid()); |
| 262 ASSERT_TRUE(subschema.GetProperty(key::kProxyServer).valid()); |
| 263 ASSERT_TRUE(subschema.GetProperty(key::kProxyServerMode).valid()); |
| 264 ASSERT_TRUE(subschema.GetProperty(key::kProxyPacUrl).valid()); |
| 265 ASSERT_TRUE(subschema.GetProperty(key::kProxyBypassList).valid()); |
| 266 |
| 267 // The properties are iterated in order. |
| 268 const char* kExpectedProperties[] = { |
| 269 key::kProxyBypassList, |
| 270 key::kProxyMode, |
| 271 key::kProxyPacUrl, |
| 272 key::kProxyServer, |
| 273 key::kProxyServerMode, |
| 274 NULL, |
| 275 }; |
| 276 const char** next = kExpectedProperties; |
| 277 for (Schema::Iterator it(subschema.GetPropertiesIterator()); |
| 278 !it.IsAtEnd(); it.Advance(), ++next) { |
| 279 ASSERT_TRUE(*next != NULL); |
| 280 EXPECT_STREQ(*next, it.key()); |
| 281 ASSERT_TRUE(it.schema().valid()); |
| 282 EXPECT_EQ(base::Value::TYPE_STRING, it.schema().type()); |
| 283 } |
| 284 EXPECT_TRUE(*next == NULL); |
| 285 } |
| 286 |
218 } // namespace policy | 287 } // namespace policy |
OLD | NEW |