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/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
14 #include "base/values.h" | 13 #include "base/values.h" |
15 #include "chrome/browser/policy/external_data_fetcher.h" | 14 #include "chrome/browser/policy/external_data_fetcher.h" |
16 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 15 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
17 #include "chrome/browser/policy/policy_domain_descriptor.h" | 16 #include "chrome/browser/policy/policy_domain_descriptor.h" |
18 #include "chrome/browser/policy/policy_schema.h" | 17 #include "chrome/browser/policy/policy_schema.h" |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
23 | 22 |
24 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
25 using ::testing::Mock; | 24 using ::testing::Mock; |
26 using ::testing::Return; | 25 using ::testing::Return; |
27 using ::testing::_; | 26 using ::testing::_; |
28 | 27 |
29 namespace policy { | 28 namespace policy { |
30 | 29 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 155 } |
157 | 156 |
158 protected: | 157 protected: |
159 MockConfigurationPolicyProvider provider0_; | 158 MockConfigurationPolicyProvider provider0_; |
160 MockConfigurationPolicyProvider provider1_; | 159 MockConfigurationPolicyProvider provider1_; |
161 MockConfigurationPolicyProvider provider2_; | 160 MockConfigurationPolicyProvider provider2_; |
162 PolicyMap policy0_; | 161 PolicyMap policy0_; |
163 PolicyMap policy1_; | 162 PolicyMap policy1_; |
164 PolicyMap policy2_; | 163 PolicyMap policy2_; |
165 scoped_ptr<PolicyServiceImpl> policy_service_; | 164 scoped_ptr<PolicyServiceImpl> policy_service_; |
166 base::MessageLoop loop_; | 165 content::TestBrowserThreadBundle thread_bundle_; |
167 | 166 |
168 private: | 167 private: |
169 DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest); | 168 DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest); |
170 }; | 169 }; |
171 | 170 |
172 TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { | 171 TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { |
173 PolicyMap expected; | 172 PolicyMap expected; |
174 expected.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 173 expected.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
175 base::Value::CreateIntegerValue(13), NULL); | 174 base::Value::CreateIntegerValue(13), NULL); |
176 EXPECT_TRUE(VerifyPolicies( | 175 EXPECT_TRUE(VerifyPolicies( |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 registrar.reset(); | 436 registrar.reset(); |
438 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 437 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
439 kValue1.DeepCopy(), NULL); | 438 kValue1.DeepCopy(), NULL); |
440 policy0_.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 439 policy0_.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
441 kValue1.DeepCopy(), NULL); | 440 kValue1.DeepCopy(), NULL); |
442 UpdateProviderPolicy(policy0_); | 441 UpdateProviderPolicy(policy0_); |
443 Mock::VerifyAndClearExpectations(this); | 442 Mock::VerifyAndClearExpectations(this); |
444 } | 443 } |
445 | 444 |
446 TEST_F(PolicyServiceTest, RefreshPolicies) { | 445 TEST_F(PolicyServiceTest, RefreshPolicies) { |
447 content::TestBrowserThread ui_thread(content::BrowserThread::UI, &loop_); | |
448 content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop_); | |
449 content::TestBrowserThread io_thread(content::BrowserThread::IO, &loop_); | |
450 | |
451 EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber()); | 446 EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber()); |
452 EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber()); | 447 EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber()); |
453 EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber()); | 448 EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber()); |
454 | 449 |
455 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 450 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
456 policy_service_->RefreshPolicies(base::Bind( | 451 policy_service_->RefreshPolicies(base::Bind( |
457 &PolicyServiceTest::OnPolicyRefresh, | 452 &PolicyServiceTest::OnPolicyRefresh, |
458 base::Unretained(this))); | 453 base::Unretained(this))); |
459 // Let any queued observer tasks run. | 454 // Let any queued observer tasks run. |
460 RunUntilIdle(); | 455 RunUntilIdle(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 scoped_refptr<PolicyDomainDescriptor> empty_extensions_descriptor = | 680 scoped_refptr<PolicyDomainDescriptor> empty_extensions_descriptor = |
686 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); | 681 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); |
687 EXPECT_CALL(provider0_, RegisterPolicyDomain( | 682 EXPECT_CALL(provider0_, RegisterPolicyDomain( |
688 scoped_refptr<const PolicyDomainDescriptor>( | 683 scoped_refptr<const PolicyDomainDescriptor>( |
689 empty_extensions_descriptor))); | 684 empty_extensions_descriptor))); |
690 policy_service_->RegisterPolicyDomain(empty_extensions_descriptor); | 685 policy_service_->RegisterPolicyDomain(empty_extensions_descriptor); |
691 Mock::VerifyAndClearExpectations(&provider0_); | 686 Mock::VerifyAndClearExpectations(&provider0_); |
692 } | 687 } |
693 | 688 |
694 } // namespace policy | 689 } // namespace policy |
OLD | NEW |