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/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/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/policy_domain_descriptor.h" |
| 16 #include "chrome/browser/policy/policy_schema.h" |
14 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
18 | 21 |
19 using ::testing::AnyNumber; | 22 using ::testing::AnyNumber; |
20 using ::testing::Mock; | 23 using ::testing::Mock; |
21 using ::testing::Return; | 24 using ::testing::Return; |
22 using ::testing::_; | 25 using ::testing::_; |
23 | 26 |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 EXPECT_TRUE(policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 623 EXPECT_TRUE(policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
621 EXPECT_TRUE( | 624 EXPECT_TRUE( |
622 policy_service_->IsInitializationComplete(POLICY_DOMAIN_EXTENSIONS)); | 625 policy_service_->IsInitializationComplete(POLICY_DOMAIN_EXTENSIONS)); |
623 | 626 |
624 // Cleanup. | 627 // Cleanup. |
625 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); | 628 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); |
626 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, &observer); | 629 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, &observer); |
627 } | 630 } |
628 | 631 |
629 TEST_F(PolicyServiceTest, RegisterPolicyDomain) { | 632 TEST_F(PolicyServiceTest, RegisterPolicyDomain) { |
630 EXPECT_CALL(provider1_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); | 633 EXPECT_CALL(provider1_, RegisterPolicyDomain(_)).Times(AnyNumber()); |
631 EXPECT_CALL(provider2_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); | 634 EXPECT_CALL(provider2_, RegisterPolicyDomain(_)).Times(AnyNumber()); |
632 | 635 |
633 const std::set<std::string> empty_set; | 636 scoped_refptr<const PolicyDomainDescriptor> chrome_descriptor = |
634 EXPECT_CALL(provider0_, | 637 new PolicyDomainDescriptor(POLICY_DOMAIN_CHROME); |
635 RegisterPolicyDomain(POLICY_DOMAIN_CHROME, empty_set)); | 638 EXPECT_CALL(provider0_, RegisterPolicyDomain(chrome_descriptor)); |
636 policy_service_->RegisterPolicyDomain(POLICY_DOMAIN_CHROME, empty_set); | 639 policy_service_->RegisterPolicyDomain(chrome_descriptor); |
637 Mock::VerifyAndClearExpectations(&provider0_); | 640 Mock::VerifyAndClearExpectations(&provider0_); |
638 | 641 |
639 // Register another namespace. | 642 // Register another namespace. |
640 std::set<std::string> extensions; | 643 std::string error; |
641 extensions.insert(kExtension); | 644 scoped_ptr<PolicySchema> schema = PolicySchema::Parse( |
642 EXPECT_CALL(provider0_, | 645 "{" |
643 RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, extensions)); | 646 " \"$schema\":\"http://json-schema.org/draft-03/schema#\"," |
644 policy_service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, extensions); | 647 " \"type\":\"object\"," |
| 648 " \"properties\": {" |
| 649 " \"Boolean\": { \"type\": \"boolean\" }," |
| 650 " \"Integer\": { \"type\": \"integer\" }," |
| 651 " \"Null\": { \"type\": \"null\" }," |
| 652 " \"Number\": { \"type\": \"number\" }," |
| 653 " \"Object\": { \"type\": \"object\" }," |
| 654 " \"String\": { \"type\": \"string\" }" |
| 655 " }" |
| 656 "}", &error); |
| 657 ASSERT_TRUE(schema); |
| 658 scoped_refptr<PolicyDomainDescriptor> extensions_descriptor = |
| 659 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); |
| 660 extensions_descriptor->RegisterComponent(kExtension, schema.Pass()); |
| 661 EXPECT_CALL(provider0_, RegisterPolicyDomain( |
| 662 scoped_refptr<const PolicyDomainDescriptor>(extensions_descriptor))); |
| 663 policy_service_->RegisterPolicyDomain(extensions_descriptor); |
645 Mock::VerifyAndClearExpectations(&provider0_); | 664 Mock::VerifyAndClearExpectations(&provider0_); |
646 | 665 |
647 // Remove those components. | 666 // Remove those components. |
648 EXPECT_CALL(provider0_, | 667 scoped_refptr<PolicyDomainDescriptor> empty_extensions_descriptor = |
649 RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, empty_set)); | 668 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); |
650 policy_service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, empty_set); | 669 EXPECT_CALL(provider0_, RegisterPolicyDomain( |
| 670 scoped_refptr<const PolicyDomainDescriptor>( |
| 671 empty_extensions_descriptor))); |
| 672 policy_service_->RegisterPolicyDomain(empty_extensions_descriptor); |
651 Mock::VerifyAndClearExpectations(&provider0_); | 673 Mock::VerifyAndClearExpectations(&provider0_); |
652 } | 674 } |
653 | 675 |
654 } // namespace policy | 676 } // namespace policy |
OLD | NEW |