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 | |
28 : public ConfigurationPolicyProvider::Observer { | |
29 public: | |
30 MOCK_METHOD0(OnUpdatePolicy, void()); | |
31 void OnProviderGoingAway() {} | |
32 }; | |
33 | |
34 class AsynchronousPolicyLoaderTest : public AsynchronousPolicyTestBase { | 27 class AsynchronousPolicyLoaderTest : public AsynchronousPolicyTestBase { |
35 public: | 28 public: |
36 AsynchronousPolicyLoaderTest() {} | 29 AsynchronousPolicyLoaderTest() {} |
37 virtual ~AsynchronousPolicyLoaderTest() {} | 30 virtual ~AsynchronousPolicyLoaderTest() {} |
38 | 31 |
39 virtual void SetUp() { | 32 virtual void SetUp() { |
40 AsynchronousPolicyTestBase::SetUp(); | 33 AsynchronousPolicyTestBase::SetUp(); |
41 mock_provider_.reset(new MockConfigurationPolicyProvider()); | 34 mock_provider_.reset(new MockConfigurationPolicyProvider()); |
42 ignore_callback_ = base::Bind(&IgnoreCallback); | 35 ignore_callback_ = base::Bind(&IgnoreCallback); |
43 } | 36 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 scoped_refptr<AsynchronousPolicyLoader> loader = | 121 scoped_refptr<AsynchronousPolicyLoader> loader = |
129 new AsynchronousPolicyLoader(delegate, 10); | 122 new AsynchronousPolicyLoader(delegate, 10); |
130 AsynchronousPolicyProvider provider(NULL, loader); | 123 AsynchronousPolicyProvider provider(NULL, loader); |
131 // |registrar| must be declared last so that it is destroyed first. | 124 // |registrar| must be declared last so that it is destroyed first. |
132 ConfigurationPolicyObserverRegistrar registrar; | 125 ConfigurationPolicyObserverRegistrar registrar; |
133 registrar.Init(&provider, &observer); | 126 registrar.Init(&provider, &observer); |
134 Mock::VerifyAndClearExpectations(delegate); | 127 Mock::VerifyAndClearExpectations(delegate); |
135 | 128 |
136 EXPECT_CALL(*delegate, Load()).WillOnce( | 129 EXPECT_CALL(*delegate, Load()).WillOnce( |
137 CreateSequencedTestDictionary(&dictionary_number_2)); | 130 CreateSequencedTestDictionary(&dictionary_number_2)); |
138 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); | 131 EXPECT_CALL(observer, OnUpdatePolicy(_)).Times(1); |
139 loader->Reload(true); | 132 provider.RefreshPolicies(); |
140 loop_.RunAllPending(); | 133 loop_.RunAllPending(); |
141 Mock::VerifyAndClearExpectations(delegate); | 134 Mock::VerifyAndClearExpectations(delegate); |
142 Mock::VerifyAndClearExpectations(&observer); | 135 Mock::VerifyAndClearExpectations(&observer); |
143 | 136 |
144 EXPECT_CALL(*delegate, Load()).WillOnce( | 137 EXPECT_CALL(*delegate, Load()).WillOnce( |
145 CreateSequencedTestDictionary(&dictionary_number_1)); | 138 CreateSequencedTestDictionary(&dictionary_number_1)); |
146 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); | 139 EXPECT_CALL(observer, OnUpdatePolicy(_)).Times(1); |
147 loader->Reload(true); | 140 provider.RefreshPolicies(); |
148 loop_.RunAllPending(); | 141 loop_.RunAllPending(); |
149 Mock::VerifyAndClearExpectations(delegate); | 142 Mock::VerifyAndClearExpectations(delegate); |
150 Mock::VerifyAndClearExpectations(&observer); | 143 Mock::VerifyAndClearExpectations(&observer); |
151 } | 144 } |
152 | 145 |
153 } // namespace policy | 146 } // namespace policy |
OLD | NEW |