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_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "chrome/browser/policy/asynchronous_policy_test_base.h" | 15 #include "chrome/browser/policy/policy_constants.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class DictionaryValue; | 20 class DictionaryValue; |
| 21 class ListValue; | 21 class ListValue; |
| 22 class Value; | 22 class Value; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace policy { | 25 namespace policy { |
| 26 | 26 |
| 27 class AsynchronousPolicyProvider; | 27 class ConfigurationPolicyProvider; |
| 28 struct PolicyDefinitionList; | 28 struct PolicyDefinitionList; |
| 29 | 29 |
| 30 // A stripped-down policy definition list that contains entries for the | 30 // A stripped-down policy definition list that contains entries for the |
| 31 // different policy setting types supported. | 31 // different policy setting types supported. |
| 32 namespace test_policy_definitions { | 32 namespace test_policy_definitions { |
| 33 | 33 |
| 34 // String policy keys. | 34 // String policy keys. |
| 35 extern const char kKeyString[]; | 35 extern const char kKeyString[]; |
| 36 extern const char kKeyBoolean[]; | 36 extern const char kKeyBoolean[]; |
| 37 extern const char kKeyInteger[]; | 37 extern const char kKeyInteger[]; |
| 38 extern const char kKeyStringList[]; | 38 extern const char kKeyStringList[]; |
| 39 extern const char kKeyDictionary[]; | 39 extern const char kKeyDictionary[]; |
| 40 | 40 |
| 41 // Policy definition list that contains entries for the keys above. | 41 // Policy definition list that contains entries for the keys above. |
| 42 extern const PolicyDefinitionList kList; | 42 extern const PolicyDefinitionList kList; |
| 43 | 43 |
| 44 } // namespace test_policy_definitions | 44 } // namespace test_policy_definitions |
| 45 | 45 |
| 46 class PolicyTestBase : public testing::Test { | |
|
Mattias Nissler (ping if slow)
2012/06/05 11:55:59
AsynchronousPolicyTestBase is going away I guess?
Joao da Silva
2012/06/05 13:52:10
Yes, the cleanup CL deletes it.
| |
| 47 public: | |
| 48 PolicyTestBase(); | |
| 49 virtual ~PolicyTestBase(); | |
| 50 | |
| 51 // testing::Test: | |
| 52 virtual void TearDown() OVERRIDE; | |
| 53 | |
| 54 protected: | |
| 55 // Create an actual IO loop (needed by FilePathWatcher). | |
| 56 MessageLoopForIO loop_; | |
| 57 | |
| 58 private: | |
| 59 content::TestBrowserThread ui_thread_; | |
| 60 content::TestBrowserThread file_thread_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(PolicyTestBase); | |
| 63 }; | |
| 64 | |
| 46 // An interface for creating a test policy provider and creating a policy | 65 // An interface for creating a test policy provider and creating a policy |
| 47 // provider instance for testing. Used as the parameter to the abstract | 66 // provider instance for testing. Used as the parameter to the abstract |
| 48 // ConfigurationPolicyProviderTest below. | 67 // ConfigurationPolicyProviderTest below. |
| 49 class PolicyProviderTestHarness { | 68 class PolicyProviderTestHarness { |
| 50 public: | 69 public: |
| 51 // |level| and |scope| are the level and scope of the policies returned by | 70 // |level| and |scope| are the level and scope of the policies returned by |
| 52 // the providers from CreateProvider(). | 71 // the providers from CreateProvider(). |
| 53 PolicyProviderTestHarness(PolicyLevel level, PolicyScope scope); | 72 PolicyProviderTestHarness(PolicyLevel level, PolicyScope scope); |
| 54 virtual ~PolicyProviderTestHarness(); | 73 virtual ~PolicyProviderTestHarness(); |
| 55 | 74 |
| 56 // Actions to run at gtest SetUp() time. | 75 // Actions to run at gtest SetUp() time. |
| 57 virtual void SetUp() = 0; | 76 virtual void SetUp() = 0; |
| 58 | 77 |
| 59 // Create a new policy provider. | 78 // Create a new policy provider. |
| 60 virtual AsynchronousPolicyProvider* CreateProvider( | 79 virtual ConfigurationPolicyProvider* CreateProvider( |
| 61 const PolicyDefinitionList* policy_definition_list) = 0; | 80 const PolicyDefinitionList* policy_definition_list) = 0; |
| 62 | 81 |
| 63 // Returns the policy level and scope set by the policy provider. | 82 // Returns the policy level and scope set by the policy provider. |
| 64 PolicyLevel policy_level() const; | 83 PolicyLevel policy_level() const; |
| 65 PolicyScope policy_scope() const; | 84 PolicyScope policy_scope() const; |
| 66 | 85 |
| 67 // Helpers to configure the environment the policy provider reads from. | 86 // Helpers to configure the environment the policy provider reads from. |
| 68 virtual void InstallEmptyPolicy() = 0; | 87 virtual void InstallEmptyPolicy() = 0; |
| 69 virtual void InstallStringPolicy(const std::string& policy_name, | 88 virtual void InstallStringPolicy(const std::string& policy_name, |
| 70 const std::string& policy_value) = 0; | 89 const std::string& policy_value) = 0; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 85 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); | 104 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); |
| 86 }; | 105 }; |
| 87 | 106 |
| 88 // A factory method for creating a test harness. | 107 // A factory method for creating a test harness. |
| 89 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); | 108 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); |
| 90 | 109 |
| 91 // Abstract policy provider test. This is meant to be instantiated for each | 110 // Abstract policy provider test. This is meant to be instantiated for each |
| 92 // policy provider implementation, passing in a suitable harness factory | 111 // policy provider implementation, passing in a suitable harness factory |
| 93 // function as the test parameter. | 112 // function as the test parameter. |
| 94 class ConfigurationPolicyProviderTest | 113 class ConfigurationPolicyProviderTest |
| 95 : public AsynchronousPolicyTestBase, | 114 : public PolicyTestBase, |
| 96 public testing::WithParamInterface<CreatePolicyProviderTestHarness> { | 115 public testing::WithParamInterface<CreatePolicyProviderTestHarness> { |
| 97 protected: | 116 protected: |
| 98 ConfigurationPolicyProviderTest(); | 117 ConfigurationPolicyProviderTest(); |
| 99 virtual ~ConfigurationPolicyProviderTest(); | 118 virtual ~ConfigurationPolicyProviderTest(); |
| 100 | 119 |
| 101 virtual void SetUp() OVERRIDE; | 120 virtual void SetUp() OVERRIDE; |
| 102 virtual void TearDown() OVERRIDE; | 121 virtual void TearDown() OVERRIDE; |
| 103 | 122 |
| 104 // Installs a valid policy and checks whether the provider returns the | 123 // Installs a valid policy and checks whether the provider returns the |
| 105 // |expected_value|. | 124 // |expected_value|. |
| 106 void CheckValue(const char* policy_name, | 125 void CheckValue(const char* policy_name, |
| 107 const base::Value& expected_value, | 126 const base::Value& expected_value, |
| 108 base::Closure install_value); | 127 base::Closure install_value); |
| 109 | 128 |
| 110 scoped_ptr<PolicyProviderTestHarness> test_harness_; | 129 scoped_ptr<PolicyProviderTestHarness> test_harness_; |
| 111 scoped_ptr<AsynchronousPolicyProvider> provider_; | 130 scoped_ptr<ConfigurationPolicyProvider> provider_; |
| 112 | 131 |
| 113 private: | 132 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); | 133 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); |
| 115 }; | 134 }; |
| 116 | 135 |
| 117 } // namespace policy | 136 } // namespace policy |
| 118 | 137 |
| 119 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 138 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| OLD | NEW |