Index: components/policy/core/common/policy_service_impl_unittest.cc |
diff --git a/components/policy/core/common/policy_service_impl_unittest.cc b/components/policy/core/common/policy_service_impl_unittest.cc |
index ae51237aac6932f4b0a5bf402f14cc78f8b2569f..d9431f12160b569ed06d52fb8fa7bf4d87bc7ffd 100644 |
--- a/components/policy/core/common/policy_service_impl_unittest.cc |
+++ b/components/policy/core/common/policy_service_impl_unittest.cc |
@@ -13,6 +13,7 @@ |
#include "components/policy/core/common/external_data_fetcher.h" |
#include "components/policy/core/common/mock_configuration_policy_provider.h" |
#include "components/policy/core/common/mock_policy_service.h" |
+#include "components/policy/core/common/policy_types.h" |
#include "policy/policy_constants.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -52,19 +53,23 @@ void AddTestPolicies(PolicyBundle* bundle, |
policy_map->Set(kSameLevelPolicy, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::StringValue(value), |
NULL); |
policy_map->Set( |
- kDiffLevelPolicy, level, scope, new base::StringValue(value), NULL); |
+ kDiffLevelPolicy, level, scope, POLICY_SOURCE_PLATFORM, |
+ new base::StringValue(value), nullptr); |
policy_map = |
&bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)); |
policy_map->Set(kSameLevelPolicy, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::StringValue(value), |
NULL); |
policy_map->Set( |
- kDiffLevelPolicy, level, scope, new base::StringValue(value), NULL); |
+ kDiffLevelPolicy, level, scope, POLICY_SOURCE_PLATFORM, |
+ new base::StringValue(value), nullptr); |
} |
// Observer class that changes the policy in the passed provider when the |
@@ -82,6 +87,7 @@ class ChangePolicyObserver : public PolicyService::Observer { |
new_policy.Set("foo", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(14), |
NULL); |
provider_->UpdateChromePolicy(new_policy); |
@@ -115,6 +121,7 @@ class PolicyServiceTest : public testing::Test { |
policy0_.Set("pre", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::FundamentalValue(13), |
NULL); |
provider0_.UpdateChromePolicy(policy0_); |
@@ -167,6 +174,7 @@ TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { |
expected.Set("pre", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::FundamentalValue(13), |
NULL); |
EXPECT_TRUE(VerifyPolicies( |
@@ -181,6 +189,7 @@ TEST_F(PolicyServiceTest, NotifyObservers) { |
expectedPrevious.Set("pre", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::FundamentalValue(13), |
NULL); |
@@ -189,11 +198,13 @@ TEST_F(PolicyServiceTest, NotifyObservers) { |
expectedCurrent.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(123), |
NULL); |
policy0_.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(123), |
NULL); |
EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
@@ -215,11 +226,13 @@ TEST_F(PolicyServiceTest, NotifyObservers) { |
expectedCurrent.Set("bbb", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(456), |
NULL); |
policy0_.Set("bbb", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(456), |
NULL); |
EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
@@ -245,11 +258,13 @@ TEST_F(PolicyServiceTest, NotifyObservers) { |
expectedCurrent.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(789), |
NULL); |
policy0_.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(789), |
NULL); |
@@ -283,6 +298,7 @@ TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) { |
previous_policy_map.Set("pre", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::FundamentalValue(13), |
NULL); |
PolicyMap policy_map; |
@@ -290,6 +306,7 @@ TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) { |
policy_map.Set("policy", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::StringValue("value"), |
NULL); |
@@ -332,6 +349,7 @@ TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) { |
policy_map.Set("policy", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::StringValue("another value"), |
NULL); |
bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) |
@@ -371,11 +389,13 @@ TEST_F(PolicyServiceTest, ObserverChangesPolicy) { |
policy0_.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(123), |
NULL); |
policy0_.Set("bbb", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(1234), |
NULL); |
// Should not crash. |
@@ -389,26 +409,31 @@ TEST_F(PolicyServiceTest, Priorities) { |
expected.Set("pre", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::FundamentalValue(13), |
NULL); |
expected.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(0), |
NULL); |
policy0_.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(0), |
NULL); |
policy1_.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(1), |
NULL); |
policy2_.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(2), |
NULL); |
provider0_.UpdateChromePolicy(policy0_); |
@@ -420,6 +445,7 @@ TEST_F(PolicyServiceTest, Priorities) { |
expected.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(1), |
NULL); |
policy0_.Erase("aaa"); |
@@ -430,11 +456,13 @@ TEST_F(PolicyServiceTest, Priorities) { |
expected.Set("aaa", |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(2), |
NULL); |
policy1_.Set("aaa", |
POLICY_LEVEL_RECOMMENDED, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(1), |
NULL); |
provider1_.UpdateChromePolicy(policy1_); |
@@ -462,14 +490,14 @@ TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { |
base::FundamentalValue kValue0(0); |
EXPECT_CALL(*this, OnPolicyValueUpdated(NULL, ValueEquals(&kValue0))); |
policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue0.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); |
provider0_.UpdateChromePolicy(policy0_); |
Mock::VerifyAndClearExpectations(this); |
// Changing other values doesn't trigger a notification. |
EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); |
policy0_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue0.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); |
provider0_.UpdateChromePolicy(policy0_); |
Mock::VerifyAndClearExpectations(this); |
@@ -478,7 +506,7 @@ TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { |
EXPECT_CALL(*this, OnPolicyValueUpdated(ValueEquals(&kValue0), |
ValueEquals(&kValue1))); |
policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue1.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); |
provider0_.UpdateChromePolicy(policy0_); |
Mock::VerifyAndClearExpectations(this); |
@@ -492,9 +520,9 @@ TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { |
EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); |
registrar.reset(); |
policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue1.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); |
policy0_.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue1.DeepCopy(), NULL); |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, kValue1.DeepCopy(), nullptr); |
provider0_.UpdateChromePolicy(policy0_); |
Mock::VerifyAndClearExpectations(this); |
} |
@@ -515,14 +543,14 @@ TEST_F(PolicyServiceTest, RefreshPolicies) { |
EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
base::FundamentalValue kValue0(0); |
policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue0.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); |
provider0_.UpdateChromePolicy(policy0_); |
Mock::VerifyAndClearExpectations(this); |
EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
base::FundamentalValue kValue1(1); |
policy1_.Set("aaa", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
- kValue1.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); |
provider1_.UpdateChromePolicy(policy1_); |
Mock::VerifyAndClearExpectations(this); |
@@ -531,7 +559,7 @@ TEST_F(PolicyServiceTest, RefreshPolicies) { |
// refreshed. |
EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
policy1_.Set("bbb", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
- kValue1.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); |
provider1_.UpdateChromePolicy(policy1_); |
Mock::VerifyAndClearExpectations(this); |
@@ -546,7 +574,7 @@ TEST_F(PolicyServiceTest, RefreshPolicies) { |
EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
policy2_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue0.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); |
provider2_.UpdateChromePolicy(policy2_); |
Mock::VerifyAndClearExpectations(this); |
@@ -554,7 +582,7 @@ TEST_F(PolicyServiceTest, RefreshPolicies) { |
EXPECT_CALL(*this, OnPolicyRefresh()).Times(2); |
base::FundamentalValue kValue2(2); |
policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
- kValue2.DeepCopy(), NULL); |
+ POLICY_SOURCE_CLOUD, kValue2.DeepCopy(), nullptr); |
provider0_.UpdateChromePolicy(policy0_); |
provider1_.UpdateChromePolicy(policy1_); |
Mock::VerifyAndClearExpectations(this); |
@@ -588,6 +616,7 @@ TEST_F(PolicyServiceTest, NamespaceMerge) { |
expected.Set(kSameLevelPolicy, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_ENTERPRISE_DEFAULT, |
new base::StringValue("bundle0"), |
NULL); |
// For policies with different levels and scopes, the highest priority |
@@ -595,6 +624,7 @@ TEST_F(PolicyServiceTest, NamespaceMerge) { |
expected.Set(kDiffLevelPolicy, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_MACHINE, |
+ POLICY_SOURCE_PLATFORM, |
new base::StringValue("bundle2"), |
NULL); |
EXPECT_TRUE(policy_service_->GetPolicies( |
@@ -694,6 +724,7 @@ TEST_F(PolicyServiceTest, FixDeprecatedPolicies) { |
policy_map.Set(key::kProxyServerMode, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(3), |
NULL); |
@@ -702,11 +733,13 @@ TEST_F(PolicyServiceTest, FixDeprecatedPolicies) { |
policy_map.Set(key::kProxyMode, |
POLICY_LEVEL_RECOMMENDED, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::StringValue("pac_script"), |
NULL); |
policy_map.Set(key::kProxyPacUrl, |
POLICY_LEVEL_RECOMMENDED, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::StringValue("http://example.com/wpad.dat"), |
NULL); |
@@ -714,6 +747,7 @@ TEST_F(PolicyServiceTest, FixDeprecatedPolicies) { |
policy_bundle->Get(extension_namespace).Set(key::kProxyServerMode, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(3), |
NULL); |
@@ -722,13 +756,15 @@ TEST_F(PolicyServiceTest, FixDeprecatedPolicies) { |
scoped_ptr<base::DictionaryValue> expected_value(new base::DictionaryValue); |
expected_value->SetInteger(key::kProxyServerMode, 3); |
expected_chrome.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, |
- POLICY_SCOPE_USER, expected_value.release(), NULL); |
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
+ expected_value.release(), nullptr); |
// The resulting Extensions namespace map shouldn't have been modified. |
PolicyMap expected_extension; |
expected_extension.Set(key::kProxyServerMode, |
POLICY_LEVEL_MANDATORY, |
POLICY_SCOPE_USER, |
+ POLICY_SOURCE_CLOUD, |
new base::FundamentalValue(3), |
NULL); |