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