| 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/extensions/api/storage/policy_value_store.h" | 5 #include "chrome/browser/extensions/api/storage/policy_value_store.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 std::unique_ptr<PolicyValueStore> store_; | 118 std::unique_ptr<PolicyValueStore> store_; |
| 119 MockSettingsObserver observer_; | 119 MockSettingsObserver observer_; |
| 120 scoped_refptr<SettingsObserverList> observers_; | 120 scoped_refptr<SettingsObserverList> observers_; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { | 123 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { |
| 124 policy::PolicyMap policies; | 124 policy::PolicyMap policies; |
| 125 base::FundamentalValue expected(123); | 125 base::FundamentalValue expected(123); |
| 126 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, | 126 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, |
| 127 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 127 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
| 128 expected.DeepCopy(), nullptr); | 128 expected.CreateDeepCopy(), nullptr); |
| 129 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, | 129 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, |
| 130 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 130 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
| 131 new base::FundamentalValue(456), NULL); | 131 base::WrapUnique(new base::FundamentalValue(456)), nullptr); |
| 132 store_->SetCurrentPolicy(policies); | 132 store_->SetCurrentPolicy(policies); |
| 133 ValueStore::ReadResult result = store_->Get(); | 133 ValueStore::ReadResult result = store_->Get(); |
| 134 ASSERT_TRUE(result->status().ok()); | 134 ASSERT_TRUE(result->status().ok()); |
| 135 EXPECT_EQ(1u, result->settings().size()); | 135 EXPECT_EQ(1u, result->settings().size()); |
| 136 base::Value* value = NULL; | 136 base::Value* value = NULL; |
| 137 EXPECT_FALSE(result->settings().Get("may", &value)); | 137 EXPECT_FALSE(result->settings().Get("may", &value)); |
| 138 EXPECT_TRUE(result->settings().Get("must", &value)); | 138 EXPECT_TRUE(result->settings().Get("must", &value)); |
| 139 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 139 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 163 ValueStoreChangeList changes; | 163 ValueStoreChangeList changes; |
| 164 changes.push_back(ValueStoreChange("aaa", NULL, value.DeepCopy())); | 164 changes.push_back(ValueStoreChange("aaa", NULL, value.DeepCopy())); |
| 165 EXPECT_CALL(observer_, | 165 EXPECT_CALL(observer_, |
| 166 OnSettingsChanged(kTestExtensionId, | 166 OnSettingsChanged(kTestExtensionId, |
| 167 settings_namespace::MANAGED, | 167 settings_namespace::MANAGED, |
| 168 ValueStoreChange::ToJson(changes))); | 168 ValueStoreChange::ToJson(changes))); |
| 169 } | 169 } |
| 170 | 170 |
| 171 policy::PolicyMap policies; | 171 policy::PolicyMap policies; |
| 172 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 172 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 173 policy::POLICY_SOURCE_CLOUD, value.DeepCopy(), nullptr); | 173 policy::POLICY_SOURCE_CLOUD, value.CreateDeepCopy(), nullptr); |
| 174 store_->SetCurrentPolicy(policies); | 174 store_->SetCurrentPolicy(policies); |
| 175 loop_.RunUntilIdle(); | 175 loop_.RunUntilIdle(); |
| 176 Mock::VerifyAndClearExpectations(&observer_); | 176 Mock::VerifyAndClearExpectations(&observer_); |
| 177 | 177 |
| 178 // Notify when new policies are added. | 178 // Notify when new policies are added. |
| 179 { | 179 { |
| 180 ValueStoreChangeList changes; | 180 ValueStoreChangeList changes; |
| 181 changes.push_back(ValueStoreChange("bbb", NULL, value.DeepCopy())); | 181 changes.push_back(ValueStoreChange("bbb", NULL, value.DeepCopy())); |
| 182 EXPECT_CALL(observer_, | 182 EXPECT_CALL(observer_, |
| 183 OnSettingsChanged(kTestExtensionId, | 183 OnSettingsChanged(kTestExtensionId, |
| 184 settings_namespace::MANAGED, | 184 settings_namespace::MANAGED, |
| 185 ValueStoreChange::ToJson(changes))); | 185 ValueStoreChange::ToJson(changes))); |
| 186 } | 186 } |
| 187 | 187 |
| 188 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 188 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 189 policy::POLICY_SOURCE_CLOUD, value.DeepCopy(), nullptr); | 189 policy::POLICY_SOURCE_CLOUD, value.CreateDeepCopy(), nullptr); |
| 190 store_->SetCurrentPolicy(policies); | 190 store_->SetCurrentPolicy(policies); |
| 191 loop_.RunUntilIdle(); | 191 loop_.RunUntilIdle(); |
| 192 Mock::VerifyAndClearExpectations(&observer_); | 192 Mock::VerifyAndClearExpectations(&observer_); |
| 193 | 193 |
| 194 // Notify when policies change. | 194 // Notify when policies change. |
| 195 const base::StringValue new_value("222"); | 195 const base::StringValue new_value("222"); |
| 196 { | 196 { |
| 197 ValueStoreChangeList changes; | 197 ValueStoreChangeList changes; |
| 198 changes.push_back( | 198 changes.push_back( |
| 199 ValueStoreChange("bbb", value.DeepCopy(), new_value.DeepCopy())); | 199 ValueStoreChange("bbb", value.DeepCopy(), new_value.DeepCopy())); |
| 200 EXPECT_CALL(observer_, | 200 EXPECT_CALL(observer_, |
| 201 OnSettingsChanged(kTestExtensionId, | 201 OnSettingsChanged(kTestExtensionId, |
| 202 settings_namespace::MANAGED, | 202 settings_namespace::MANAGED, |
| 203 ValueStoreChange::ToJson(changes))); | 203 ValueStoreChange::ToJson(changes))); |
| 204 } | 204 } |
| 205 | 205 |
| 206 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 206 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 207 policy::POLICY_SOURCE_CLOUD, new_value.DeepCopy(), nullptr); | 207 policy::POLICY_SOURCE_CLOUD, new_value.CreateDeepCopy(), |
| 208 nullptr); |
| 208 store_->SetCurrentPolicy(policies); | 209 store_->SetCurrentPolicy(policies); |
| 209 loop_.RunUntilIdle(); | 210 loop_.RunUntilIdle(); |
| 210 Mock::VerifyAndClearExpectations(&observer_); | 211 Mock::VerifyAndClearExpectations(&observer_); |
| 211 | 212 |
| 212 // Notify when policies are removed. | 213 // Notify when policies are removed. |
| 213 { | 214 { |
| 214 ValueStoreChangeList changes; | 215 ValueStoreChangeList changes; |
| 215 changes.push_back(ValueStoreChange("bbb", new_value.DeepCopy(), NULL)); | 216 changes.push_back(ValueStoreChange("bbb", new_value.DeepCopy(), NULL)); |
| 216 EXPECT_CALL(observer_, | 217 EXPECT_CALL(observer_, |
| 217 OnSettingsChanged(kTestExtensionId, | 218 OnSettingsChanged(kTestExtensionId, |
| 218 settings_namespace::MANAGED, | 219 settings_namespace::MANAGED, |
| 219 ValueStoreChange::ToJson(changes))); | 220 ValueStoreChange::ToJson(changes))); |
| 220 } | 221 } |
| 221 | 222 |
| 222 policies.Erase("bbb"); | 223 policies.Erase("bbb"); |
| 223 store_->SetCurrentPolicy(policies); | 224 store_->SetCurrentPolicy(policies); |
| 224 loop_.RunUntilIdle(); | 225 loop_.RunUntilIdle(); |
| 225 Mock::VerifyAndClearExpectations(&observer_); | 226 Mock::VerifyAndClearExpectations(&observer_); |
| 226 | 227 |
| 227 // Don't notify when there aren't any changes. | 228 // Don't notify when there aren't any changes. |
| 228 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 229 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
| 229 store_->SetCurrentPolicy(policies); | 230 store_->SetCurrentPolicy(policies); |
| 230 loop_.RunUntilIdle(); | 231 loop_.RunUntilIdle(); |
| 231 Mock::VerifyAndClearExpectations(&observer_); | 232 Mock::VerifyAndClearExpectations(&observer_); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace extensions | 235 } // namespace extensions |
| OLD | NEW |