OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/component_cloud_policy_store.h" | 5 #include "chrome/browser/policy/cloud/component_cloud_policy_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/sha1.h" | 15 #include "base/sha1.h" |
16 #include "base/test/test_simple_task_runner.h" | 16 #include "base/test/test_simple_task_runner.h" |
17 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 17 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
18 #include "chrome/browser/policy/cloud/policy_builder.h" | 18 #include "chrome/browser/policy/cloud/policy_builder.h" |
19 #include "chrome/browser/policy/cloud/resource_cache.h" | 19 #include "chrome/browser/policy/cloud/resource_cache.h" |
20 #include "chrome/browser/policy/external_data_fetcher.h" | 20 #include "chrome/browser/policy/external_data_fetcher.h" |
21 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" | 21 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
41 " \"Second\": {" | 41 " \"Second\": {" |
42 " \"Value\": \"maybe\"," | 42 " \"Value\": \"maybe\"," |
43 " \"Level\": \"Recommended\"" | 43 " \"Level\": \"Recommended\"" |
44 " }" | 44 " }" |
45 "}"; | 45 "}"; |
46 | 46 |
47 std::string TestPolicyHash() { | 47 std::string TestPolicyHash() { |
48 return base::SHA1HashString(kTestPolicy); | 48 return base::SHA1HashString(kTestPolicy); |
49 } | 49 } |
50 | 50 |
51 bool NotEquals(const std::string& expected, const std::string& key) { | |
bartfab (slow)
2013/11/05 15:53:04
Nit: s/Equals/Equal/ (x.Equals(y) reads like prope
Joao da Silva
2013/11/07 13:15:00
Done.
| |
52 return key != expected; | |
53 } | |
54 | |
51 class MockComponentCloudPolicyStoreDelegate | 55 class MockComponentCloudPolicyStoreDelegate |
52 : public ComponentCloudPolicyStore::Delegate { | 56 : public ComponentCloudPolicyStore::Delegate { |
53 public: | 57 public: |
54 virtual ~MockComponentCloudPolicyStoreDelegate() {} | 58 virtual ~MockComponentCloudPolicyStoreDelegate() {} |
55 | 59 |
56 MOCK_METHOD0(OnComponentCloudPolicyStoreUpdated, void()); | 60 MOCK_METHOD0(OnComponentCloudPolicyStoreUpdated, void()); |
57 }; | 61 }; |
58 | 62 |
59 } // namespace | 63 } // namespace |
60 | 64 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 TEST_F(ComponentCloudPolicyStoreTest, Purge) { | 279 TEST_F(ComponentCloudPolicyStoreTest, Purge) { |
276 // Store a valid policy. | 280 // Store a valid policy. |
277 EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated()); | 281 EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated()); |
278 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); | 282 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
279 EXPECT_TRUE(store_->Store( | 283 EXPECT_TRUE(store_->Store( |
280 ns, CreateSerializedResponse(), TestPolicyHash(), kTestPolicy)); | 284 ns, CreateSerializedResponse(), TestPolicyHash(), kTestPolicy)); |
281 Mock::VerifyAndClearExpectations(&store_delegate_); | 285 Mock::VerifyAndClearExpectations(&store_delegate_); |
282 EXPECT_FALSE(IsEmpty()); | 286 EXPECT_FALSE(IsEmpty()); |
283 EXPECT_TRUE(store_->policy().Equals(expected_bundle_)); | 287 EXPECT_TRUE(store_->policy().Equals(expected_bundle_)); |
284 | 288 |
285 // Purge other namespaces. | 289 // Purge other components. |
286 std::set<std::string> keep; | 290 store_->Purge(POLICY_DOMAIN_EXTENSIONS, |
287 keep.insert(kTestExtension); | 291 base::Bind(&NotEquals, kTestExtension)); |
288 store_->Purge(POLICY_DOMAIN_EXTENSIONS, keep); | |
289 | 292 |
290 // The policy for |ns| is still served. | 293 // The policy for |ns| is still served. |
291 EXPECT_TRUE(store_->policy().Equals(expected_bundle_)); | 294 EXPECT_TRUE(store_->policy().Equals(expected_bundle_)); |
292 | 295 |
293 // Loading the store again will still see |ns|. | 296 // Loading the store again will still see |ns|. |
294 ComponentCloudPolicyStore another_store(&store_delegate_, cache_.get()); | 297 ComponentCloudPolicyStore another_store(&store_delegate_, cache_.get()); |
295 const PolicyBundle empty_bundle; | 298 const PolicyBundle empty_bundle; |
296 EXPECT_TRUE(another_store.policy().Equals(empty_bundle)); | 299 EXPECT_TRUE(another_store.policy().Equals(empty_bundle)); |
297 another_store.SetCredentials(ComponentPolicyBuilder::kFakeUsername, | 300 another_store.SetCredentials(ComponentPolicyBuilder::kFakeUsername, |
298 ComponentPolicyBuilder::kFakeToken); | 301 ComponentPolicyBuilder::kFakeToken); |
299 another_store.Load(); | 302 another_store.Load(); |
300 EXPECT_TRUE(another_store.policy().Equals(expected_bundle_)); | 303 EXPECT_TRUE(another_store.policy().Equals(expected_bundle_)); |
301 | 304 |
302 // Now purge everything. | 305 // Now purge everything. |
303 EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated()); | 306 EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated()); |
304 keep.clear(); | 307 store_->Purge(POLICY_DOMAIN_EXTENSIONS, base::Bind(&NotEquals, "obsolete")); |
bartfab (slow)
2013/11/05 15:53:04
The fact that "obsolete" does not match any of the
Joao da Silva
2013/11/07 13:15:00
Done.
| |
305 store_->Purge(POLICY_DOMAIN_EXTENSIONS, keep); | |
306 Mock::VerifyAndClearExpectations(&store_delegate_); | 308 Mock::VerifyAndClearExpectations(&store_delegate_); |
307 | 309 |
308 // No policies are served anymore. | 310 // No policies are served anymore. |
309 EXPECT_TRUE(store_->policy().Equals(empty_bundle)); | 311 EXPECT_TRUE(store_->policy().Equals(empty_bundle)); |
310 | 312 |
311 // And they aren't loaded anymore either. | 313 // And they aren't loaded anymore either. |
312 ComponentCloudPolicyStore yet_another_store(&store_delegate_, cache_.get()); | 314 ComponentCloudPolicyStore yet_another_store(&store_delegate_, cache_.get()); |
313 yet_another_store.SetCredentials(ComponentPolicyBuilder::kFakeUsername, | 315 yet_another_store.SetCredentials(ComponentPolicyBuilder::kFakeUsername, |
314 ComponentPolicyBuilder::kFakeToken); | 316 ComponentPolicyBuilder::kFakeToken); |
315 yet_another_store.Load(); | 317 yet_another_store.Load(); |
316 EXPECT_TRUE(yet_another_store.policy().Equals(empty_bundle)); | 318 EXPECT_TRUE(yet_another_store.policy().Equals(empty_bundle)); |
317 } | 319 } |
318 | 320 |
319 } // namespace policy | 321 } // namespace policy |
OLD | NEW |