OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_ |
| 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/browser_thread.h" |
| 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 12 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace policy { |
| 17 |
| 18 // A delegate for testing that can feed arbitrary information to the loader. |
| 19 class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate { |
| 20 public: |
| 21 ProviderDelegateMock() : AsynchronousPolicyProvider::Delegate() {} |
| 22 virtual ~ProviderDelegateMock() {} |
| 23 |
| 24 MOCK_METHOD0(Load, DictionaryValue*()); |
| 25 |
| 26 private: |
| 27 DISALLOW_COPY_AND_ASSIGN(ProviderDelegateMock); |
| 28 }; |
| 29 |
| 30 class AsynchronousPolicyTestBase : public testing::Test { |
| 31 public: |
| 32 AsynchronousPolicyTestBase() |
| 33 : ui_thread_(BrowserThread::UI, &loop_), |
| 34 file_thread_(BrowserThread::FILE, &loop_) {} |
| 35 |
| 36 virtual ~AsynchronousPolicyTestBase() {} |
| 37 |
| 38 virtual void SetUp() { |
| 39 delegate_.reset(new ProviderDelegateMock()); |
| 40 store_.reset(new MockConfigurationPolicyStore); |
| 41 } |
| 42 |
| 43 virtual void TearDown() { |
| 44 loop_.RunAllPending(); |
| 45 } |
| 46 |
| 47 protected: |
| 48 MessageLoop loop_; |
| 49 |
| 50 // The mocks that are used in the test must outlive the scope of the test |
| 51 // because they still get accessed in the RunAllPending of the TearDown. |
| 52 scoped_ptr<MockConfigurationPolicyStore> store_; |
| 53 scoped_ptr<ProviderDelegateMock> delegate_; |
| 54 |
| 55 private: |
| 56 BrowserThread ui_thread_; |
| 57 BrowserThread file_thread_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyTestBase); |
| 60 }; |
| 61 |
| 62 } // namespace policy |
| 63 |
| 64 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_ |
OLD | NEW |