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

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

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