| 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" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/policy/async_policy_loader.h" | 13 #include "chrome/browser/policy/async_policy_loader.h" |
| 14 #include "chrome/browser/policy/external_data_fetcher.h" | 14 #include "chrome/browser/policy/external_data_fetcher.h" |
| 15 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 15 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 16 #include "chrome/browser/policy/schema_registry.h" |
| 16 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using testing::Mock; | 21 using testing::Mock; |
| 21 using testing::Return; | 22 using testing::Return; |
| 22 using testing::Sequence; | 23 using testing::Sequence; |
| 23 | 24 |
| 24 namespace policy { | 25 namespace policy { |
| 25 | 26 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 78 |
| 78 class AsyncPolicyProviderTest : public testing::Test { | 79 class AsyncPolicyProviderTest : public testing::Test { |
| 79 protected: | 80 protected: |
| 80 AsyncPolicyProviderTest(); | 81 AsyncPolicyProviderTest(); |
| 81 virtual ~AsyncPolicyProviderTest(); | 82 virtual ~AsyncPolicyProviderTest(); |
| 82 | 83 |
| 83 virtual void SetUp() OVERRIDE; | 84 virtual void SetUp() OVERRIDE; |
| 84 virtual void TearDown() OVERRIDE; | 85 virtual void TearDown() OVERRIDE; |
| 85 | 86 |
| 86 base::MessageLoop loop_; | 87 base::MessageLoop loop_; |
| 88 SchemaRegistry schema_registry_; |
| 87 PolicyBundle initial_bundle_; | 89 PolicyBundle initial_bundle_; |
| 88 MockPolicyLoader* loader_; | 90 MockPolicyLoader* loader_; |
| 89 scoped_ptr<AsyncPolicyProvider> provider_; | 91 scoped_ptr<AsyncPolicyProvider> provider_; |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProviderTest); | 94 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProviderTest); |
| 93 }; | 95 }; |
| 94 | 96 |
| 95 AsyncPolicyProviderTest::AsyncPolicyProviderTest() {} | 97 AsyncPolicyProviderTest::AsyncPolicyProviderTest() {} |
| 96 | 98 |
| 97 AsyncPolicyProviderTest::~AsyncPolicyProviderTest() {} | 99 AsyncPolicyProviderTest::~AsyncPolicyProviderTest() {} |
| 98 | 100 |
| 99 void AsyncPolicyProviderTest::SetUp() { | 101 void AsyncPolicyProviderTest::SetUp() { |
| 100 SetPolicy(&initial_bundle_, "policy", "initial"); | 102 SetPolicy(&initial_bundle_, "policy", "initial"); |
| 101 loader_ = new MockPolicyLoader(loop_.message_loop_proxy()); | 103 loader_ = new MockPolicyLoader(loop_.message_loop_proxy()); |
| 102 EXPECT_CALL(*loader_, LastModificationTime()) | 104 EXPECT_CALL(*loader_, LastModificationTime()) |
| 103 .WillRepeatedly(Return(base::Time())); | 105 .WillRepeatedly(Return(base::Time())); |
| 104 EXPECT_CALL(*loader_, InitOnBackgroundThread()).Times(1); | 106 EXPECT_CALL(*loader_, InitOnBackgroundThread()).Times(1); |
| 105 EXPECT_CALL(*loader_, MockLoad()).WillOnce(Return(&initial_bundle_)); | 107 EXPECT_CALL(*loader_, MockLoad()).WillOnce(Return(&initial_bundle_)); |
| 106 | 108 |
| 107 provider_.reset( | 109 provider_.reset(new AsyncPolicyProvider( |
| 108 new AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader>(loader_))); | 110 &schema_registry_, scoped_ptr<AsyncPolicyLoader>(loader_))); |
| 109 provider_->Init(); | 111 provider_->Init(&schema_registry_); |
| 110 // Verify that the initial load is done synchronously: | 112 // Verify that the initial load is done synchronously: |
| 111 EXPECT_TRUE(provider_->policies().Equals(initial_bundle_)); | 113 EXPECT_TRUE(provider_->policies().Equals(initial_bundle_)); |
| 112 | 114 |
| 113 loop_.RunUntilIdle(); | 115 loop_.RunUntilIdle(); |
| 114 Mock::VerifyAndClearExpectations(loader_); | 116 Mock::VerifyAndClearExpectations(loader_); |
| 115 | 117 |
| 116 EXPECT_CALL(*loader_, LastModificationTime()) | 118 EXPECT_CALL(*loader_, LastModificationTime()) |
| 117 .WillRepeatedly(Return(base::Time())); | 119 .WillRepeatedly(Return(base::Time())); |
| 118 } | 120 } |
| 119 | 121 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(0); | 219 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(0); |
| 218 provider_->Shutdown(); | 220 provider_->Shutdown(); |
| 219 loop_.RunUntilIdle(); | 221 loop_.RunUntilIdle(); |
| 220 Mock::VerifyAndClearExpectations(&observer); | 222 Mock::VerifyAndClearExpectations(&observer); |
| 221 | 223 |
| 222 provider_->RemoveObserver(&observer); | 224 provider_->RemoveObserver(&observer); |
| 223 provider_.reset(); | 225 provider_.reset(); |
| 224 } | 226 } |
| 225 | 227 |
| 226 } // namespace policy | 228 } // namespace policy |
| OLD | NEW |