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", nullptr, value.CreateDeepCopy())); | 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.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", nullptr, value.CreateDeepCopy())); | 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.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(ValueStoreChange("bbb", value.CreateDeepCopy(), | 198 changes.push_back(ValueStoreChange("bbb", value.CreateDeepCopy(), |
199 new_value.CreateDeepCopy())); | 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.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( | 216 changes.push_back( |
216 ValueStoreChange("bbb", new_value.CreateDeepCopy(), nullptr)); | 217 ValueStoreChange("bbb", new_value.CreateDeepCopy(), nullptr)); |
217 EXPECT_CALL(observer_, | 218 EXPECT_CALL(observer_, |
218 OnSettingsChanged(kTestExtensionId, | 219 OnSettingsChanged(kTestExtensionId, |
219 settings_namespace::MANAGED, | 220 settings_namespace::MANAGED, |
220 ValueStoreChange::ToJson(changes))); | 221 ValueStoreChange::ToJson(changes))); |
221 } | 222 } |
222 | 223 |
223 policies.Erase("bbb"); | 224 policies.Erase("bbb"); |
224 store_->SetCurrentPolicy(policies); | 225 store_->SetCurrentPolicy(policies); |
225 loop_.RunUntilIdle(); | 226 loop_.RunUntilIdle(); |
226 Mock::VerifyAndClearExpectations(&observer_); | 227 Mock::VerifyAndClearExpectations(&observer_); |
227 | 228 |
228 // Don't notify when there aren't any changes. | 229 // Don't notify when there aren't any changes. |
229 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 230 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
230 store_->SetCurrentPolicy(policies); | 231 store_->SetCurrentPolicy(policies); |
231 loop_.RunUntilIdle(); | 232 loop_.RunUntilIdle(); |
232 Mock::VerifyAndClearExpectations(&observer_); | 233 Mock::VerifyAndClearExpectations(&observer_); |
233 } | 234 } |
234 | 235 |
235 } // namespace extensions | 236 } // namespace extensions |
OLD | NEW |