| 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/cloud_policy_provider.h" | 5 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/policy/browser_policy_connector.h" | 9 #include "chrome/browser/policy/browser_policy_connector.h" |
| 10 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 10 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
| 11 #include "chrome/browser/policy/cloud_policy_provider_impl.h" | 11 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 12 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 13 #include "content/test/test_browser_thread.h" |
| 14 #include "policy/policy_constants.h" | 14 #include "policy/policy_constants.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using testing::Mock; | 18 using testing::Mock; |
| 18 using testing::_; | |
| 19 | 19 |
| 20 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
| 21 | 21 |
| 22 namespace policy { | 22 namespace policy { |
| 23 | 23 |
| 24 namespace { | |
| 25 | |
| 26 // Utility function for tests. | |
| 27 void SetPolicy(PolicyMap* map, const char* policy, Value* value) { | |
| 28 map->Set(policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value); | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 class MockCloudPolicyCache : public CloudPolicyCacheBase { | 24 class MockCloudPolicyCache : public CloudPolicyCacheBase { |
| 34 public: | 25 public: |
| 35 MockCloudPolicyCache() {} | 26 MockCloudPolicyCache() {} |
| 36 virtual ~MockCloudPolicyCache() {} | 27 virtual ~MockCloudPolicyCache() {} |
| 37 | 28 |
| 38 // CloudPolicyCacheBase implementation. | 29 virtual void Load() OVERRIDE {} |
| 39 void Load() OVERRIDE {} | 30 |
| 40 bool SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE { | 31 virtual bool SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE { |
| 41 return true; | |
| 42 } | |
| 43 bool DecodePolicyData(const em::PolicyData& policy_data, | |
| 44 PolicyMap* policies) OVERRIDE { | |
| 45 return true; | 32 return true; |
| 46 } | 33 } |
| 47 | 34 |
| 48 void SetUnmanaged() OVERRIDE { | 35 virtual void SetUnmanaged() OVERRIDE { |
| 49 is_unmanaged_ = true; | 36 is_unmanaged_ = true; |
| 50 } | 37 } |
| 51 | 38 |
| 39 virtual bool DecodePolicyData(const em::PolicyData& policy_data, |
| 40 PolicyMap* policies) OVERRIDE { |
| 41 return true; |
| 42 } |
| 43 |
| 52 PolicyMap* mutable_policy() { | 44 PolicyMap* mutable_policy() { |
| 53 return &policies_; | 45 return &policies_; |
| 54 } | 46 } |
| 55 | 47 |
| 56 void set_initialized(bool initialized) { | 48 // Make these methods public. |
| 57 initialization_complete_ = initialized; | 49 using CloudPolicyCacheBase::SetReady; |
| 58 } | 50 using CloudPolicyCacheBase::NotifyObservers; |
| 59 | |
| 60 void Set(const char *name, Value* value) { | |
| 61 policies_.Set(name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value); | |
| 62 } | |
| 63 | 51 |
| 64 private: | 52 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyCache); | 53 DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyCache); |
| 66 }; | 54 }; |
| 67 | 55 |
| 68 class CloudPolicyProviderTest : public testing::Test { | 56 class CloudPolicyProviderTest : public testing::Test { |
| 69 protected: | 57 protected: |
| 70 void CreateCloudPolicyProvider() { | 58 CloudPolicyProviderTest() |
| 71 cloud_policy_provider_.reset( | 59 : cloud_policy_provider_(&browser_policy_connector_, |
| 72 new CloudPolicyProviderImpl(&browser_policy_connector_, | 60 GetChromePolicyDefinitionList(), |
| 73 GetChromePolicyDefinitionList(), | 61 POLICY_LEVEL_MANDATORY) {} |
| 74 POLICY_LEVEL_MANDATORY)); | 62 |
| 63 void SetUp() OVERRIDE { |
| 64 registrar_.Init(&cloud_policy_provider_, &observer_); |
| 75 } | 65 } |
| 76 | 66 |
| 77 // Appends the caches to a provider and then provides the policies to | 67 void AddUserCache() { |
| 78 // |result|. | 68 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 79 void RunCachesThroughProvider(MockCloudPolicyCache caches[], int n, | 69 cloud_policy_provider_.SetUserPolicyCache(&user_policy_cache_); |
| 80 PolicyMap* result) { | 70 Mock::VerifyAndClearExpectations(&observer_); |
| 81 CloudPolicyProviderImpl provider( | |
| 82 &browser_policy_connector_, | |
| 83 GetChromePolicyDefinitionList(), | |
| 84 POLICY_LEVEL_MANDATORY); | |
| 85 for (int i = 0; i < n; i++) { | |
| 86 provider.AppendCache(&caches[i]); | |
| 87 } | |
| 88 provider.Provide(result); | |
| 89 } | 71 } |
| 90 | 72 |
| 91 void CombineTwoPolicyMaps(const PolicyMap& base, | 73 void AddDeviceCache() { |
| 92 const PolicyMap& overlay, | 74 #if defined(OS_CHROMEOS) |
| 93 PolicyMap* out_map) { | 75 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 94 MockCloudPolicyCache caches[2]; | 76 cloud_policy_provider_.SetDevicePolicyCache(&device_policy_cache_); |
| 95 caches[0].mutable_policy()->CopyFrom(base); | 77 Mock::VerifyAndClearExpectations(&observer_); |
| 96 caches[0].set_initialized(true); | 78 #endif |
| 97 caches[1].mutable_policy()->CopyFrom(overlay); | |
| 98 caches[1].set_initialized(true); | |
| 99 RunCachesThroughProvider(caches, 2, out_map); | |
| 100 } | 79 } |
| 101 | 80 |
| 102 void FixDeprecatedPolicies(PolicyMap* policies) { | 81 void SetUserCacheReady() { |
| 103 CloudPolicyProviderImpl::FixDeprecatedPolicies(policies); | 82 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 83 user_policy_cache_.SetReady(); |
| 84 Mock::VerifyAndClearExpectations(&observer_); |
| 85 EXPECT_TRUE(user_policy_cache_.IsReady()); |
| 104 } | 86 } |
| 105 | 87 |
| 106 scoped_ptr<CloudPolicyProviderImpl> cloud_policy_provider_; | 88 void SetDeviceCacheReady() { |
| 89 #if defined(OS_CHROMEOS) |
| 90 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 91 device_policy_cache_.SetReady(); |
| 92 Mock::VerifyAndClearExpectations(&observer_); |
| 93 EXPECT_TRUE(device_policy_cache_.IsReady()); |
| 94 #endif |
| 95 } |
| 107 | 96 |
| 108 private: | |
| 109 BrowserPolicyConnector browser_policy_connector_; | 97 BrowserPolicyConnector browser_policy_connector_; |
| 98 |
| 99 MockCloudPolicyCache user_policy_cache_; |
| 100 #if defined(OS_CHROMEOS) |
| 101 MockCloudPolicyCache device_policy_cache_; |
| 102 #endif |
| 103 |
| 104 CloudPolicyProvider cloud_policy_provider_; |
| 105 MockConfigurationPolicyObserver observer_; |
| 106 ConfigurationPolicyObserverRegistrar registrar_; |
| 110 }; | 107 }; |
| 111 | 108 |
| 112 // Proxy setting distributed over multiple caches. | 109 TEST_F(CloudPolicyProviderTest, Initialization) { |
| 113 TEST_F(CloudPolicyProviderTest, | 110 EXPECT_FALSE(cloud_policy_provider_.IsInitializationComplete()); |
| 114 ProxySettingDistributedOverMultipleCaches) { | |
| 115 // There are proxy_policy_count()+1 = 6 caches and they are mixed together by | |
| 116 // one instance of CloudPolicyProvider. The first cache has some policies but | |
| 117 // no proxy-related ones. The following caches have each one proxy-policy set. | |
| 118 const int n = 6; | |
| 119 MockCloudPolicyCache caches[n]; | |
| 120 | 111 |
| 121 // Prepare |cache[0]| to serve some non-proxy policies. | 112 // The provider only becomes initialized when it has all caches, and the |
| 122 caches[0].Set(key::kShowHomeButton, Value::CreateBooleanValue(true)); | 113 // caches are ready too. |
| 123 caches[0].Set(key::kIncognitoEnabled, Value::CreateBooleanValue(true)); | 114 AddDeviceCache(); |
| 124 caches[0].Set(key::kTranslateEnabled, Value::CreateBooleanValue(true)); | 115 EXPECT_FALSE(cloud_policy_provider_.IsInitializationComplete()); |
| 125 caches[0].set_initialized(true); | 116 SetDeviceCacheReady(); |
| 117 EXPECT_FALSE(cloud_policy_provider_.IsInitializationComplete()); |
| 118 AddUserCache(); |
| 119 EXPECT_FALSE(user_policy_cache_.IsReady()); |
| 120 EXPECT_FALSE(cloud_policy_provider_.IsInitializationComplete()); |
| 126 | 121 |
| 127 // Prepare the other caches to serve one proxy-policy each. | 122 PolicyMap policy; |
| 128 caches[1].Set(key::kProxyMode, Value::CreateStringValue("cache 1")); | 123 EXPECT_TRUE(cloud_policy_provider_.Provide(&policy)); |
| 129 caches[1].set_initialized(true); | 124 EXPECT_TRUE(policy.empty()); |
| 130 caches[2].Set(key::kProxyServerMode, Value::CreateIntegerValue(2)); | |
| 131 caches[2].set_initialized(true); | |
| 132 caches[3].Set(key::kProxyServer, Value::CreateStringValue("cache 3")); | |
| 133 caches[3].set_initialized(true); | |
| 134 caches[4].Set(key::kProxyPacUrl, Value::CreateStringValue("cache 4")); | |
| 135 caches[4].set_initialized(true); | |
| 136 caches[5].Set(key::kProxyMode, Value::CreateStringValue("cache 5")); | |
| 137 caches[5].set_initialized(true); | |
| 138 | 125 |
| 139 PolicyMap policies; | 126 SetUserCacheReady(); |
| 140 RunCachesThroughProvider(caches, n, &policies); | 127 EXPECT_TRUE(cloud_policy_provider_.IsInitializationComplete()); |
| 128 EXPECT_TRUE(cloud_policy_provider_.Provide(&policy)); |
| 129 EXPECT_TRUE(policy.empty()); |
| 141 | 130 |
| 142 // Verify expectations. | 131 const std::string kUrl("http://chromium.org"); |
| 143 EXPECT_TRUE(policies.Get(key::kProxyMode) == NULL); | 132 user_policy_cache_.mutable_policy()->Set(key::kHomepageLocation, |
| 144 EXPECT_TRUE(policies.Get(key::kProxyServerMode) == NULL); | 133 POLICY_LEVEL_MANDATORY, |
| 145 EXPECT_TRUE(policies.Get(key::kProxyServer) == NULL); | 134 POLICY_SCOPE_USER, |
| 146 EXPECT_TRUE(policies.Get(key::kProxyPacUrl) == NULL); | 135 Value::CreateStringValue(kUrl)); |
| 136 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 137 user_policy_cache_.NotifyObservers(); |
| 138 Mock::VerifyAndClearExpectations(&observer_); |
| 139 EXPECT_TRUE(cloud_policy_provider_.Provide(&policy)); |
| 147 | 140 |
| 148 const Value* value = policies.GetValue(key::kProxySettings); | 141 PolicyMap expected; |
| 149 ASSERT_TRUE(value != NULL); | 142 expected.Set(key::kHomepageLocation, |
| 150 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); | 143 POLICY_LEVEL_MANDATORY, |
| 151 const DictionaryValue* settings = static_cast<const DictionaryValue*>(value); | 144 POLICY_SCOPE_USER, |
| 152 std::string mode; | 145 Value::CreateStringValue(kUrl)); |
| 153 EXPECT_TRUE(settings->GetString(key::kProxyMode, &mode)); | 146 EXPECT_TRUE(policy.Equals(expected)); |
| 154 EXPECT_EQ("cache 1", mode); | |
| 155 | |
| 156 base::FundamentalValue expected(true); | |
| 157 EXPECT_TRUE(base::Value::Equals(&expected, | |
| 158 policies.GetValue(key::kShowHomeButton))); | |
| 159 EXPECT_TRUE(base::Value::Equals(&expected, | |
| 160 policies.GetValue(key::kIncognitoEnabled))); | |
| 161 EXPECT_TRUE(base::Value::Equals(&expected, | |
| 162 policies.GetValue(key::kTranslateEnabled))); | |
| 163 } | |
| 164 | |
| 165 // Combining two PolicyMaps. | |
| 166 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsSame) { | |
| 167 PolicyMap A, B, C; | |
| 168 SetPolicy(&A, key::kHomepageLocation, | |
| 169 Value::CreateStringValue("http://www.chromium.org")); | |
| 170 SetPolicy(&B, key::kHomepageLocation, | |
| 171 Value::CreateStringValue("http://www.google.com")); | |
| 172 SetPolicy(&A, key::kApplicationLocaleValue, Value::CreateStringValue("hu")); | |
| 173 SetPolicy(&B, key::kApplicationLocaleValue, Value::CreateStringValue("us")); | |
| 174 SetPolicy(&A, key::kDevicePolicyRefreshRate, new base::FundamentalValue(100)); | |
| 175 SetPolicy(&B, key::kDevicePolicyRefreshRate, new base::FundamentalValue(200)); | |
| 176 CombineTwoPolicyMaps(A, B, &C); | |
| 177 EXPECT_TRUE(A.Equals(C)); | |
| 178 } | |
| 179 | |
| 180 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsEmpty) { | |
| 181 PolicyMap A, B, C; | |
| 182 CombineTwoPolicyMaps(A, B, &C); | |
| 183 EXPECT_TRUE(C.empty()); | |
| 184 } | |
| 185 | |
| 186 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsPartial) { | |
| 187 PolicyMap A, B, C; | |
| 188 | |
| 189 SetPolicy(&A, key::kHomepageLocation, | |
| 190 Value::CreateStringValue("http://www.chromium.org")); | |
| 191 SetPolicy(&B, key::kHomepageLocation, | |
| 192 Value::CreateStringValue("http://www.google.com")); | |
| 193 SetPolicy(&B, key::kApplicationLocaleValue, Value::CreateStringValue("us")); | |
| 194 SetPolicy(&A, key::kDevicePolicyRefreshRate, new base::FundamentalValue(100)); | |
| 195 SetPolicy(&B, key::kDevicePolicyRefreshRate, new base::FundamentalValue(200)); | |
| 196 CombineTwoPolicyMaps(A, B, &C); | |
| 197 | |
| 198 const Value* value; | |
| 199 std::string string_value; | |
| 200 int int_value; | |
| 201 value = C.GetValue(key::kHomepageLocation); | |
| 202 ASSERT_TRUE(NULL != value); | |
| 203 EXPECT_TRUE(value->GetAsString(&string_value)); | |
| 204 EXPECT_EQ("http://www.chromium.org", string_value); | |
| 205 value = C.GetValue(key::kApplicationLocaleValue); | |
| 206 ASSERT_TRUE(NULL != value); | |
| 207 EXPECT_TRUE(value->GetAsString(&string_value)); | |
| 208 EXPECT_EQ("us", string_value); | |
| 209 value = C.GetValue(key::kDevicePolicyRefreshRate); | |
| 210 ASSERT_TRUE(NULL != value); | |
| 211 EXPECT_TRUE(value->GetAsInteger(&int_value)); | |
| 212 EXPECT_EQ(100, int_value); | |
| 213 } | |
| 214 | |
| 215 TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsProxies) { | |
| 216 const int a_value = 1; | |
| 217 const int b_value = -1; | |
| 218 PolicyMap A, B, C; | |
| 219 | |
| 220 SetPolicy(&A, key::kProxyMode, Value::CreateIntegerValue(a_value)); | |
| 221 SetPolicy(&B, key::kProxyServerMode, Value::CreateIntegerValue(b_value)); | |
| 222 SetPolicy(&B, key::kProxyServer, Value::CreateIntegerValue(b_value)); | |
| 223 SetPolicy(&B, key::kProxyPacUrl, Value::CreateIntegerValue(b_value)); | |
| 224 SetPolicy(&B, key::kProxyBypassList, Value::CreateIntegerValue(b_value)); | |
| 225 | |
| 226 CombineTwoPolicyMaps(A, B, &C); | |
| 227 | |
| 228 FixDeprecatedPolicies(&A); | |
| 229 FixDeprecatedPolicies(&B); | |
| 230 EXPECT_TRUE(A.Equals(C)); | |
| 231 EXPECT_FALSE(B.Equals(C)); | |
| 232 } | 147 } |
| 233 | 148 |
| 234 TEST_F(CloudPolicyProviderTest, RefreshPolicies) { | 149 TEST_F(CloudPolicyProviderTest, RefreshPolicies) { |
| 235 CreateCloudPolicyProvider(); | |
| 236 MockCloudPolicyCache cache0; | |
| 237 MockCloudPolicyCache cache1; | |
| 238 MockCloudPolicyCache cache2; | |
| 239 MockConfigurationPolicyObserver observer; | |
| 240 ConfigurationPolicyObserverRegistrar registrar; | |
| 241 registrar.Init(cloud_policy_provider_.get(), &observer); | |
| 242 | |
| 243 // OnUpdatePolicy is called when the provider doesn't have any caches. | 150 // OnUpdatePolicy is called when the provider doesn't have any caches. |
| 244 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1); | 151 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(1); |
| 245 cloud_policy_provider_->RefreshPolicies(); | 152 cloud_policy_provider_.RefreshPolicies(); |
| 246 Mock::VerifyAndClearExpectations(&observer); | 153 Mock::VerifyAndClearExpectations(&observer_); |
| 247 | 154 |
| 248 // OnUpdatePolicy is called when all the caches have updated. | 155 // OnUpdatePolicy is called when all the caches have updated. |
| 249 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(2); | 156 AddUserCache(); |
| 250 cloud_policy_provider_->AppendCache(&cache0); | |
| 251 cloud_policy_provider_->AppendCache(&cache1); | |
| 252 Mock::VerifyAndClearExpectations(&observer); | |
| 253 | 157 |
| 254 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0); | 158 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(0); |
| 255 cloud_policy_provider_->RefreshPolicies(); | 159 cloud_policy_provider_.RefreshPolicies(); |
| 256 Mock::VerifyAndClearExpectations(&observer); | 160 Mock::VerifyAndClearExpectations(&observer_); |
| 257 | 161 |
| 258 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0); | 162 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(1); |
| 259 // Updating just one of the caches is not enough. | 163 cloud_policy_provider_.OnCacheUpdate(&user_policy_cache_); |
| 260 cloud_policy_provider_->OnCacheUpdate(&cache0); | 164 Mock::VerifyAndClearExpectations(&observer_); |
| 261 Mock::VerifyAndClearExpectations(&observer); | |
| 262 | 165 |
| 263 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0); | 166 #if defined(OS_CHROMEOS) |
| 264 // This cache wasn't available when RefreshPolicies was called, so it isn't | 167 AddDeviceCache(); |
| 265 // required to fire the update. | |
| 266 cloud_policy_provider_->AppendCache(&cache2); | |
| 267 Mock::VerifyAndClearExpectations(&observer); | |
| 268 | 168 |
| 269 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1); | 169 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(0); |
| 270 cloud_policy_provider_->OnCacheUpdate(&cache1); | 170 cloud_policy_provider_.RefreshPolicies(); |
| 271 Mock::VerifyAndClearExpectations(&observer); | 171 Mock::VerifyAndClearExpectations(&observer_); |
| 272 | 172 |
| 273 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0); | 173 // Updating one of the caches is not enough, both must be updated. |
| 274 cloud_policy_provider_->RefreshPolicies(); | 174 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(0); |
| 275 Mock::VerifyAndClearExpectations(&observer); | 175 cloud_policy_provider_.OnCacheUpdate(&user_policy_cache_); |
| 276 | 176 Mock::VerifyAndClearExpectations(&observer_); |
| 277 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0); | |
| 278 cloud_policy_provider_->OnCacheUpdate(&cache0); | |
| 279 cloud_policy_provider_->OnCacheUpdate(&cache1); | |
| 280 Mock::VerifyAndClearExpectations(&observer); | |
| 281 | 177 |
| 282 // If a cache refreshes more than once, the provider should still wait for | 178 // If a cache refreshes more than once, the provider should still wait for |
| 283 // the others before firing the update. | 179 // the others before firing the update. |
| 284 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(0); | 180 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(0); |
| 285 cloud_policy_provider_->OnCacheUpdate(&cache0); | 181 cloud_policy_provider_.OnCacheUpdate(&user_policy_cache_); |
| 286 Mock::VerifyAndClearExpectations(&observer); | 182 Mock::VerifyAndClearExpectations(&observer_); |
| 287 | 183 |
| 288 // Fire updates if one of the required caches goes away while waiting. | 184 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)).Times(1); |
| 289 EXPECT_CALL(observer, OnUpdatePolicy(cloud_policy_provider_.get())).Times(1); | 185 cloud_policy_provider_.OnCacheUpdate(&device_policy_cache_); |
| 290 cloud_policy_provider_->OnCacheGoingAway(&cache2); | 186 Mock::VerifyAndClearExpectations(&observer_); |
| 291 Mock::VerifyAndClearExpectations(&observer); | 187 #endif |
| 292 } | 188 } |
| 293 | 189 |
| 190 #if defined(OS_CHROMEOS) |
| 191 TEST_F(CloudPolicyProviderTest, MergeProxyPolicies) { |
| 192 AddDeviceCache(); |
| 193 AddUserCache(); |
| 194 SetDeviceCacheReady(); |
| 195 SetUserCacheReady(); |
| 196 EXPECT_TRUE(cloud_policy_provider_.IsInitializationComplete()); |
| 197 PolicyMap policy; |
| 198 EXPECT_TRUE(cloud_policy_provider_.Provide(&policy)); |
| 199 EXPECT_TRUE(policy.empty()); |
| 200 |
| 201 // User policy takes precedence over device policy. |
| 202 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 203 device_policy_cache_.mutable_policy()->Set( |
| 204 key::kProxyMode, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, |
| 205 Value::CreateStringValue("device mode")); |
| 206 device_policy_cache_.NotifyObservers(); |
| 207 Mock::VerifyAndClearExpectations(&observer_); |
| 208 |
| 209 EXPECT_CALL(observer_, OnUpdatePolicy(&cloud_policy_provider_)); |
| 210 user_policy_cache_.mutable_policy()->Set( |
| 211 key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 212 Value::CreateStringValue("user mode")); |
| 213 user_policy_cache_.NotifyObservers(); |
| 214 Mock::VerifyAndClearExpectations(&observer_); |
| 215 |
| 216 EXPECT_TRUE(cloud_policy_provider_.Provide(&policy)); |
| 217 |
| 218 // The deprecated proxy policies are converted to the new ProxySettings. |
| 219 EXPECT_TRUE(policy.Get(key::kProxyMode) == NULL); |
| 220 EXPECT_TRUE(policy.Get(key::kProxyServerMode) == NULL); |
| 221 EXPECT_TRUE(policy.Get(key::kProxyServer) == NULL); |
| 222 EXPECT_TRUE(policy.Get(key::kProxyPacUrl) == NULL); |
| 223 |
| 224 EXPECT_EQ(1u, policy.size()); |
| 225 const PolicyMap::Entry* entry = policy.Get(key::kProxySettings); |
| 226 ASSERT_TRUE(entry != NULL); |
| 227 ASSERT_TRUE(entry->value != NULL); |
| 228 EXPECT_EQ(POLICY_LEVEL_MANDATORY, entry->level); |
| 229 EXPECT_EQ(POLICY_SCOPE_USER, entry->scope); |
| 230 const DictionaryValue* settings; |
| 231 ASSERT_TRUE(entry->value->GetAsDictionary(&settings)); |
| 232 std::string mode; |
| 233 EXPECT_TRUE(settings->GetString(key::kProxyMode, &mode)); |
| 234 EXPECT_EQ("user mode", mode); |
| 235 } |
| 236 #endif |
| 237 |
| 294 } // namespace policy | 238 } // namespace policy |
| OLD | NEW |