| OLD | NEW |
| (Empty) |
| 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 | |
| 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/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/test/test_browser_thread.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace policy { | |
| 18 | |
| 19 class PolicyBundle; | |
| 20 | |
| 21 // A delegate for testing that can feed arbitrary information to the loader. | |
| 22 class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate { | |
| 23 public: | |
| 24 ProviderDelegateMock(); | |
| 25 virtual ~ProviderDelegateMock(); | |
| 26 | |
| 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; | |
| 33 PolicyBundle* loaded = MockLoad(); | |
| 34 if (loaded) { | |
| 35 bundle.reset(new PolicyBundle()); | |
| 36 bundle->CopyFrom(*loaded); | |
| 37 } | |
| 38 return bundle.Pass(); | |
| 39 } | |
| 40 | |
| 41 MOCK_METHOD0(MockLoad, PolicyBundle*()); | |
| 42 | |
| 43 private: | |
| 44 DISALLOW_COPY_AND_ASSIGN(ProviderDelegateMock); | |
| 45 }; | |
| 46 | |
| 47 class AsynchronousPolicyTestBase : public testing::Test { | |
| 48 public: | |
| 49 AsynchronousPolicyTestBase(); | |
| 50 virtual ~AsynchronousPolicyTestBase(); | |
| 51 | |
| 52 // testing::Test: | |
| 53 virtual void TearDown() OVERRIDE; | |
| 54 | |
| 55 protected: | |
| 56 // Create an actual IO loop (needed by FilePathWatcher). | |
| 57 MessageLoopForIO loop_; | |
| 58 | |
| 59 private: | |
| 60 content::TestBrowserThread ui_thread_; | |
| 61 content::TestBrowserThread file_thread_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyTestBase); | |
| 64 }; | |
| 65 | |
| 66 } // namespace policy | |
| 67 | |
| 68 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_ | |
| OLD | NEW |