| 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 "components/policy/core/common/configuration_policy_provider_test.h" | 5 #include "components/policy/core/common/configuration_policy_provider_test.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "components/policy/core/common/configuration_policy_provider.h" | 14 #include "components/policy/core/common/configuration_policy_provider.h" |
| 15 #include "components/policy/core/common/external_data_fetcher.h" | 15 #include "components/policy/core/common/external_data_fetcher.h" |
| 16 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 16 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 17 #include "components/policy/core/common/policy_bundle.h" | 17 #include "components/policy/core/common/policy_bundle.h" |
| 18 #include "components/policy/core/common/policy_map.h" | 18 #include "components/policy/core/common/policy_map.h" |
| 19 #include "components/policy/core/common/policy_namespace.h" | 19 #include "components/policy/core/common/policy_namespace.h" |
| 20 #include "components/policy/core/common/policy_test_utils.h" |
| 20 #include "components/policy/core/common/policy_types.h" | 21 #include "components/policy/core/common/policy_types.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 | 23 |
| 23 using ::testing::Mock; | 24 using ::testing::Mock; |
| 24 using ::testing::_; | 25 using ::testing::_; |
| 25 | 26 |
| 26 namespace policy { | 27 namespace { |
| 27 | 28 |
| 28 const char kTestChromeSchema[] = | 29 const char kTestChromeSchema[] = |
| 29 "{" | 30 "{" |
| 30 " \"type\": \"object\"," | 31 " \"type\": \"object\"," |
| 31 " \"properties\": {" | 32 " \"properties\": {" |
| 32 " \"StringPolicy\": { \"type\": \"string\" }," | 33 " \"StringPolicy\": { \"type\": \"string\" }," |
| 33 " \"BooleanPolicy\": { \"type\": \"boolean\" }," | 34 " \"BooleanPolicy\": { \"type\": \"boolean\" }," |
| 34 " \"IntegerPolicy\": { \"type\": \"integer\" }," | 35 " \"IntegerPolicy\": { \"type\": \"integer\" }," |
| 35 " \"StringListPolicy\": {" | 36 " \"StringListPolicy\": {" |
| 36 " \"type\": \"array\"," | 37 " \"type\": \"array\"," |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 " }" | 109 " }" |
| 109 " }" | 110 " }" |
| 110 " }" | 111 " }" |
| 111 " }" | 112 " }" |
| 112 " }" | 113 " }" |
| 113 " }" | 114 " }" |
| 114 " }" | 115 " }" |
| 115 " }" | 116 " }" |
| 116 "}"; | 117 "}"; |
| 117 | 118 |
| 119 } // anonymous namespace |
| 120 |
| 121 namespace policy { |
| 122 |
| 118 namespace test_keys { | 123 namespace test_keys { |
| 119 | 124 |
| 125 // These are the defaults for PolicyProviderTestHarness but they are generally |
| 126 // available for use in other tests. Subclasses of PolicyProviderTestHarness |
| 127 // may use different values. |
| 120 const char kKeyString[] = "StringPolicy"; | 128 const char kKeyString[] = "StringPolicy"; |
| 121 const char kKeyBoolean[] = "BooleanPolicy"; | 129 const char kKeyBoolean[] = "BooleanPolicy"; |
| 122 const char kKeyInteger[] = "IntegerPolicy"; | 130 const char kKeyInteger[] = "IntegerPolicy"; |
| 123 const char kKeyStringList[] = "StringListPolicy"; | 131 const char kKeyStringList[] = "StringListPolicy"; |
| 124 const char kKeyDictionary[] = "DictionaryPolicy"; | 132 const char kKeyDictionary[] = "DictionaryPolicy"; |
| 125 | 133 |
| 126 } // namespace test_keys | 134 } // namespace test_keys |
| 127 | 135 |
| 128 PolicyTestBase::PolicyTestBase() {} | 136 PolicyTestBase::PolicyTestBase() {} |
| 129 | 137 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 146 schema_registry_.RegisterComponent(ns, schema); | 154 schema_registry_.RegisterComponent(ns, schema); |
| 147 return true; | 155 return true; |
| 148 } | 156 } |
| 149 ADD_FAILURE() << error; | 157 ADD_FAILURE() << error; |
| 150 return false; | 158 return false; |
| 151 } | 159 } |
| 152 | 160 |
| 153 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, | 161 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, |
| 154 PolicyScope scope, | 162 PolicyScope scope, |
| 155 PolicySource source) | 163 PolicySource source) |
| 156 : level_(level), scope_(scope), source_(source) {} | 164 : key_string_(test_keys::kKeyString), |
| 165 key_boolean_(test_keys::kKeyBoolean), |
| 166 key_integer_(test_keys::kKeyInteger), |
| 167 key_stringlist_(test_keys::kKeyStringList), |
| 168 key_dictionary_(test_keys::kKeyDictionary), |
| 169 test_schema_(kTestChromeSchema), |
| 170 level_(level), |
| 171 scope_(scope), |
| 172 source_(source) { |
| 173 } |
| 157 | 174 |
| 158 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} | 175 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} |
| 159 | 176 |
| 160 PolicyLevel PolicyProviderTestHarness::policy_level() const { | |
| 161 return level_; | |
| 162 } | |
| 163 | |
| 164 PolicyScope PolicyProviderTestHarness::policy_scope() const { | |
| 165 return scope_; | |
| 166 } | |
| 167 | |
| 168 PolicySource PolicyProviderTestHarness::policy_source() const { | |
| 169 return source_; | |
| 170 } | |
| 171 | |
| 172 void PolicyProviderTestHarness::Install3rdPartyPolicy( | 177 void PolicyProviderTestHarness::Install3rdPartyPolicy( |
| 173 const base::DictionaryValue* policies) { | 178 const base::DictionaryValue* policies) { |
| 174 FAIL(); | 179 FAIL(); |
| 175 } | 180 } |
| 176 | 181 |
| 177 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} | 182 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} |
| 178 | 183 |
| 179 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} | 184 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} |
| 180 | 185 |
| 181 void ConfigurationPolicyProviderTest::SetUp() { | 186 void ConfigurationPolicyProviderTest::SetUp() { |
| 182 PolicyTestBase::SetUp(); | 187 harness_.reset((*GetParam())()); |
| 183 | 188 harness_->SetUp(); |
| 184 test_harness_.reset((*GetParam())()); | |
| 185 test_harness_->SetUp(); | |
| 186 | 189 |
| 187 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); | 190 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); |
| 191 ASSERT_TRUE(RegisterSchema(chrome_ns, harness_->test_schema())); |
| 192 |
| 188 Schema chrome_schema = *schema_registry_.schema_map()->GetSchema(chrome_ns); | 193 Schema chrome_schema = *schema_registry_.schema_map()->GetSchema(chrome_ns); |
| 189 Schema extension_schema = | 194 Schema extension_schema = |
| 190 chrome_schema.GetKnownProperty(test_keys::kKeyDictionary); | 195 chrome_schema.GetKnownProperty(harness_->key_dictionary()); |
| 191 ASSERT_TRUE(extension_schema.valid()); | 196 ASSERT_TRUE(extension_schema.valid()); |
| 192 schema_registry_.RegisterComponent( | 197 schema_registry_.RegisterComponent( |
| 193 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 198 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 194 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | 199 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), |
| 195 extension_schema); | 200 extension_schema); |
| 196 schema_registry_.RegisterComponent( | 201 schema_registry_.RegisterComponent( |
| 197 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 202 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 198 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), | 203 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), |
| 199 extension_schema); | 204 extension_schema); |
| 200 schema_registry_.RegisterComponent( | 205 schema_registry_.RegisterComponent( |
| 201 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 206 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 202 "cccccccccccccccccccccccccccccccc"), | 207 "cccccccccccccccccccccccccccccccc"), |
| 203 extension_schema); | 208 extension_schema); |
| 204 | 209 |
| 205 provider_.reset( | 210 provider_.reset( |
| 206 test_harness_->CreateProvider(&schema_registry_, loop_.task_runner())); | 211 harness_->CreateProvider(&schema_registry_, loop_.task_runner())); |
| 207 provider_->Init(&schema_registry_); | 212 provider_->Init(&schema_registry_); |
| 208 // Some providers do a reload on init. Make sure any notifications generated | 213 // Some providers do a reload on init. Make sure any notifications generated |
| 209 // are fired now. | 214 // are fired now. |
| 210 loop_.RunUntilIdle(); | 215 loop_.RunUntilIdle(); |
| 211 | 216 |
| 212 const PolicyBundle kEmptyBundle; | 217 const PolicyBundle kEmptyBundle; |
| 213 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 218 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void ConfigurationPolicyProviderTest::TearDown() { | 221 void ConfigurationPolicyProviderTest::TearDown() { |
| 217 // Give providers the chance to clean up after themselves on the file thread. | 222 // Give providers the chance to clean up after themselves on the file thread. |
| 218 provider_->Shutdown(); | 223 if (provider_) { |
| 219 provider_.reset(); | 224 provider_->Shutdown(); |
| 225 provider_.reset(); |
| 226 } |
| 220 | 227 |
| 221 PolicyTestBase::TearDown(); | 228 PolicyTestBase::TearDown(); |
| 222 } | 229 } |
| 223 | 230 |
| 224 void ConfigurationPolicyProviderTest::CheckValue( | 231 void ConfigurationPolicyProviderTest::CheckValue( |
| 225 const char* policy_name, | 232 const char* policy_name, |
| 226 const base::Value& expected_value, | 233 const base::Value& expected_value, |
| 227 base::Closure install_value) { | 234 base::Closure install_value) { |
| 228 // Install the value, reload policy and check the provider for the value. | 235 // Install the value, reload policy and check the provider for the value. |
| 229 install_value.Run(); | 236 install_value.Run(); |
| 230 provider_->RefreshPolicies(); | 237 provider_->RefreshPolicies(); |
| 231 loop_.RunUntilIdle(); | 238 loop_.RunUntilIdle(); |
| 232 PolicyBundle expected_bundle; | 239 PolicyBundle expected_bundle; |
| 233 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 240 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 234 .Set(policy_name, test_harness_->policy_level(), | 241 .Set(policy_name, harness_->policy_level(), harness_->policy_scope(), |
| 235 test_harness_->policy_scope(), test_harness_->policy_source(), | 242 harness_->policy_source(), expected_value.CreateDeepCopy(), nullptr); |
| 236 expected_value.CreateDeepCopy(), nullptr); | 243 bool match = provider_->policies().Equals(expected_bundle); |
| 237 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 244 if (!match) { |
| 245 LOG(ERROR) << "EXPECTED: " << expected_bundle; |
| 246 LOG(ERROR) << "ACTUAL: " << provider_->policies(); |
| 247 } |
| 248 EXPECT_TRUE(match); |
| 238 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, | 249 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, |
| 239 // and extend the |expected_bundle|, once all providers are ready. | 250 // and extend the |expected_bundle|, once all providers are ready. |
| 240 } | 251 } |
| 241 | 252 |
| 242 TEST_P(ConfigurationPolicyProviderTest, Empty) { | 253 TEST_P(ConfigurationPolicyProviderTest, Empty) { |
| 243 provider_->RefreshPolicies(); | 254 provider_->RefreshPolicies(); |
| 244 loop_.RunUntilIdle(); | 255 loop_.RunUntilIdle(); |
| 245 const PolicyBundle kEmptyBundle; | 256 const PolicyBundle kEmptyBundle; |
| 246 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 257 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
| 247 } | 258 } |
| 248 | 259 |
| 249 TEST_P(ConfigurationPolicyProviderTest, StringValue) { | 260 TEST_P(ConfigurationPolicyProviderTest, StringValue) { |
| 250 const char kTestString[] = "string_value"; | 261 const char kTestString[] = "string_value"; |
| 251 base::StringValue expected_value(kTestString); | 262 base::StringValue expected_value(kTestString); |
| 252 CheckValue(test_keys::kKeyString, | 263 CheckValue(harness_->key_string(), |
| 253 expected_value, | 264 expected_value, |
| 254 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, | 265 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, |
| 255 base::Unretained(test_harness_.get()), | 266 base::Unretained(harness_.get()), |
| 256 test_keys::kKeyString, | 267 harness_->key_string(), |
| 257 kTestString)); | 268 kTestString)); |
| 258 } | 269 } |
| 259 | 270 |
| 260 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) { | 271 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) { |
| 261 base::FundamentalValue expected_value(true); | 272 base::FundamentalValue expected_value(true); |
| 262 CheckValue(test_keys::kKeyBoolean, | 273 CheckValue(harness_->key_boolean(), |
| 263 expected_value, | 274 expected_value, |
| 264 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy, | 275 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy, |
| 265 base::Unretained(test_harness_.get()), | 276 base::Unretained(harness_.get()), |
| 266 test_keys::kKeyBoolean, | 277 harness_->key_boolean(), |
| 267 true)); | 278 true)); |
| 268 } | 279 } |
| 269 | 280 |
| 270 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) { | 281 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) { |
| 271 base::FundamentalValue expected_value(42); | 282 base::FundamentalValue expected_value(42); |
| 272 CheckValue(test_keys::kKeyInteger, | 283 CheckValue(harness_->key_integer(), |
| 273 expected_value, | 284 expected_value, |
| 274 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, | 285 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, |
| 275 base::Unretained(test_harness_.get()), | 286 base::Unretained(harness_.get()), |
| 276 test_keys::kKeyInteger, | 287 harness_->key_integer(), |
| 277 42)); | 288 42)); |
| 278 } | 289 } |
| 279 | 290 |
| 280 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { | 291 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { |
| 281 base::ListValue expected_value; | 292 base::ListValue expected_value; |
| 282 expected_value.Set(0U, new base::StringValue("first")); | 293 expected_value.Set(0U, new base::StringValue("first")); |
| 283 expected_value.Set(1U, new base::StringValue("second")); | 294 expected_value.Set(1U, new base::StringValue("second")); |
| 284 CheckValue(test_keys::kKeyStringList, | 295 CheckValue(harness_->key_stringlist(), |
| 285 expected_value, | 296 expected_value, |
| 286 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, | 297 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, |
| 287 base::Unretained(test_harness_.get()), | 298 base::Unretained(harness_.get()), |
| 288 test_keys::kKeyStringList, | 299 harness_->key_stringlist(), |
| 289 &expected_value)); | 300 &expected_value)); |
| 290 } | 301 } |
| 291 | 302 |
| 292 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { | 303 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { |
| 293 base::DictionaryValue expected_value; | 304 base::DictionaryValue expected_value; |
| 294 expected_value.SetBoolean("bool", true); | 305 expected_value.SetBoolean("bool", true); |
| 295 expected_value.SetDouble("double", 123.456); | 306 expected_value.SetDouble("double", 123.456); |
| 296 expected_value.SetInteger("int", 123); | 307 expected_value.SetInteger("int", 123); |
| 297 expected_value.SetString("string", "omg"); | 308 expected_value.SetString("string", "omg"); |
| 298 | 309 |
| 299 base::ListValue* list = new base::ListValue(); | 310 base::ListValue* list = new base::ListValue(); |
| 300 list->Set(0U, new base::StringValue("first")); | 311 list->Set(0U, new base::StringValue("first")); |
| 301 list->Set(1U, new base::StringValue("second")); | 312 list->Set(1U, new base::StringValue("second")); |
| 302 expected_value.Set("array", list); | 313 expected_value.Set("array", list); |
| 303 | 314 |
| 304 base::DictionaryValue* dict = new base::DictionaryValue(); | 315 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 305 dict->SetString("sub", "value"); | 316 dict->SetString("sub", "value"); |
| 306 list = new base::ListValue(); | 317 list = new base::ListValue(); |
| 307 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue()); | 318 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue()); |
| 308 sub->SetInteger("aaa", 111); | 319 sub->SetInteger("aaa", 111); |
| 309 sub->SetInteger("bbb", 222); | 320 sub->SetInteger("bbb", 222); |
| 310 list->Append(std::move(sub)); | 321 list->Append(std::move(sub)); |
| 311 sub.reset(new base::DictionaryValue()); | 322 sub.reset(new base::DictionaryValue()); |
| 312 sub->SetString("ccc", "333"); | 323 sub->SetString("ccc", "333"); |
| 313 sub->SetString("ddd", "444"); | 324 sub->SetString("ddd", "444"); |
| 314 list->Append(std::move(sub)); | 325 list->Append(std::move(sub)); |
| 315 dict->Set("sublist", list); | 326 dict->Set("sublist", list); |
| 316 expected_value.Set("dictionary", dict); | 327 expected_value.Set("dictionary", dict); |
| 317 | 328 |
| 318 CheckValue(test_keys::kKeyDictionary, | 329 CheckValue(harness_->key_dictionary(), |
| 319 expected_value, | 330 expected_value, |
| 320 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, | 331 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, |
| 321 base::Unretained(test_harness_.get()), | 332 base::Unretained(harness_.get()), |
| 322 test_keys::kKeyDictionary, | 333 harness_->key_dictionary(), |
| 323 &expected_value)); | 334 &expected_value)); |
| 324 } | 335 } |
| 325 | 336 |
| 326 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { | 337 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { |
| 327 PolicyBundle bundle; | 338 PolicyBundle bundle; |
| 328 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 339 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 329 | 340 |
| 330 // OnUpdatePolicy is called even when there are no changes. | 341 // OnUpdatePolicy is called even when there are no changes. |
| 331 MockConfigurationPolicyObserver observer; | 342 MockConfigurationPolicyObserver observer; |
| 332 provider_->AddObserver(&observer); | 343 provider_->AddObserver(&observer); |
| 333 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 344 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
| 334 provider_->RefreshPolicies(); | 345 provider_->RefreshPolicies(); |
| 335 loop_.RunUntilIdle(); | 346 loop_.RunUntilIdle(); |
| 336 Mock::VerifyAndClearExpectations(&observer); | 347 Mock::VerifyAndClearExpectations(&observer); |
| 337 | 348 |
| 338 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 349 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 339 | 350 |
| 340 // OnUpdatePolicy is called when there are changes. | 351 // OnUpdatePolicy is called when there are changes. |
| 341 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); | 352 harness_->InstallStringPolicy(harness_->key_string(), "value"); |
| 342 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 353 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
| 343 provider_->RefreshPolicies(); | 354 provider_->RefreshPolicies(); |
| 344 loop_.RunUntilIdle(); | 355 loop_.RunUntilIdle(); |
| 345 Mock::VerifyAndClearExpectations(&observer); | 356 Mock::VerifyAndClearExpectations(&observer); |
| 346 | 357 |
| 347 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 358 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 348 .Set(test_keys::kKeyString, test_harness_->policy_level(), | 359 .Set(harness_->key_string(), harness_->policy_level(), |
| 349 test_harness_->policy_scope(), test_harness_->policy_source(), | 360 harness_->policy_scope(), harness_->policy_source(), |
| 350 base::WrapUnique(new base::StringValue("value")), nullptr); | 361 base::WrapUnique(new base::StringValue("value")), nullptr); |
| 351 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 362 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 352 provider_->RemoveObserver(&observer); | 363 provider_->RemoveObserver(&observer); |
| 353 } | 364 } |
| 354 | 365 |
| 355 Configuration3rdPartyPolicyProviderTest:: | 366 Configuration3rdPartyPolicyProviderTest:: |
| 356 Configuration3rdPartyPolicyProviderTest() {} | 367 Configuration3rdPartyPolicyProviderTest() {} |
| 357 | 368 |
| 358 Configuration3rdPartyPolicyProviderTest:: | 369 Configuration3rdPartyPolicyProviderTest:: |
| 359 ~Configuration3rdPartyPolicyProviderTest() {} | 370 ~Configuration3rdPartyPolicyProviderTest() {} |
| 360 | 371 |
| 361 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) { | 372 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) { |
| 362 base::DictionaryValue policy_dict; | 373 base::DictionaryValue policy_dict; |
| 363 policy_dict.SetBoolean("bool", true); | 374 policy_dict.SetBoolean("bool", true); |
| 364 policy_dict.SetDouble("double", 123.456); | 375 policy_dict.SetDouble("double", 123.456); |
| 365 policy_dict.SetInteger("int", 789); | 376 policy_dict.SetInteger("int", 789); |
| 366 policy_dict.SetString("string", "string value"); | 377 policy_dict.SetString("string", "string value"); |
| 367 | 378 |
| 368 base::ListValue* list = new base::ListValue(); | 379 base::ListValue* list = new base::ListValue(); |
| 369 for (int i = 0; i < 2; ++i) { | 380 for (int i = 0; i < 2; ++i) { |
| 370 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 381 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 371 dict->SetInteger("subdictindex", i); | 382 dict->SetInteger("subdictindex", i); |
| 372 dict->Set("subdict", policy_dict.DeepCopy()); | 383 dict->Set("subdict", policy_dict.DeepCopy()); |
| 373 list->Append(std::move(dict)); | 384 list->Append(std::move(dict)); |
| 374 } | 385 } |
| 375 policy_dict.Set("list", list); | 386 policy_dict.Set("list", list); |
| 376 policy_dict.Set("dict", policy_dict.DeepCopy()); | 387 policy_dict.Set("dict", policy_dict.DeepCopy()); |
| 377 | 388 |
| 378 // Install these policies as a Chrome policy. | 389 // Install these policies as a Chrome policy. |
| 379 test_harness_->InstallDictionaryPolicy(test_keys::kKeyDictionary, | 390 harness_->InstallDictionaryPolicy(harness_->key_dictionary(), &policy_dict); |
| 380 &policy_dict); | |
| 381 // Install them as 3rd party policies too. | 391 // Install them as 3rd party policies too. |
| 382 base::DictionaryValue policy_3rdparty; | 392 base::DictionaryValue policy_3rdparty; |
| 383 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | 393 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 384 policy_dict.DeepCopy()); | 394 policy_dict.DeepCopy()); |
| 385 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", | 395 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", |
| 386 policy_dict.DeepCopy()); | 396 policy_dict.DeepCopy()); |
| 387 // Install invalid 3rd party policies that shouldn't be loaded. These also | 397 // Install invalid 3rd party policies that shouldn't be loaded. These also |
| 388 // help detecting memory leaks in the code paths that detect invalid input. | 398 // help detecting memory leaks in the code paths that detect invalid input. |
| 389 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); | 399 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); |
| 390 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", | 400 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", |
| 391 new base::StringValue("invalid-value")); | 401 new base::StringValue("invalid-value")); |
| 392 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); | 402 harness_->Install3rdPartyPolicy(&policy_3rdparty); |
| 393 | 403 |
| 394 provider_->RefreshPolicies(); | 404 provider_->RefreshPolicies(); |
| 395 loop_.RunUntilIdle(); | 405 loop_.RunUntilIdle(); |
| 396 | 406 |
| 397 PolicyMap expected_policy; | 407 PolicyMap expected_policy; |
| 398 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(), | 408 expected_policy.Set(harness_->key_dictionary(), harness_->policy_level(), |
| 399 test_harness_->policy_scope(), | 409 harness_->policy_scope(), harness_->policy_source(), |
| 400 test_harness_->policy_source(), | |
| 401 policy_dict.CreateDeepCopy(), nullptr); | 410 policy_dict.CreateDeepCopy(), nullptr); |
| 402 PolicyBundle expected_bundle; | 411 PolicyBundle expected_bundle; |
| 403 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 412 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 404 .CopyFrom(expected_policy); | 413 .CopyFrom(expected_policy); |
| 405 expected_policy.Clear(); | 414 expected_policy.Clear(); |
| 406 expected_policy.LoadFrom(&policy_dict, | 415 expected_policy.LoadFrom(&policy_dict, |
| 407 test_harness_->policy_level(), | 416 harness_->policy_level(), |
| 408 test_harness_->policy_scope(), | 417 harness_->policy_scope(), |
| 409 test_harness_->policy_source()); | 418 harness_->policy_source()); |
| 410 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 419 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 411 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 420 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 412 .CopyFrom(expected_policy); | 421 .CopyFrom(expected_policy); |
| 413 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 422 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 414 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 423 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 415 .CopyFrom(expected_policy); | 424 .CopyFrom(expected_policy); |
| 416 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 425 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 417 } | 426 } |
| 418 | 427 |
| 419 } // namespace policy | 428 } // namespace policy |
| OLD | NEW |