OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "chrome/browser/policy/asynchronous_policy_loader.h" | 7 #include "chrome/browser/policy/asynchronous_policy_loader.h" |
8 #include "chrome/browser/policy/asynchronous_policy_provider.h" | 8 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
9 #include "chrome/browser/policy/asynchronous_policy_test_base.h" | 9 #include "chrome/browser/policy/asynchronous_policy_test_base.h" |
10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 | 12 |
13 using ::testing::InSequence; | 13 using ::testing::InSequence; |
14 using ::testing::Mock; | 14 using ::testing::Mock; |
15 using ::testing::Return; | 15 using ::testing::Return; |
16 using ::testing::_; | 16 using ::testing::_; |
17 | 17 |
18 namespace policy { | 18 namespace policy { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 void IgnoreCallback() { | 22 void IgnoreCallback() { |
23 } | 23 } |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 class MockConfigurationPolicyObserver | 27 class MockConfigurationPolicyObserver |
28 : public ConfigurationPolicyProvider::Observer { | 28 : public ConfigurationPolicyProvider::Observer { |
29 public: | 29 public: |
30 MOCK_METHOD0(OnUpdatePolicy, void()); | 30 MOCK_METHOD1(OnUpdatePolicy, void(ConfigurationPolicyProvider*)); |
31 void OnProviderGoingAway() {} | |
32 }; | 31 }; |
33 | 32 |
34 class AsynchronousPolicyLoaderTest : public AsynchronousPolicyTestBase { | 33 class AsynchronousPolicyLoaderTest : public AsynchronousPolicyTestBase { |
35 public: | 34 public: |
36 AsynchronousPolicyLoaderTest() {} | 35 AsynchronousPolicyLoaderTest() {} |
37 virtual ~AsynchronousPolicyLoaderTest() {} | 36 virtual ~AsynchronousPolicyLoaderTest() {} |
38 | 37 |
39 virtual void SetUp() { | 38 virtual void SetUp() { |
40 AsynchronousPolicyTestBase::SetUp(); | 39 AsynchronousPolicyTestBase::SetUp(); |
41 mock_provider_.reset(new MockConfigurationPolicyProvider()); | 40 mock_provider_.reset(new MockConfigurationPolicyProvider()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 scoped_refptr<AsynchronousPolicyLoader> loader = | 127 scoped_refptr<AsynchronousPolicyLoader> loader = |
129 new AsynchronousPolicyLoader(delegate, 10); | 128 new AsynchronousPolicyLoader(delegate, 10); |
130 AsynchronousPolicyProvider provider(NULL, loader); | 129 AsynchronousPolicyProvider provider(NULL, loader); |
131 // |registrar| must be declared last so that it is destroyed first. | 130 // |registrar| must be declared last so that it is destroyed first. |
132 ConfigurationPolicyObserverRegistrar registrar; | 131 ConfigurationPolicyObserverRegistrar registrar; |
133 registrar.Init(&provider, &observer); | 132 registrar.Init(&provider, &observer); |
134 Mock::VerifyAndClearExpectations(delegate); | 133 Mock::VerifyAndClearExpectations(delegate); |
135 | 134 |
136 EXPECT_CALL(*delegate, Load()).WillOnce( | 135 EXPECT_CALL(*delegate, Load()).WillOnce( |
137 CreateSequencedTestDictionary(&dictionary_number_2)); | 136 CreateSequencedTestDictionary(&dictionary_number_2)); |
138 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); | 137 EXPECT_CALL(observer, OnUpdatePolicy(_)).Times(1); |
139 loader->Reload(true); | 138 provider.RefreshPolicies(); |
140 loop_.RunAllPending(); | 139 loop_.RunAllPending(); |
141 Mock::VerifyAndClearExpectations(delegate); | 140 Mock::VerifyAndClearExpectations(delegate); |
142 Mock::VerifyAndClearExpectations(&observer); | 141 Mock::VerifyAndClearExpectations(&observer); |
143 | 142 |
144 EXPECT_CALL(*delegate, Load()).WillOnce( | 143 EXPECT_CALL(*delegate, Load()).WillOnce( |
145 CreateSequencedTestDictionary(&dictionary_number_1)); | 144 CreateSequencedTestDictionary(&dictionary_number_1)); |
146 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); | 145 EXPECT_CALL(observer, OnUpdatePolicy(_)).Times(1); |
147 loader->Reload(true); | 146 provider.RefreshPolicies(); |
148 loop_.RunAllPending(); | 147 loop_.RunAllPending(); |
149 Mock::VerifyAndClearExpectations(delegate); | 148 Mock::VerifyAndClearExpectations(delegate); |
150 Mock::VerifyAndClearExpectations(&observer); | 149 Mock::VerifyAndClearExpectations(&observer); |
151 } | 150 } |
152 | 151 |
153 } // namespace policy | 152 } // namespace policy |
OLD | NEW |