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