| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 keys.push_back("key"); | 154 keys.push_back("key"); |
| 155 EXPECT_FALSE(store_->Remove(keys)->status().ok()); | 155 EXPECT_FALSE(store_->Remove(keys)->status().ok()); |
| 156 EXPECT_FALSE(store_->Clear()->status().ok()); | 156 EXPECT_FALSE(store_->Clear()->status().ok()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 TEST_F(PolicyValueStoreTest, NotifyOnChanges) { | 159 TEST_F(PolicyValueStoreTest, NotifyOnChanges) { |
| 160 // Notify when setting the initial policy. | 160 // Notify when setting the initial policy. |
| 161 const base::StringValue value("111"); | 161 const base::StringValue value("111"); |
| 162 { | 162 { |
| 163 ValueStoreChangeList changes; | 163 ValueStoreChangeList changes; |
| 164 changes.push_back(ValueStoreChange("aaa", NULL, value.DeepCopy())); | 164 changes.push_back(ValueStoreChange("aaa", nullptr, value.CreateDeepCopy())); |
| 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.DeepCopy(), 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", nullptr, value.CreateDeepCopy())); |
| 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.DeepCopy(), 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(ValueStoreChange("bbb", value.CreateDeepCopy(), |
| 199 ValueStoreChange("bbb", value.DeepCopy(), new_value.DeepCopy())); | 199 new_value.CreateDeepCopy())); |
| 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.DeepCopy(), nullptr); |
| 208 store_->SetCurrentPolicy(policies); | 208 store_->SetCurrentPolicy(policies); |
| 209 loop_.RunUntilIdle(); | 209 loop_.RunUntilIdle(); |
| 210 Mock::VerifyAndClearExpectations(&observer_); | 210 Mock::VerifyAndClearExpectations(&observer_); |
| 211 | 211 |
| 212 // Notify when policies are removed. | 212 // Notify when policies are removed. |
| 213 { | 213 { |
| 214 ValueStoreChangeList changes; | 214 ValueStoreChangeList changes; |
| 215 changes.push_back(ValueStoreChange("bbb", new_value.DeepCopy(), NULL)); | 215 changes.push_back( |
| 216 ValueStoreChange("bbb", new_value.CreateDeepCopy(), nullptr)); |
| 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 |