summaryrefslogtreecommitdiff
path: root/chromium/components/policy/core/common/preferences_mock_mac.cc
blob: 76ec203e7415191ab434902e2f76166be75ebcc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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));
  machine_.reset(
      CFSetCreateMutable(kCFAllocatorDefault, 0, &kCFTypeSetCallBacks));
}

MockPreferences::~MockPreferences() {
}

Boolean MockPreferences::AppSynchronize(CFStringRef application_id) {
  return true;
}

CFPropertyListRef MockPreferences::CopyAppValue(CFStringRef key,
                                                CFStringRef application_id) {
  CFPropertyListRef value;
  Boolean found = CFDictionaryGetValueIfPresent(values_,
                                                key,
                                                &value);
  if (!found || !value)
    return NULL;
  CFRetain(value);
  return value;
}

Boolean MockPreferences::AppValueIsForced(CFStringRef key,
                                          CFStringRef application_id) {
  return CFSetContainsValue(forced_, key);
}

Boolean MockPreferences::IsManagedPolicyAvailableForMachineScope(
    CFStringRef key) {
  return CFSetContainsValue(machine_, key);
}

void MockPreferences::AddTestItem(CFStringRef key,
                                  CFPropertyListRef value,
                                  bool is_forced,
                                  bool is_machine) {
  CFDictionarySetValue(values_, key, value);
  if (is_forced)
    CFSetAddValue(forced_, key);
  if (is_machine)
    CFSetAddValue(machine_, key);
}