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

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

Issue 582933003: Revert of Cleanup: Remove remaining generated extensions APIs on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extclean4
Patch Set: Created 6 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
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_provider_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/schema.h" 11 #include "components/policy/core/common/schema.h"
12 #include "extensions/common/value_builder.h"
12 #include "policy/policy_constants.h" 13 #include "policy/policy_constants.h"
13 14
14 #if defined(ENABLE_EXTENSIONS)
15 #include "extensions/common/value_builder.h"
16 #endif
17
18 namespace policy { 15 namespace policy {
19 16
20 class ManagedBookmarksPolicyHandlerTest 17 class ManagedBookmarksPolicyHandlerTest
21 : public ConfigurationPolicyPrefStoreTest { 18 : public ConfigurationPolicyPrefStoreTest {
22 virtual void SetUp() OVERRIDE { 19 virtual void SetUp() OVERRIDE {
23 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); 20 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData());
24 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( 21 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
25 new ManagedBookmarksPolicyHandler(chrome_schema))); 22 new ManagedBookmarksPolicyHandler(chrome_schema)));
26 } 23 }
27 }; 24 };
28 25
29 #if defined(ENABLE_EXTENSIONS)
30 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) { 26 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) {
31 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL)); 27 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL));
32 28
33 PolicyMap policy; 29 PolicyMap policy;
34 policy.Set(key::kManagedBookmarks, 30 policy.Set(key::kManagedBookmarks,
35 POLICY_LEVEL_MANDATORY, 31 POLICY_LEVEL_MANDATORY,
36 POLICY_SCOPE_USER, 32 POLICY_SCOPE_USER,
37 base::JSONReader::Read( 33 base::JSONReader::Read(
38 "[" 34 "["
39 " {" 35 " {"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 .Set("name", "Bugs") 94 .Set("name", "Bugs")
99 .Set("url", "http://crbug.com/") 95 .Set("url", "http://crbug.com/")
100 .Pass()) 96 .Pass())
101 .Pass()) 97 .Pass())
102 .Pass()) 98 .Pass())
103 .Pass()) 99 .Pass())
104 .Pass()) 100 .Pass())
105 .Build()); 101 .Build());
106 EXPECT_TRUE(pref_value->Equals(expected.get())); 102 EXPECT_TRUE(pref_value->Equals(expected.get()));
107 } 103 }
108 #endif // defined(ENABLE_EXTENSIONS)
109 104
110 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongPolicyType) { 105 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongPolicyType) {
111 PolicyMap policy; 106 PolicyMap policy;
112 // The expected type is base::ListValue, but this policy sets it as an 107 // The expected type is base::ListValue, but this policy sets it as an
113 // unparsed base::StringValue. Any type other than ListValue should fail. 108 // unparsed base::StringValue. Any type other than ListValue should fail.
114 policy.Set(key::kManagedBookmarks, 109 policy.Set(key::kManagedBookmarks,
115 POLICY_LEVEL_MANDATORY, 110 POLICY_LEVEL_MANDATORY,
116 POLICY_SCOPE_USER, 111 POLICY_SCOPE_USER,
117 new base::StringValue( 112 new base::StringValue(
118 "[" 113 "["
119 " {" 114 " {"
120 " \"name\": \"Google\"," 115 " \"name\": \"Google\","
121 " \"url\": \"google.com\"" 116 " \"url\": \"google.com\""
122 " }," 117 " },"
123 "]"), 118 "]"),
124 NULL); 119 NULL);
125 UpdateProviderPolicy(policy); 120 UpdateProviderPolicy(policy);
126 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL)); 121 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL));
127 } 122 }
128 123
129 #if defined(ENABLE_EXTENSIONS)
130 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) { 124 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) {
131 PolicyMap policy; 125 PolicyMap policy;
132 policy.Set(key::kManagedBookmarks, 126 policy.Set(key::kManagedBookmarks,
133 POLICY_LEVEL_MANDATORY, 127 POLICY_LEVEL_MANDATORY,
134 POLICY_SCOPE_USER, 128 POLICY_SCOPE_USER,
135 base::JSONReader::Read( 129 base::JSONReader::Read(
136 "[" 130 "["
137 " {" 131 " {"
138 " \"name\": \"Google\"," 132 " \"name\": \"Google\","
139 " \"unknown\": \"should be ignored\"," 133 " \"unknown\": \"should be ignored\","
140 " \"url\": \"google.com\"" 134 " \"url\": \"google.com\""
141 " }" 135 " }"
142 "]"), 136 "]"),
143 NULL); 137 NULL);
144 UpdateProviderPolicy(policy); 138 UpdateProviderPolicy(policy);
145 const base::Value* pref_value = NULL; 139 const base::Value* pref_value = NULL;
146 EXPECT_TRUE( 140 EXPECT_TRUE(
147 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); 141 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value));
148 ASSERT_TRUE(pref_value); 142 ASSERT_TRUE(pref_value);
149 143
150 scoped_ptr<base::Value> expected( 144 scoped_ptr<base::Value> expected(
151 extensions::ListBuilder() 145 extensions::ListBuilder()
152 .Append(extensions::DictionaryBuilder() 146 .Append(extensions::DictionaryBuilder()
153 .Set("name", "Google") 147 .Set("name", "Google")
154 .Set("url", "http://google.com/")) 148 .Set("url", "http://google.com/"))
155 .Build()); 149 .Build());
156 EXPECT_TRUE(pref_value->Equals(expected.get())); 150 EXPECT_TRUE(pref_value->Equals(expected.get()));
157 } 151 }
158 #endif
159 152
160 #if defined(ENABLE_EXTENSIONS)
161 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) { 153 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) {
162 PolicyMap policy; 154 PolicyMap policy;
163 policy.Set(key::kManagedBookmarks, 155 policy.Set(key::kManagedBookmarks,
164 POLICY_LEVEL_MANDATORY, 156 POLICY_LEVEL_MANDATORY,
165 POLICY_SCOPE_USER, 157 POLICY_SCOPE_USER,
166 base::JSONReader::Read( 158 base::JSONReader::Read(
167 "[" 159 "["
168 " {" 160 " {"
169 " \"name\": \"Empty\"," 161 " \"name\": \"Empty\","
170 " \"url\": \"\"" 162 " \"url\": \"\""
(...skipping 19 matching lines...) Expand all
190 ASSERT_TRUE(pref_value); 182 ASSERT_TRUE(pref_value);
191 183
192 scoped_ptr<base::Value> expected( 184 scoped_ptr<base::Value> expected(
193 extensions::ListBuilder() 185 extensions::ListBuilder()
194 .Append(extensions::DictionaryBuilder() 186 .Append(extensions::DictionaryBuilder()
195 .Set("name", "Google") 187 .Set("name", "Google")
196 .Set("url", "http://google.com/")) 188 .Set("url", "http://google.com/"))
197 .Build()); 189 .Build());
198 EXPECT_TRUE(pref_value->Equals(expected.get())); 190 EXPECT_TRUE(pref_value->Equals(expected.get()));
199 } 191 }
200 #endif
201 192
202 } // namespace policy 193 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_provider_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698