OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" |
| 15 #include "content/test/test_browser_thread.h" |
| 16 #include "policy/configuration_policy_type.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace base { |
| 20 class ListValue; |
| 21 } |
| 22 |
| 23 namespace policy { |
| 24 |
| 25 class AsynchronousPolicyProvider; |
| 26 struct PolicyDefinitionList; |
| 27 |
| 28 // A stripped-down policy definition list that contains entries for the |
| 29 // different policy setting types supported. |
| 30 namespace test_policy_definitions { |
| 31 |
| 32 // String policy keys. |
| 33 extern const char kKeyString[]; |
| 34 extern const char kKeyBoolean[]; |
| 35 extern const char kKeyInteger[]; |
| 36 extern const char kKeyStringList[]; |
| 37 |
| 38 // Corresponding type constants. |
| 39 extern const ConfigurationPolicyType kPolicyString; |
| 40 extern const ConfigurationPolicyType kPolicyBoolean; |
| 41 extern const ConfigurationPolicyType kPolicyInteger; |
| 42 extern const ConfigurationPolicyType kPolicyStringList; |
| 43 |
| 44 // Policy definition list that contains entries for the keys above. |
| 45 extern const PolicyDefinitionList kList; |
| 46 |
| 47 } // namespace test_policy_definitions |
| 48 |
| 49 // An interface for creating a test policy provider and creating a policy |
| 50 // provider instance for testing. Used as the parameter to the abstract |
| 51 // ConfigurationPolicyProviderTest below. |
| 52 class PolicyProviderTestHarness { |
| 53 public: |
| 54 PolicyProviderTestHarness(); |
| 55 virtual ~PolicyProviderTestHarness(); |
| 56 |
| 57 // Actions to run at gtest SetUp() time. |
| 58 virtual void SetUp() = 0; |
| 59 |
| 60 // Create a new policy provider. |
| 61 virtual AsynchronousPolicyProvider* CreateProvider( |
| 62 const PolicyDefinitionList* policy_definition_list) = 0; |
| 63 |
| 64 // Helpers to configure the environment the policy provider reads from. |
| 65 virtual void InstallEmptyPolicy() = 0; |
| 66 virtual void InstallStringPolicy(const std::string& policy_name, |
| 67 const std::string& policy_value) = 0; |
| 68 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 69 int policy_value) = 0; |
| 70 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 71 bool policy_value) = 0; |
| 72 virtual void InstallStringListPolicy(const std::string& policy_name, |
| 73 const ListValue* policy_value) = 0; |
| 74 |
| 75 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); |
| 77 }; |
| 78 |
| 79 // A factory method for creating a test harness. |
| 80 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); |
| 81 |
| 82 // Abstract policy provider test. This is meant to be instantiated for each |
| 83 // policy provider implementation, passing in a suitable harness factory |
| 84 // function as the test parameter. |
| 85 class ConfigurationPolicyProviderTest |
| 86 : public testing::TestWithParam<CreatePolicyProviderTestHarness> { |
| 87 protected: |
| 88 ConfigurationPolicyProviderTest(); |
| 89 virtual ~ConfigurationPolicyProviderTest(); |
| 90 |
| 91 virtual void SetUp(); |
| 92 virtual void TearDown(); |
| 93 |
| 94 // Installs a valid policy and checks whether the provider returns the |
| 95 // |expected_value|. |
| 96 void CheckValue(const char* policy_name, |
| 97 ConfigurationPolicyType policy_type, |
| 98 const base::Value& expected_value, |
| 99 base::Closure install_value); |
| 100 |
| 101 // Threading setup so we can have providers reload stuff on the FILE thread. |
| 102 MessageLoopForIO loop_; |
| 103 content::TestBrowserThread ui_thread_; |
| 104 content::TestBrowserThread file_thread_; |
| 105 |
| 106 scoped_ptr<PolicyProviderTestHarness> test_harness_; |
| 107 scoped_ptr<AsynchronousPolicyProvider> provider_; |
| 108 |
| 109 private: |
| 110 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); |
| 111 }; |
| 112 |
| 113 } // namespace policy |
| 114 |
| 115 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
OLD | NEW |