Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: components/policy/core/common/cloud/component_cloud_policy_service_unittest.cc

Issue 2231753002: components: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more call site Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/policy/core/common/cloud/component_cloud_policy_service.h" 5 #include "components/policy/core/common/cloud/component_cloud_policy_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 RunUntilIdle(); 387 RunUntilIdle();
388 Mock::VerifyAndClearExpectations(&delegate_); 388 Mock::VerifyAndClearExpectations(&delegate_);
389 389
390 ns.component_id = kTestExtension; 390 ns.component_id = kTestExtension;
391 expected_bundle.Get(ns).Clear(); 391 expected_bundle.Get(ns).Clear();
392 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); 392 EXPECT_TRUE(service_->policy().Equals(expected_bundle));
393 393
394 std::map<std::string, std::string> contents; 394 std::map<std::string, std::string> contents;
395 cache_->LoadAllSubkeys("extension-policy", &contents); 395 cache_->LoadAllSubkeys("extension-policy", &contents);
396 EXPECT_EQ(1u, contents.size()); 396 EXPECT_EQ(1u, contents.size());
397 EXPECT_TRUE(ContainsKey(contents, kTestExtension2)); 397 EXPECT_TRUE(base::ContainsKey(contents, kTestExtension2));
398 } 398 }
399 399
400 TEST_F(ComponentCloudPolicyServiceTest, SignInAfterStartup) { 400 TEST_F(ComponentCloudPolicyServiceTest, SignInAfterStartup) {
401 registry_.SetReady(POLICY_DOMAIN_CHROME); 401 registry_.SetReady(POLICY_DOMAIN_CHROME);
402 registry_.SetReady(POLICY_DOMAIN_EXTENSIONS); 402 registry_.SetReady(POLICY_DOMAIN_EXTENSIONS);
403 403
404 // Initialize the store without credentials. 404 // Initialize the store without credentials.
405 EXPECT_FALSE(store_.is_initialized()); 405 EXPECT_FALSE(store_.is_initialized());
406 store_.NotifyStoreLoaded(); 406 store_.NotifyStoreLoaded();
407 RunUntilIdle(); 407 RunUntilIdle();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 Mock::VerifyAndClearExpectations(client_); 531 Mock::VerifyAndClearExpectations(client_);
532 Mock::VerifyAndClearExpectations(&delegate_); 532 Mock::VerifyAndClearExpectations(&delegate_);
533 533
534 EXPECT_TRUE(service_->is_initialized()); 534 EXPECT_TRUE(service_->is_initialized());
535 EXPECT_EQ(2u, client_->types_to_fetch_.size()); 535 EXPECT_EQ(2u, client_->types_to_fetch_.size());
536 536
537 // Verify that policy for 2 extensions has been loaded from the cache. 537 // Verify that policy for 2 extensions has been loaded from the cache.
538 std::map<std::string, std::string> contents; 538 std::map<std::string, std::string> contents;
539 cache_->LoadAllSubkeys("extension-policy", &contents); 539 cache_->LoadAllSubkeys("extension-policy", &contents);
540 ASSERT_EQ(2u, contents.size()); 540 ASSERT_EQ(2u, contents.size());
541 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); 541 EXPECT_TRUE(base::ContainsKey(contents, kTestExtension));
542 EXPECT_TRUE(ContainsKey(contents, kTestExtension2)); 542 EXPECT_TRUE(base::ContainsKey(contents, kTestExtension2));
543 543
544 PolicyBundle expected_bundle; 544 PolicyBundle expected_bundle;
545 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); 545 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension);
546 expected_bundle.Get(ns).CopyFrom(expected_policy_); 546 expected_bundle.Get(ns).CopyFrom(expected_policy_);
547 const PolicyNamespace ns2(POLICY_DOMAIN_EXTENSIONS, kTestExtension2); 547 const PolicyNamespace ns2(POLICY_DOMAIN_EXTENSIONS, kTestExtension2);
548 expected_bundle.Get(ns2).CopyFrom(expected_policy_); 548 expected_bundle.Get(ns2).CopyFrom(expected_policy_);
549 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); 549 EXPECT_TRUE(service_->policy().Equals(expected_bundle));
550 550
551 // Receive an updated fetch response from the server. There is no response for 551 // Receive an updated fetch response from the server. There is no response for
552 // extension 2, so it will be dropped from the cache. This triggers an 552 // extension 2, so it will be dropped from the cache. This triggers an
553 // immediate notification to the delegate. 553 // immediate notification to the delegate.
554 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); 554 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated());
555 client_->SetPolicy(dm_protocol::kChromeExtensionPolicyType, kTestExtension, 555 client_->SetPolicy(dm_protocol::kChromeExtensionPolicyType, kTestExtension,
556 *CreateResponse()); 556 *CreateResponse());
557 service_->OnPolicyFetched(client_); 557 service_->OnPolicyFetched(client_);
558 RunUntilIdle(); 558 RunUntilIdle();
559 Mock::VerifyAndClearExpectations(&delegate_); 559 Mock::VerifyAndClearExpectations(&delegate_);
560 560
561 // That should have triggered the download fetch for the first extension. 561 // That should have triggered the download fetch for the first extension.
562 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 562 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
563 ASSERT_TRUE(fetcher); 563 ASSERT_TRUE(fetcher);
564 564
565 // The cache should have dropped the entries for the second extension. 565 // The cache should have dropped the entries for the second extension.
566 contents.clear(); 566 contents.clear();
567 cache_->LoadAllSubkeys("extension-policy", &contents); 567 cache_->LoadAllSubkeys("extension-policy", &contents);
568 ASSERT_EQ(1u, contents.size()); 568 ASSERT_EQ(1u, contents.size());
569 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); 569 EXPECT_TRUE(base::ContainsKey(contents, kTestExtension));
570 EXPECT_FALSE(ContainsKey(contents, kTestExtension2)); 570 EXPECT_FALSE(base::ContainsKey(contents, kTestExtension2));
571 571
572 // And the service isn't publishing policy for the second extension anymore. 572 // And the service isn't publishing policy for the second extension anymore.
573 expected_bundle.Clear(); 573 expected_bundle.Clear();
574 expected_bundle.Get(ns).CopyFrom(expected_policy_); 574 expected_bundle.Get(ns).CopyFrom(expected_policy_);
575 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); 575 EXPECT_TRUE(service_->policy().Equals(expected_bundle));
576 } 576 }
577 577
578 } // namespace policy 578 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698