Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/configuration_policy_provider_test.h" | 5 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/policy/configuration_policy_provider.h" | 11 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 12 #include "chrome/browser/policy/external_data_fetcher.h" | 12 #include "chrome/browser/policy/external_data_fetcher.h" |
| 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 13 #include "chrome/browser/policy/mock_configuration_policy_provider.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 "policy/policy_constants.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 | 18 |
| 19 using ::testing::Mock; | 19 using ::testing::Mock; |
| 20 using ::testing::_; | 20 using ::testing::_; |
| 21 | 21 |
| 22 namespace policy { | 22 namespace policy { |
| 23 | 23 |
| 24 const char kTestChromeSchema[] = | |
| 25 "{" | |
| 26 " \"type\": \"object\"," | |
| 27 " \"properties\": {" | |
| 28 " \"StringPolicy\": { \"type\": \"string\" }," | |
| 29 " \"BooleanPolicy\": { \"type\": \"boolean\" }," | |
| 30 " \"IntegerPolicy\": { \"type\": \"integer\" }," | |
| 31 " \"StringListPolicy\": {" | |
| 32 " \"type\": \"array\"," | |
| 33 " \"items\": { \"type\": \"string\" }" | |
| 34 " }," | |
| 35 " \"DictionaryPolicy\": {" | |
| 36 " \"type\": \"object\"," | |
| 37 " \"properties\": {" | |
| 38 " \"bool\": { \"type\": \"boolean\" }," | |
| 39 " \"double\": { \"type\": \"number\" }," | |
| 40 " \"int\": { \"type\": \"integer\" }," | |
| 41 " \"string\": { \"type\": \"string\" }," | |
| 42 " \"array\": {" | |
| 43 " \"type\": \"array\"," | |
| 44 " \"items\": { \"type\": \"string\" }" | |
| 45 " }," | |
| 46 " \"dictionary\": {" | |
| 47 " \"type\": \"object\"," | |
| 48 " \"properties\": {" | |
| 49 " \"sub\": { \"type\": \"string\" }," | |
| 50 " \"sublist\": {" | |
| 51 " \"type\": \"array\"," | |
| 52 " \"items\": {" | |
| 53 " \"type\": \"object\"," | |
| 54 " \"properties\": {" | |
| 55 " \"aaa\": { \"type\": \"integer\" }," | |
| 56 " \"bbb\": { \"type\": \"integer\" }," | |
| 57 " \"ccc\": { \"type\": \"string\" }," | |
| 58 " \"ddd\": { \"type\": \"string\" }" | |
| 59 " }" | |
| 60 " }" | |
| 61 " }" | |
| 62 " }" | |
| 63 " }," | |
| 64 " \"list\": {" | |
| 65 " \"type\": \"array\"," | |
| 66 " \"items\": {" | |
| 67 " \"type\": \"object\"," | |
| 68 " \"properties\": {" | |
| 69 " \"subdictindex\": { \"type\": \"integer\" }," | |
| 70 " \"subdict\": {" | |
| 71 " \"type\": \"object\"," | |
| 72 " \"properties\": {" | |
| 73 " \"bool\": { \"type\": \"boolean\" }," | |
| 74 " \"double\": { \"type\": \"number\" }," | |
| 75 " \"int\": { \"type\": \"integer\" }," | |
| 76 " \"string\": { \"type\": \"string\" }" | |
| 77 " }" | |
| 78 " }" | |
| 79 " }" | |
| 80 " }" | |
| 81 " }," | |
| 82 " \"dict\": {" | |
| 83 " \"type\": \"object\"," | |
| 84 " \"properties\": {" | |
| 85 " \"bool\": { \"type\": \"boolean\" }," | |
| 86 " \"double\": { \"type\": \"number\" }," | |
| 87 " \"int\": { \"type\": \"integer\" }," | |
| 88 " \"string\": { \"type\": \"string\" }," | |
| 89 " \"list\": {" | |
| 90 " \"type\": \"array\"," | |
| 91 " \"items\": {" | |
| 92 " \"type\": \"object\"," | |
| 93 " \"properties\": {" | |
| 94 " \"subdictindex\": { \"type\": \"integer\" }," | |
| 95 " \"subdict\": {" | |
| 96 " \"type\": \"object\"," | |
| 97 " \"properties\": {" | |
| 98 " \"bool\": { \"type\": \"boolean\" }," | |
| 99 " \"double\": { \"type\": \"number\" }," | |
| 100 " \"int\": { \"type\": \"integer\" }," | |
| 101 " \"string\": { \"type\": \"string\" }" | |
| 102 " }" | |
| 103 " }" | |
| 104 " }" | |
| 105 " }" | |
| 106 " }" | |
| 107 " }" | |
| 108 " }" | |
| 109 " }" | |
| 110 " }" | |
| 111 " }" | |
| 112 "}"; | |
| 113 | |
| 24 namespace test_policy_definitions { | 114 namespace test_policy_definitions { |
| 25 | 115 |
| 26 const char kKeyString[] = "StringPolicy"; | 116 const char kKeyString[] = "StringPolicy"; |
| 27 const char kKeyBoolean[] = "BooleanPolicy"; | 117 const char kKeyBoolean[] = "BooleanPolicy"; |
| 28 const char kKeyInteger[] = "IntegerPolicy"; | 118 const char kKeyInteger[] = "IntegerPolicy"; |
| 29 const char kKeyStringList[] = "StringListPolicy"; | 119 const char kKeyStringList[] = "StringListPolicy"; |
| 30 const char kKeyDictionary[] = "DictionaryPolicy"; | 120 const char kKeyDictionary[] = "DictionaryPolicy"; |
| 31 | 121 |
| 32 static const PolicyDefinitionList::Entry kEntries[] = { | 122 static const PolicyDefinitionList::Entry kEntries[] = { |
| 33 { kKeyString, base::Value::TYPE_STRING }, | 123 { kKeyString, base::Value::TYPE_STRING }, |
| 34 { kKeyBoolean, base::Value::TYPE_BOOLEAN }, | 124 { kKeyBoolean, base::Value::TYPE_BOOLEAN }, |
| 35 { kKeyInteger, base::Value::TYPE_INTEGER }, | 125 { kKeyInteger, base::Value::TYPE_INTEGER }, |
| 36 { kKeyStringList, base::Value::TYPE_LIST }, | 126 { kKeyStringList, base::Value::TYPE_LIST }, |
| 37 { kKeyDictionary, base::Value::TYPE_DICTIONARY }, | 127 { kKeyDictionary, base::Value::TYPE_DICTIONARY }, |
| 38 }; | 128 }; |
| 39 | 129 |
| 40 const PolicyDefinitionList kList = { | 130 const PolicyDefinitionList kList = { |
| 41 kEntries, kEntries + arraysize(kEntries) | 131 kEntries, kEntries + arraysize(kEntries) |
| 42 }; | 132 }; |
| 43 | 133 |
| 44 } // namespace test_policy_definitions | 134 } // namespace test_policy_definitions |
| 45 | 135 |
| 46 PolicyTestBase::PolicyTestBase() {} | 136 PolicyTestBase::PolicyTestBase() {} |
| 47 | 137 |
| 48 PolicyTestBase::~PolicyTestBase() {} | 138 PolicyTestBase::~PolicyTestBase() {} |
| 49 | 139 |
| 140 void PolicyTestBase::SetUp() { | |
| 141 std::string error; | |
| 142 chrome_schema_ = Schema::Parse(kTestChromeSchema, &error); | |
| 143 ASSERT_TRUE(chrome_schema_.valid()) << error; | |
| 144 schema_registry_.RegisterComponent(PolicyNamespace(POLICY_DOMAIN_CHROME, ""), | |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: #include "components/policy/core/common/polic
Joao da Silva
2013/11/07 13:15:00
Done.
| |
| 145 chrome_schema_); | |
| 146 } | |
| 147 | |
| 50 void PolicyTestBase::TearDown() { | 148 void PolicyTestBase::TearDown() { |
| 51 loop_.RunUntilIdle(); | 149 loop_.RunUntilIdle(); |
| 52 } | 150 } |
| 53 | 151 |
| 54 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, | 152 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, |
| 55 PolicyScope scope) | 153 PolicyScope scope) |
| 56 : level_(level), scope_(scope) {} | 154 : level_(level), scope_(scope) {} |
| 57 | 155 |
| 58 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} | 156 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} |
| 59 | 157 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 73 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} | 171 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} |
| 74 | 172 |
| 75 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} | 173 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} |
| 76 | 174 |
| 77 void ConfigurationPolicyProviderTest::SetUp() { | 175 void ConfigurationPolicyProviderTest::SetUp() { |
| 78 PolicyTestBase::SetUp(); | 176 PolicyTestBase::SetUp(); |
| 79 | 177 |
| 80 test_harness_.reset((*GetParam())()); | 178 test_harness_.reset((*GetParam())()); |
| 81 test_harness_->SetUp(); | 179 test_harness_->SetUp(); |
| 82 | 180 |
| 181 Schema extension_schema = | |
| 182 chrome_schema_.GetKnownProperty(test_policy_definitions::kKeyDictionary); | |
| 183 ASSERT_TRUE(extension_schema.valid()); | |
| 184 schema_registry_.RegisterComponent( | |
| 185 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | |
| 186 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | |
| 187 extension_schema); | |
| 188 schema_registry_.RegisterComponent( | |
| 189 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | |
| 190 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), | |
| 191 extension_schema); | |
| 192 schema_registry_.RegisterComponent( | |
| 193 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | |
| 194 "cccccccccccccccccccccccccccccccc"), | |
| 195 extension_schema); | |
| 196 | |
| 83 provider_.reset(test_harness_->CreateProvider( | 197 provider_.reset(test_harness_->CreateProvider( |
| 84 loop_.message_loop_proxy(), &test_policy_definitions::kList)); | 198 &schema_registry_, |
| 85 provider_->Init(); | 199 loop_.message_loop_proxy(), |
| 200 &test_policy_definitions::kList)); | |
| 201 provider_->Init(&schema_registry_); | |
| 86 // Some providers do a reload on init. Make sure any notifications generated | 202 // Some providers do a reload on init. Make sure any notifications generated |
| 87 // are fired now. | 203 // are fired now. |
| 88 loop_.RunUntilIdle(); | 204 loop_.RunUntilIdle(); |
| 89 | 205 |
| 90 const PolicyBundle kEmptyBundle; | 206 const PolicyBundle kEmptyBundle; |
| 91 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 207 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
| 92 } | 208 } |
| 93 | 209 |
| 94 void ConfigurationPolicyProviderTest::TearDown() { | 210 void ConfigurationPolicyProviderTest::TearDown() { |
| 95 // Give providers the chance to clean up after themselves on the file thread. | 211 // Give providers the chance to clean up after themselves on the file thread. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 expected_value, | 281 expected_value, |
| 166 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, | 282 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, |
| 167 base::Unretained(test_harness_.get()), | 283 base::Unretained(test_harness_.get()), |
| 168 test_policy_definitions::kKeyStringList, | 284 test_policy_definitions::kKeyStringList, |
| 169 &expected_value)); | 285 &expected_value)); |
| 170 } | 286 } |
| 171 | 287 |
| 172 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { | 288 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { |
| 173 base::DictionaryValue expected_value; | 289 base::DictionaryValue expected_value; |
| 174 expected_value.SetBoolean("bool", true); | 290 expected_value.SetBoolean("bool", true); |
| 291 expected_value.SetDouble("double", 123.456); | |
| 175 expected_value.SetInteger("int", 123); | 292 expected_value.SetInteger("int", 123); |
| 176 expected_value.SetString("str", "omg"); | 293 expected_value.SetString("string", "omg"); |
| 177 | 294 |
| 178 base::ListValue* list = new base::ListValue(); | 295 base::ListValue* list = new base::ListValue(); |
| 179 list->Set(0U, base::Value::CreateStringValue("first")); | 296 list->Set(0U, base::Value::CreateStringValue("first")); |
| 180 list->Set(1U, base::Value::CreateStringValue("second")); | 297 list->Set(1U, base::Value::CreateStringValue("second")); |
| 181 expected_value.Set("list", list); | 298 expected_value.Set("array", list); |
| 182 | 299 |
| 183 base::DictionaryValue* dict = new base::DictionaryValue(); | 300 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 184 dict->SetString("sub", "value"); | 301 dict->SetString("sub", "value"); |
| 185 list = new base::ListValue(); | 302 list = new base::ListValue(); |
| 186 base::DictionaryValue* sub = new base::DictionaryValue(); | 303 base::DictionaryValue* sub = new base::DictionaryValue(); |
| 187 sub->SetInteger("aaa", 111); | 304 sub->SetInteger("aaa", 111); |
| 188 sub->SetInteger("bbb", 222); | 305 sub->SetInteger("bbb", 222); |
| 189 list->Append(sub); | 306 list->Append(sub); |
| 190 sub = new base::DictionaryValue(); | 307 sub = new base::DictionaryValue(); |
| 191 sub->SetString("ccc", "333"); | 308 sub->SetString("ccc", "333"); |
| 192 sub->SetString("ddd", "444"); | 309 sub->SetString("ddd", "444"); |
| 193 list->Append(sub); | 310 list->Append(sub); |
| 194 dict->Set("sublist", list); | 311 dict->Set("sublist", list); |
| 195 expected_value.Set("dict", dict); | 312 expected_value.Set("dictionary", dict); |
| 196 | 313 |
| 197 CheckValue(test_policy_definitions::kKeyDictionary, | 314 CheckValue(test_policy_definitions::kKeyDictionary, |
| 198 expected_value, | 315 expected_value, |
| 199 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, | 316 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, |
| 200 base::Unretained(test_harness_.get()), | 317 base::Unretained(test_harness_.get()), |
| 201 test_policy_definitions::kKeyDictionary, | 318 test_policy_definitions::kKeyDictionary, |
| 202 &expected_value)); | 319 &expected_value)); |
| 203 } | 320 } |
| 204 | 321 |
| 205 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { | 322 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 Configuration3rdPartyPolicyProviderTest() {} | 393 Configuration3rdPartyPolicyProviderTest() {} |
| 277 | 394 |
| 278 Configuration3rdPartyPolicyProviderTest:: | 395 Configuration3rdPartyPolicyProviderTest:: |
| 279 ~Configuration3rdPartyPolicyProviderTest() {} | 396 ~Configuration3rdPartyPolicyProviderTest() {} |
| 280 | 397 |
| 281 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) { | 398 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) { |
| 282 base::DictionaryValue policy_dict; | 399 base::DictionaryValue policy_dict; |
| 283 policy_dict.SetBoolean("bool", true); | 400 policy_dict.SetBoolean("bool", true); |
| 284 policy_dict.SetDouble("double", 123.456); | 401 policy_dict.SetDouble("double", 123.456); |
| 285 policy_dict.SetInteger("int", 789); | 402 policy_dict.SetInteger("int", 789); |
| 286 policy_dict.SetString("str", "string value"); | 403 policy_dict.SetString("string", "string value"); |
| 287 | 404 |
| 288 base::ListValue* list = new base::ListValue(); | 405 base::ListValue* list = new base::ListValue(); |
| 289 for (int i = 0; i < 2; ++i) { | 406 for (int i = 0; i < 2; ++i) { |
| 290 base::DictionaryValue* dict = new base::DictionaryValue(); | 407 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 291 dict->SetInteger("subdictindex", i); | 408 dict->SetInteger("subdictindex", i); |
| 292 dict->Set("subdict", policy_dict.DeepCopy()); | 409 dict->Set("subdict", policy_dict.DeepCopy()); |
| 293 list->Append(dict); | 410 list->Append(dict); |
| 294 } | 411 } |
| 295 policy_dict.Set("list", list); | 412 policy_dict.Set("list", list); |
| 296 policy_dict.Set("dict", policy_dict.DeepCopy()); | 413 policy_dict.Set("dict", policy_dict.DeepCopy()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 447 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 331 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 448 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 332 .CopyFrom(expected_policy); | 449 .CopyFrom(expected_policy); |
| 333 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 450 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 334 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 451 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 335 .CopyFrom(expected_policy); | 452 .CopyFrom(expected_policy); |
| 336 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 453 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 337 } | 454 } |
| 338 | 455 |
| 339 } // namespace policy | 456 } // namespace policy |
| OLD | NEW |