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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (c) 2010 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 <gtest/gtest.h>
#include "base/stl_util-inl.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/configuration_policy_provider_mac.h"
#include "chrome/browser/mock_configuration_policy_store.h"
#include "chrome/browser/preferences_mock_mac.h"
// A subclass of |ConfigurationPolicyProviderMac| providing access to various
// internal things without an orgy of FRIEND_TESTS.
class TestConfigurationPolicyProviderMac
: public ConfigurationPolicyProviderMac {
public:
TestConfigurationPolicyProviderMac() :
ConfigurationPolicyProviderMac(new MockPreferences()) { }
virtual ~TestConfigurationPolicyProviderMac() { }
void AddTestItem(ConfigurationPolicyStore::PolicyType policy,
CFPropertyListRef value,
bool is_forced);
typedef std::vector<PolicyValueMapEntry> PolicyValueMap;
static const PolicyValueMap* PolicyValueMapping() {
return ConfigurationPolicyProvider::PolicyValueMapping();
}
};
void TestConfigurationPolicyProviderMac::AddTestItem(
ConfigurationPolicyStore::PolicyType policy,
CFPropertyListRef value,
bool is_forced) {
const PolicyValueMap* mapping = PolicyValueMapping();
for (PolicyValueMap::const_iterator current = mapping->begin();
current != mapping->end(); ++current) {
if (current->policy_type == policy) {
scoped_cftyperef<CFStringRef> name(
base::SysUTF8ToCFStringRef(current->name));
static_cast<MockPreferences*>(preferences_.get())->
AddTestItem(name, value, is_forced);
}
}
}
TEST(ConfigurationPolicyProviderMacTest, TestPolicyDefault) {
MockConfigurationPolicyStore store;
TestConfigurationPolicyProviderMac provider;
provider.Provide(&store);
const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map());
EXPECT_FALSE(ContainsKey(map, ConfigurationPolicyStore::kPolicyHomePage));
}
TEST(ConfigurationPolicyProviderMacTest, TestHomePagePolicy) {
MockConfigurationPolicyStore store;
TestConfigurationPolicyProviderMac provider;
provider.AddTestItem(ConfigurationPolicyStore::kPolicyHomePage,
CFSTR("http://chromium.org"),
true);
provider.Provide(&store);
const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map());
MockConfigurationPolicyStore::PolicyMap::const_iterator i =
map.find(ConfigurationPolicyStore::kPolicyHomePage);
ASSERT_TRUE(i != map.end());
std::string value;
i->second->GetAsString(&value);
EXPECT_EQ("http://chromium.org", value);
}
TEST(ConfigurationPolicyProviderMacTest, TestHomePagePolicyUnforced) {
MockConfigurationPolicyStore store;
TestConfigurationPolicyProviderMac provider;
provider.AddTestItem(ConfigurationPolicyStore::kPolicyHomePage,
CFSTR("http://chromium.org"),
false);
provider.Provide(&store);
const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map());
EXPECT_FALSE(ContainsKey(map, ConfigurationPolicyStore::kPolicyHomePage));
}
TEST(ConfigurationPolicyProviderMacTest, TestHomePagePolicyWrongType) {
MockConfigurationPolicyStore store;
TestConfigurationPolicyProviderMac provider;
provider.AddTestItem(ConfigurationPolicyStore::kPolicyHomePage,
kCFBooleanTrue,
true);
provider.Provide(&store);
const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map());
EXPECT_FALSE(ContainsKey(map, ConfigurationPolicyStore::kPolicyHomePage));
}
TEST(ConfigurationPolicyProviderMacTest, TestHomepageIsNewTabPagePolicy) {
MockConfigurationPolicyStore store;
TestConfigurationPolicyProviderMac provider;
provider.AddTestItem(ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage,
kCFBooleanTrue,
true);
provider.Provide(&store);
const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map());
MockConfigurationPolicyStore::PolicyMap::const_iterator i =
map.find(ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage);
ASSERT_TRUE(i != map.end());
bool value = false;
i->second->GetAsBoolean(&value);
EXPECT_EQ(true, value);
}
|