| 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/async_policy_provider.h" | 5 #include "chrome/browser/policy/async_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void AsyncPolicyProviderTest::SetUp() { | 99 void AsyncPolicyProviderTest::SetUp() { |
| 100 SetPolicy(&initial_bundle_, "policy", "initial"); | 100 SetPolicy(&initial_bundle_, "policy", "initial"); |
| 101 loader_ = new MockPolicyLoader(loop_.message_loop_proxy()); | 101 loader_ = new MockPolicyLoader(loop_.message_loop_proxy()); |
| 102 EXPECT_CALL(*loader_, LastModificationTime()) | 102 EXPECT_CALL(*loader_, LastModificationTime()) |
| 103 .WillRepeatedly(Return(base::Time())); | 103 .WillRepeatedly(Return(base::Time())); |
| 104 EXPECT_CALL(*loader_, InitOnBackgroundThread()).Times(1); | 104 EXPECT_CALL(*loader_, InitOnBackgroundThread()).Times(1); |
| 105 EXPECT_CALL(*loader_, MockLoad()).WillOnce(Return(&initial_bundle_)); | 105 EXPECT_CALL(*loader_, MockLoad()).WillOnce(Return(&initial_bundle_)); |
| 106 | 106 |
| 107 provider_.reset( | 107 provider_.reset( |
| 108 new AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader>(loader_))); | 108 new AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader>(loader_))); |
| 109 // Initial load shouldn't happen until invoked. |
| 110 EXPECT_FALSE(provider_->policies().Equals(initial_bundle_)); |
| 111 |
| 112 // Now perform an initial synchronous load. |
| 113 provider_->InitialLoad(); |
| 114 EXPECT_TRUE(provider_->policies().Equals(initial_bundle_)); |
| 115 |
| 109 provider_->Init(); | 116 provider_->Init(); |
| 110 // Verify that the initial load is done synchronously: | |
| 111 EXPECT_TRUE(provider_->policies().Equals(initial_bundle_)); | |
| 112 | 117 |
| 113 loop_.RunUntilIdle(); | 118 loop_.RunUntilIdle(); |
| 114 Mock::VerifyAndClearExpectations(loader_); | 119 Mock::VerifyAndClearExpectations(loader_); |
| 115 | 120 |
| 116 EXPECT_CALL(*loader_, LastModificationTime()) | 121 EXPECT_CALL(*loader_, LastModificationTime()) |
| 117 .WillRepeatedly(Return(base::Time())); | 122 .WillRepeatedly(Return(base::Time())); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void AsyncPolicyProviderTest::TearDown() { | 125 void AsyncPolicyProviderTest::TearDown() { |
| 121 if (provider_) { | 126 if (provider_) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(0); | 222 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(0); |
| 218 provider_->Shutdown(); | 223 provider_->Shutdown(); |
| 219 loop_.RunUntilIdle(); | 224 loop_.RunUntilIdle(); |
| 220 Mock::VerifyAndClearExpectations(&observer); | 225 Mock::VerifyAndClearExpectations(&observer); |
| 221 | 226 |
| 222 provider_->RemoveObserver(&observer); | 227 provider_->RemoveObserver(&observer); |
| 223 provider_.reset(); | 228 provider_.reset(); |
| 224 } | 229 } |
| 225 | 230 |
| 226 } // namespace policy | 231 } // namespace policy |
| OLD | NEW |