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

Side by Side Diff: chrome/browser/policy/policy_service_impl_unittest.cc

Issue 56623005: Policy providers all get a SchemaRegistry to work with. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-9-purge-with-callback
Patch Set: rebase Created 7 years, 1 month 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) 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/policy/policy_service_impl.h" 5 #include "chrome/browser/policy/policy_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
12 #include "base/run_loop.h" 11 #include "base/run_loop.h"
13 #include "base/values.h" 12 #include "base/values.h"
14 #include "chrome/browser/policy/external_data_fetcher.h" 13 #include "chrome/browser/policy/external_data_fetcher.h"
15 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
16 #include "chrome/browser/policy/mock_policy_service.h" 15 #include "chrome/browser/policy/mock_policy_service.h"
17 #include "chrome/browser/policy/policy_domain_descriptor.h"
18 #include "components/policy/core/common/schema.h"
19 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
21 18
22 using ::testing::AnyNumber; 19 using ::testing::AnyNumber;
23 using ::testing::Mock; 20 using ::testing::Mock;
24 using ::testing::Return; 21 using ::testing::Return;
25 using ::testing::_; 22 using ::testing::_;
26 23
27 namespace policy { 24 namespace policy {
28 25
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 Mock::VerifyAndClearExpectations(&observer); 595 Mock::VerifyAndClearExpectations(&observer);
599 EXPECT_TRUE(policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 596 EXPECT_TRUE(policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
600 EXPECT_TRUE( 597 EXPECT_TRUE(
601 policy_service_->IsInitializationComplete(POLICY_DOMAIN_EXTENSIONS)); 598 policy_service_->IsInitializationComplete(POLICY_DOMAIN_EXTENSIONS));
602 599
603 // Cleanup. 600 // Cleanup.
604 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); 601 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer);
605 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, &observer); 602 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, &observer);
606 } 603 }
607 604
608 TEST_F(PolicyServiceTest, RegisterPolicyDomain) {
609 EXPECT_FALSE(policy_service_->GetPolicyDomainDescriptor(POLICY_DOMAIN_CHROME)
610 .get());
611 EXPECT_FALSE(policy_service_->GetPolicyDomainDescriptor(
612 POLICY_DOMAIN_EXTENSIONS).get());
613
614 EXPECT_CALL(provider1_, RegisterPolicyDomain(_)).Times(AnyNumber());
615 EXPECT_CALL(provider2_, RegisterPolicyDomain(_)).Times(AnyNumber());
616
617 scoped_refptr<const PolicyDomainDescriptor> chrome_descriptor =
618 new PolicyDomainDescriptor(POLICY_DOMAIN_CHROME);
619 EXPECT_CALL(provider0_, RegisterPolicyDomain(chrome_descriptor));
620 policy_service_->RegisterPolicyDomain(chrome_descriptor);
621 Mock::VerifyAndClearExpectations(&provider0_);
622
623 EXPECT_TRUE(policy_service_->GetPolicyDomainDescriptor(POLICY_DOMAIN_CHROME)
624 .get());
625 EXPECT_FALSE(policy_service_->GetPolicyDomainDescriptor(
626 POLICY_DOMAIN_EXTENSIONS).get());
627
628 // Register another namespace.
629 std::string error;
630 Schema schema = Schema::Parse(
631 "{"
632 " \"type\":\"object\","
633 " \"properties\": {"
634 " \"Boolean\": { \"type\": \"boolean\" },"
635 " \"Integer\": { \"type\": \"integer\" },"
636 " \"Null\": { \"type\": \"null\" },"
637 " \"Number\": { \"type\": \"number\" },"
638 " \"Object\": { \"type\": \"object\" },"
639 " \"String\": { \"type\": \"string\" }"
640 " }"
641 "}", &error);
642 ASSERT_TRUE(schema.valid()) << error;
643 scoped_refptr<PolicyDomainDescriptor> extensions_descriptor =
644 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS);
645 extensions_descriptor->RegisterComponent(kExtension, schema);
646 EXPECT_CALL(provider0_, RegisterPolicyDomain(
647 scoped_refptr<const PolicyDomainDescriptor>(extensions_descriptor)));
648 policy_service_->RegisterPolicyDomain(extensions_descriptor);
649 Mock::VerifyAndClearExpectations(&provider0_);
650
651 EXPECT_TRUE(policy_service_->GetPolicyDomainDescriptor(POLICY_DOMAIN_CHROME)
652 .get());
653 EXPECT_TRUE(policy_service_->GetPolicyDomainDescriptor(
654 POLICY_DOMAIN_EXTENSIONS).get());
655
656 // Remove those components.
657 scoped_refptr<PolicyDomainDescriptor> empty_extensions_descriptor =
658 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS);
659 EXPECT_CALL(provider0_, RegisterPolicyDomain(
660 scoped_refptr<const PolicyDomainDescriptor>(
661 empty_extensions_descriptor)));
662 policy_service_->RegisterPolicyDomain(empty_extensions_descriptor);
663 Mock::VerifyAndClearExpectations(&provider0_);
664 }
665
666 } // namespace policy 605 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_service_impl.cc ('k') | chrome/browser/policy/policy_service_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698