OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #include "base/json/json_reader.h" | |
6 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h" | |
7 #include "components/bookmarks/common/bookmark_pref_names.h" | |
8 #include "components/policy/core/browser/configuration_policy_pref_store.h" | |
9 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" | |
10 #include "components/policy/core/common/policy_map.h" | |
11 #include "components/policy/core/common/schema.h" | |
12 #include "extensions/common/value_builder.h" | |
13 #include "policy/policy_constants.h" | |
14 | |
15 namespace policy { | |
16 | |
17 class ManagedBookmarksPolicyHandlerTest | |
18 : public ConfigurationPolicyPrefStoreTest { | |
19 virtual void SetUp() OVERRIDE { | |
20 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); | |
21 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( | |
22 new ManagedBookmarksPolicyHandler(chrome_schema))); | |
23 } | |
24 }; | |
25 | |
26 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) { | |
27 EXPECT_FALSE(store_->GetValue(prefs::kManagedBookmarks, NULL)); | |
28 | |
29 PolicyMap policy; | |
30 policy.Set(key::kManagedBookmarks, | |
31 POLICY_LEVEL_MANDATORY, | |
32 POLICY_SCOPE_USER, | |
33 base::JSONReader::Read( | |
34 "[" | |
35 " {" | |
36 " \"name\": \"Google\"," | |
37 " \"url\": \"google.com\"" | |
38 " }," | |
39 " {" | |
40 " \"name\": \"Empty Folder\"," | |
41 " \"children\": []" | |
42 " }," | |
43 " {" | |
44 " \"name\": \"Big Folder\"," | |
45 " \"children\": [" | |
46 " {" | |
47 " \"name\": \"Youtube\"," | |
48 " \"url\": \"youtube.com\"" | |
49 " }," | |
50 " {" | |
51 " \"name\": \"Chromium\"," | |
52 " \"url\": \"chromium.org\"" | |
53 " }," | |
54 " {" | |
55 " \"name\": \"More Stuff\"," | |
56 " \"children\": [" | |
57 " {" | |
58 " \"name\": \"Bugs\"," | |
59 " \"url\": \"crbug.com\"" | |
60 " }" | |
61 " ]" | |
62 " }" | |
63 " ]" | |
64 " }" | |
65 "]"), | |
66 NULL); | |
67 UpdateProviderPolicy(policy); | |
68 const base::Value* pref_value = NULL; | |
69 EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); | |
70 ASSERT_TRUE(pref_value); | |
71 | |
72 scoped_ptr<base::Value> expected( | |
73 extensions::ListBuilder() | |
74 .Append(extensions::DictionaryBuilder() | |
75 .Set("name", "Google") | |
76 .Set("url", "http://google.com/")) | |
77 .Append(extensions::DictionaryBuilder() | |
78 .Set("name", "Empty Folder") | |
79 .Set("children", extensions::ListBuilder().Pass())) | |
80 .Append(extensions::DictionaryBuilder() | |
81 .Set("name", "Big Folder") | |
82 .Set("children", extensions::ListBuilder() | |
83 .Append(extensions::DictionaryBuilder() | |
84 .Set("name", "Youtube") | |
85 .Set("url", "http://youtube.com/")) | |
86 .Append(extensions::DictionaryBuilder() | |
87 .Set("name", "Chromium") | |
88 .Set("url", "http://chromium.org/")) | |
89 .Append(extensions::DictionaryBuilder() | |
90 .Set("name", "More Stuff") | |
91 .Set("children", extensions::ListBuilder() | |
92 .Append(extensions::DictionaryBuilder() | |
93 .Set("name", "Bugs") | |
94 .Set("url", "http://crbug.com/") | |
95 .Pass()) | |
96 .Pass()) | |
97 .Pass()) | |
98 .Pass()) | |
99 .Pass()) | |
100 .Build()); | |
101 EXPECT_TRUE(pref_value->Equals(expected.get())); | |
102 } | |
103 | |
104 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongType) { | |
pastarmovj
2014/05/30 14:07:13
Please change this to WrongPolicyType
Joao da Silva
2014/05/30 20:54:35
Done.
| |
105 PolicyMap policy; | |
106 policy.Set(key::kManagedBookmarks, | |
107 POLICY_LEVEL_MANDATORY, | |
108 POLICY_SCOPE_USER, | |
109 new base::StringValue( | |
110 "[" | |
111 " {" | |
112 " \"name\": \"Google\"," | |
113 " \"url\": \"google.com\"" | |
114 " }," | |
115 "]"), | |
116 NULL); | |
117 UpdateProviderPolicy(policy); | |
118 EXPECT_FALSE(store_->GetValue(prefs::kManagedBookmarks, NULL)); | |
119 } | |
120 | |
121 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) { | |
122 PolicyMap policy; | |
123 policy.Set(key::kManagedBookmarks, | |
124 POLICY_LEVEL_MANDATORY, | |
125 POLICY_SCOPE_USER, | |
126 base::JSONReader::Read( | |
127 "[" | |
128 " {" | |
129 " \"name\": \"Google\"," | |
130 " \"unknown\": \"should be ignored\"," | |
131 " \"url\": \"google.com\"" | |
132 " }" | |
133 "]"), | |
134 NULL); | |
135 UpdateProviderPolicy(policy); | |
136 const base::Value* pref_value = NULL; | |
137 EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); | |
138 ASSERT_TRUE(pref_value); | |
139 | |
140 scoped_ptr<base::Value> expected( | |
141 extensions::ListBuilder() | |
142 .Append(extensions::DictionaryBuilder() | |
143 .Set("name", "Google") | |
144 .Set("url", "http://google.com/")) | |
145 .Build()); | |
146 EXPECT_TRUE(pref_value->Equals(expected.get())); | |
147 } | |
148 | |
149 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) { | |
150 PolicyMap policy; | |
151 policy.Set(key::kManagedBookmarks, | |
152 POLICY_LEVEL_MANDATORY, | |
153 POLICY_SCOPE_USER, | |
154 base::JSONReader::Read( | |
155 "[" | |
156 " {" | |
157 " \"name\": \"Empty\"," | |
158 " \"url\": \"\"" | |
159 " }," | |
160 " {" | |
161 " \"name\": \"Invalid type\"," | |
162 " \"url\": 4" | |
163 " }," | |
164 " {" | |
165 " \"name\": \"Invalid URL\"," | |
166 " \"url\": \"?\"" | |
167 " }," | |
168 " {" | |
169 " \"name\": \"Google\"," | |
170 " \"url\": \"google.com\"" | |
171 " }" | |
172 "]"), | |
173 NULL); | |
174 UpdateProviderPolicy(policy); | |
175 const base::Value* pref_value = NULL; | |
176 EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); | |
177 ASSERT_TRUE(pref_value); | |
178 | |
179 scoped_ptr<base::Value> expected( | |
180 extensions::ListBuilder() | |
181 .Append(extensions::DictionaryBuilder() | |
182 .Set("name", "Google") | |
183 .Set("url", "http://google.com/")) | |
184 .Build()); | |
185 EXPECT_TRUE(pref_value->Equals(expected.get())); | |
186 } | |
187 | |
188 } // namespace policy | |
OLD | NEW |