Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Side by Side Diff: chrome/browser/policy/managed_bookmarks_policy_handler_unittest.cc

Issue 1348903007: Revert of Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #include "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h" 6 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h"
7 #include "components/bookmarks/common/bookmark_pref_names.h" 7 #include "components/bookmarks/common/bookmark_pref_names.h"
8 #include "components/policy/core/browser/configuration_policy_pref_store.h" 8 #include "components/policy/core/browser/configuration_policy_pref_store.h"
9 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 9 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
10 #include "components/policy/core/common/policy_map.h" 10 #include "components/policy/core/common/policy_map.h"
11 #include "components/policy/core/common/policy_types.h"
12 #include "components/policy/core/common/schema.h" 11 #include "components/policy/core/common/schema.h"
13 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
14 13
15 #if defined(ENABLE_EXTENSIONS) 14 #if defined(ENABLE_EXTENSIONS)
16 #include "extensions/common/value_builder.h" 15 #include "extensions/common/value_builder.h"
17 #endif 16 #endif
18 17
19 namespace policy { 18 namespace policy {
20 19
21 class ManagedBookmarksPolicyHandlerTest 20 class ManagedBookmarksPolicyHandlerTest
22 : public ConfigurationPolicyPrefStoreTest { 21 : public ConfigurationPolicyPrefStoreTest {
23 void SetUp() override { 22 void SetUp() override {
24 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); 23 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData());
25 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( 24 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
26 new ManagedBookmarksPolicyHandler(chrome_schema))); 25 new ManagedBookmarksPolicyHandler(chrome_schema)));
27 } 26 }
28 }; 27 };
29 28
30 #if defined(ENABLE_EXTENSIONS) 29 #if defined(ENABLE_EXTENSIONS)
31 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) { 30 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) {
32 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL)); 31 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL));
33 32
34 PolicyMap policy; 33 PolicyMap policy;
35 policy.Set(key::kManagedBookmarks, 34 policy.Set(key::kManagedBookmarks, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
36 POLICY_LEVEL_MANDATORY,
37 POLICY_SCOPE_USER,
38 POLICY_SOURCE_CLOUD,
39 base::JSONReader::Read("[" 35 base::JSONReader::Read("["
40 " {" 36 " {"
41 " \"name\": \"Google\"," 37 " \"name\": \"Google\","
42 " \"url\": \"google.com\"" 38 " \"url\": \"google.com\""
43 " }," 39 " },"
44 " {" 40 " {"
45 " \"name\": \"Empty Folder\"," 41 " \"name\": \"Empty Folder\","
46 " \"children\": []" 42 " \"children\": []"
47 " }," 43 " },"
48 " {" 44 " {"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 105 }
110 #endif // defined(ENABLE_EXTENSIONS) 106 #endif // defined(ENABLE_EXTENSIONS)
111 107
112 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongPolicyType) { 108 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongPolicyType) {
113 PolicyMap policy; 109 PolicyMap policy;
114 // The expected type is base::ListValue, but this policy sets it as an 110 // The expected type is base::ListValue, but this policy sets it as an
115 // unparsed base::StringValue. Any type other than ListValue should fail. 111 // unparsed base::StringValue. Any type other than ListValue should fail.
116 policy.Set(key::kManagedBookmarks, 112 policy.Set(key::kManagedBookmarks,
117 POLICY_LEVEL_MANDATORY, 113 POLICY_LEVEL_MANDATORY,
118 POLICY_SCOPE_USER, 114 POLICY_SCOPE_USER,
119 POLICY_SOURCE_CLOUD,
120 new base::StringValue( 115 new base::StringValue(
121 "[" 116 "["
122 " {" 117 " {"
123 " \"name\": \"Google\"," 118 " \"name\": \"Google\","
124 " \"url\": \"google.com\"" 119 " \"url\": \"google.com\""
125 " }," 120 " },"
126 "]"), 121 "]"),
127 NULL); 122 NULL);
128 UpdateProviderPolicy(policy); 123 UpdateProviderPolicy(policy);
129 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL)); 124 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL));
130 } 125 }
131 126
132 #if defined(ENABLE_EXTENSIONS) 127 #if defined(ENABLE_EXTENSIONS)
133 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) { 128 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) {
134 PolicyMap policy; 129 PolicyMap policy;
135 policy.Set(key::kManagedBookmarks, 130 policy.Set(key::kManagedBookmarks, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
136 POLICY_LEVEL_MANDATORY,
137 POLICY_SCOPE_USER,
138 POLICY_SOURCE_CLOUD,
139 base::JSONReader::Read("[" 131 base::JSONReader::Read("["
140 " {" 132 " {"
141 " \"name\": \"Google\"," 133 " \"name\": \"Google\","
142 " \"unknown\": \"should be ignored\"," 134 " \"unknown\": \"should be ignored\","
143 " \"url\": \"google.com\"" 135 " \"url\": \"google.com\""
144 " }" 136 " }"
145 "]") 137 "]")
146 .release(), 138 .release(),
147 NULL); 139 NULL);
148 UpdateProviderPolicy(policy); 140 UpdateProviderPolicy(policy);
149 const base::Value* pref_value = NULL; 141 const base::Value* pref_value = NULL;
150 EXPECT_TRUE( 142 EXPECT_TRUE(
151 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); 143 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value));
152 ASSERT_TRUE(pref_value); 144 ASSERT_TRUE(pref_value);
153 145
154 scoped_ptr<base::Value> expected( 146 scoped_ptr<base::Value> expected(
155 extensions::ListBuilder() 147 extensions::ListBuilder()
156 .Append(extensions::DictionaryBuilder() 148 .Append(extensions::DictionaryBuilder()
157 .Set("name", "Google") 149 .Set("name", "Google")
158 .Set("url", "http://google.com/")) 150 .Set("url", "http://google.com/"))
159 .Build()); 151 .Build());
160 EXPECT_TRUE(pref_value->Equals(expected.get())); 152 EXPECT_TRUE(pref_value->Equals(expected.get()));
161 } 153 }
162 #endif 154 #endif
163 155
164 #if defined(ENABLE_EXTENSIONS) 156 #if defined(ENABLE_EXTENSIONS)
165 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) { 157 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) {
166 PolicyMap policy; 158 PolicyMap policy;
167 policy.Set(key::kManagedBookmarks, 159 policy.Set(key::kManagedBookmarks, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
168 POLICY_LEVEL_MANDATORY,
169 POLICY_SCOPE_USER,
170 POLICY_SOURCE_CLOUD,
171 base::JSONReader::Read("[" 160 base::JSONReader::Read("["
172 " {" 161 " {"
173 " \"name\": \"Empty\"," 162 " \"name\": \"Empty\","
174 " \"url\": \"\"" 163 " \"url\": \"\""
175 " }," 164 " },"
176 " {" 165 " {"
177 " \"name\": \"Invalid type\"," 166 " \"name\": \"Invalid type\","
178 " \"url\": 4" 167 " \"url\": 4"
179 " }," 168 " },"
180 " {" 169 " {"
(...skipping 17 matching lines...) Expand all
198 extensions::ListBuilder() 187 extensions::ListBuilder()
199 .Append(extensions::DictionaryBuilder() 188 .Append(extensions::DictionaryBuilder()
200 .Set("name", "Google") 189 .Set("name", "Google")
201 .Set("url", "http://google.com/")) 190 .Set("url", "http://google.com/"))
202 .Build()); 191 .Build());
203 EXPECT_TRUE(pref_value->Equals(expected.get())); 192 EXPECT_TRUE(pref_value->Equals(expected.get()));
204 } 193 }
205 #endif 194 #endif
206 195
207 } // namespace policy 196 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/javascript_policy_handler_unittest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698