diff options
author | dconnelly@chromium.org <dconnelly@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-26 21:07:20 +0000 |
---|---|---|
committer | dconnelly@chromium.org <dconnelly@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-26 21:07:20 +0000 |
commit | ed004b334f206052c4ada768cf3eb2f6aba0ff0d (patch) | |
tree | 9670043a93dfc15b64cb3c4339872c89b8d111a0 /components | |
parent | 81f8b91b2f2213ad40d5bd4ecbe096550a2eedd6 (diff) | |
download | chromium_src-ed004b334f206052c4ada768cf3eb2f6aba0ff0d.zip chromium_src-ed004b334f206052c4ada768cf3eb2f6aba0ff0d.tar.gz chromium_src-ed004b334f206052c4ada768cf3eb2f6aba0ff0d.tar.bz2 |
Move PreferencesMac to components/policy/.
This facilitates the refactoring of chrome/browser/policy into a layered
component.
BUG=271392
Review URL: https://codereview.chromium.org/78603003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/components_tests.gyp | 1 | ||||
-rw-r--r-- | components/policy.gypi | 16 | ||||
-rw-r--r-- | components/policy/core/common/preferences_mac.cc | 19 | ||||
-rw-r--r-- | components/policy/core/common/preferences_mac.h | 35 | ||||
-rw-r--r-- | components/policy/core/common/preferences_mock_mac.cc | 47 | ||||
-rw-r--r-- | components/policy/core/common/preferences_mock_mac.h | 34 |
6 files changed, 152 insertions, 0 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp index e21d2af..b70f043 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -90,6 +90,7 @@ # Dependencies of policy 'components.gyp:policy_component', + 'components.gyp:policy_test_support', # Dependencies of precache 'components.gyp:precache_core', diff --git a/components/policy.gypi b/components/policy.gypi index 4580dea..ca168d7 100644 --- a/components/policy.gypi +++ b/components/policy.gypi @@ -36,6 +36,8 @@ 'policy/core/common/policy_switches.cc', 'policy/core/common/policy_switches.h', 'policy/core/common/policy_types.h', + 'policy/core/common/preferences_mac.cc', + 'policy/core/common/preferences_mac.h', 'policy/core/common/registry_dict_win.cc', 'policy/core/common/registry_dict_win.h', 'policy/core/common/schema.cc', @@ -63,5 +65,19 @@ }], ], }, + { + 'target_name': 'policy_test_support', + 'type': 'static_library', + 'defines!': ['POLICY_COMPONENT_IMPLEMENTATION'], + 'dependencies': [], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'policy/core/common/preferences_mock_mac.cc', + 'policy/core/common/preferences_mock_mac.h', + ], + 'conditions': [], + }, ], } diff --git a/components/policy/core/common/preferences_mac.cc b/components/policy/core/common/preferences_mac.cc new file mode 100644 index 0000000..e65b162 --- /dev/null +++ b/components/policy/core/common/preferences_mac.cc @@ -0,0 +1,19 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/policy/core/common/preferences_mac.h" + +Boolean MacPreferences::AppSynchronize(CFStringRef applicationID) { + return CFPreferencesAppSynchronize(applicationID); +} + +CFPropertyListRef MacPreferences::CopyAppValue(CFStringRef key, + CFStringRef applicationID) { + return CFPreferencesCopyAppValue(key, applicationID); +} + +Boolean MacPreferences::AppValueIsForced(CFStringRef key, + CFStringRef applicationID) { + return CFPreferencesAppValueIsForced(key, applicationID); +} diff --git a/components/policy/core/common/preferences_mac.h b/components/policy/core/common/preferences_mac.h new file mode 100644 index 0000000..5bb14c0 --- /dev/null +++ b/components/policy/core/common/preferences_mac.h @@ -0,0 +1,35 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MAC_H_ +#define COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MAC_H_ + +#include <CoreFoundation/CoreFoundation.h> + +#include "base/basictypes.h" +#include "components/policy/policy_export.h" + +// Wraps a small part of the CFPreferences API surface in a very thin layer, to +// allow it to be mocked out for testing. + +// See CFPreferences documentation for function documentation, as these call +// through directly to their CFPreferences equivalents (Foo -> +// CFPreferencesFoo). +class POLICY_EXPORT MacPreferences { + public: + MacPreferences() {} + virtual ~MacPreferences() {} + + virtual Boolean AppSynchronize(CFStringRef applicationID); + + virtual CFPropertyListRef CopyAppValue(CFStringRef key, + CFStringRef applicationID); + + virtual Boolean AppValueIsForced(CFStringRef key, CFStringRef applicationID); + + private: + DISALLOW_COPY_AND_ASSIGN(MacPreferences); +}; + +#endif // COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MAC_H_ diff --git a/components/policy/core/common/preferences_mock_mac.cc b/components/policy/core/common/preferences_mock_mac.cc new file mode 100644 index 0000000..bc51c9a --- /dev/null +++ b/components/policy/core/common/preferences_mock_mac.cc @@ -0,0 +1,47 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/policy/core/common/preferences_mock_mac.h" + +MockPreferences::MockPreferences() { + values_.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks)); + forced_.reset(CFSetCreateMutable(kCFAllocatorDefault, + 0, + &kCFTypeSetCallBacks)); +} + +MockPreferences::~MockPreferences() { +} + +Boolean MockPreferences::AppSynchronize(CFStringRef applicationID) { + return true; +} + +CFPropertyListRef MockPreferences::CopyAppValue(CFStringRef key, + CFStringRef applicationID) { + CFPropertyListRef value; + Boolean found = CFDictionaryGetValueIfPresent(values_, + key, + &value); + if (!found || !value) + return NULL; + CFRetain(value); + return value; +} + +Boolean MockPreferences::AppValueIsForced(CFStringRef key, + CFStringRef applicationID) { + return CFSetContainsValue(forced_, key); +} + +void MockPreferences::AddTestItem(CFStringRef key, + CFPropertyListRef value, + bool is_forced) { + CFDictionarySetValue(values_, key, value); + if (is_forced) + CFSetAddValue(forced_, key); +} diff --git a/components/policy/core/common/preferences_mock_mac.h b/components/policy/core/common/preferences_mock_mac.h new file mode 100644 index 0000000..f28f8fe --- /dev/null +++ b/components/policy/core/common/preferences_mock_mac.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MOCK_MAC_H_ +#define COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MOCK_MAC_H_ + +#include "base/mac/scoped_cftyperef.h" +#include "components/policy/core/common/preferences_mac.h" +#include "components/policy/policy_export.h" + +// Mock preferences wrapper for testing code that interacts with CFPreferences. +class POLICY_EXPORT MockPreferences : public MacPreferences { + public: + MockPreferences(); + virtual ~MockPreferences(); + + virtual Boolean AppSynchronize(CFStringRef applicationID) OVERRIDE; + + virtual CFPropertyListRef CopyAppValue(CFStringRef key, + CFStringRef applicationID) OVERRIDE; + + virtual Boolean AppValueIsForced(CFStringRef key, + CFStringRef applicationID) OVERRIDE; + + // Adds a preference item with the given info to the test set. + void AddTestItem(CFStringRef key, CFPropertyListRef value, bool is_forced); + + private: + base::ScopedCFTypeRef<CFMutableDictionaryRef> values_; + base::ScopedCFTypeRef<CFMutableSetRef> forced_; +}; + +#endif // COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MOCK_MAC_H_ |