Chromium Code Reviews| 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 #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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" | 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/test/test_browser_thread.h" | 13 #include "content/test/test_browser_thread.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace policy { | 17 namespace policy { |
| 18 | 18 |
| 19 class PolicyMap; | 19 class PolicyBundle; |
| 20 | 20 |
| 21 // A delegate for testing that can feed arbitrary information to the loader. | 21 // A delegate for testing that can feed arbitrary information to the loader. |
| 22 class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate { | 22 class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate { |
| 23 public: | 23 public: |
| 24 ProviderDelegateMock(); | 24 ProviderDelegateMock(); |
| 25 virtual ~ProviderDelegateMock(); | 25 virtual ~ProviderDelegateMock(); |
| 26 | 26 |
| 27 MOCK_METHOD0(Load, PolicyMap*()); | 27 // Load() returns a scoped_ptr<PolicyBundle> but it can't be mocked because |
| 28 // scoped_ptr is moveable but not copyable. This override forwards the | |
| 29 // call to MockLoad() which returns a PolicyBundle*, and returns a copy | |
| 30 // wrapped in a passed scoped_ptr. | |
| 31 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE { | |
| 32 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | |
| 33 PolicyBundle* loaded = MockLoad(); | |
| 34 if (loaded) | |
| 35 bundle->CopyFrom(*loaded); | |
|
Mattias Nissler (ping if slow)
2012/05/15 17:07:24
nit: Can we return NULL if loaded == NULL?
Joao da Silva
2012/05/16 10:25:44
Yes, it will be passed along to ConfigurationPolic
| |
| 36 return bundle.Pass(); | |
| 37 } | |
| 38 | |
| 39 MOCK_METHOD0(MockLoad, PolicyBundle*()); | |
| 28 | 40 |
| 29 private: | 41 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(ProviderDelegateMock); | 42 DISALLOW_COPY_AND_ASSIGN(ProviderDelegateMock); |
| 31 }; | 43 }; |
| 32 | 44 |
| 33 class AsynchronousPolicyTestBase : public testing::Test { | 45 class AsynchronousPolicyTestBase : public testing::Test { |
| 34 public: | 46 public: |
| 35 AsynchronousPolicyTestBase(); | 47 AsynchronousPolicyTestBase(); |
| 36 virtual ~AsynchronousPolicyTestBase(); | 48 virtual ~AsynchronousPolicyTestBase(); |
| 37 | 49 |
| 38 // testing::Test: | 50 // testing::Test: |
| 39 virtual void TearDown() OVERRIDE; | 51 virtual void TearDown() OVERRIDE; |
| 40 | 52 |
| 41 protected: | 53 protected: |
| 42 // Create an actual IO loop (needed by FilePathWatcher). | 54 // Create an actual IO loop (needed by FilePathWatcher). |
| 43 MessageLoopForIO loop_; | 55 MessageLoopForIO loop_; |
| 44 | 56 |
| 45 private: | 57 private: |
| 46 content::TestBrowserThread ui_thread_; | 58 content::TestBrowserThread ui_thread_; |
| 47 content::TestBrowserThread file_thread_; | 59 content::TestBrowserThread file_thread_; |
| 48 | 60 |
| 49 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyTestBase); | 61 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyTestBase); |
| 50 }; | 62 }; |
| 51 | 63 |
| 52 } // namespace policy | 64 } // namespace policy |
| 53 | 65 |
| 54 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_ | 66 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_ |
| OLD | NEW |