OLD | NEW |
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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h" | 8 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h" |
9 #include "components/bookmarks/common/bookmark_pref_names.h" | 9 #include "components/bookmarks/common/bookmark_pref_names.h" |
10 #include "components/policy/core/browser/configuration_policy_pref_store.h" | 10 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 .release(), | 73 .release(), |
74 NULL); | 74 NULL); |
75 UpdateProviderPolicy(policy); | 75 UpdateProviderPolicy(policy); |
76 const base::Value* pref_value = NULL; | 76 const base::Value* pref_value = NULL; |
77 EXPECT_TRUE( | 77 EXPECT_TRUE( |
78 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); | 78 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); |
79 ASSERT_TRUE(pref_value); | 79 ASSERT_TRUE(pref_value); |
80 | 80 |
81 scoped_ptr<base::Value> expected( | 81 scoped_ptr<base::Value> expected( |
82 extensions::ListBuilder() | 82 extensions::ListBuilder() |
83 .Append(std::move(extensions::DictionaryBuilder() | 83 .Append(extensions::DictionaryBuilder() |
84 .Set("name", "Google") | 84 .Set("name", "Google") |
85 .Set("url", "http://google.com/"))) | 85 .Set("url", "http://google.com/") |
86 .Append(std::move(extensions::DictionaryBuilder() | 86 .Build()) |
87 .Set("name", "Empty Folder") | 87 .Append(extensions::DictionaryBuilder() |
88 .Set("children", extensions::ListBuilder()))) | 88 .Set("name", "Empty Folder") |
89 .Append(std::move( | 89 .Set("children", extensions::ListBuilder().Build()) |
| 90 .Build()) |
| 91 .Append( |
90 extensions::DictionaryBuilder() | 92 extensions::DictionaryBuilder() |
91 .Set("name", "Big Folder") | 93 .Set("name", "Big Folder") |
92 .Set( | 94 .Set("children", |
93 "children", | 95 extensions::ListBuilder() |
94 std::move( | 96 .Append(extensions::DictionaryBuilder() |
95 extensions::ListBuilder() | 97 .Set("name", "Youtube") |
96 .Append(std::move( | 98 .Set("url", "http://youtube.com/") |
97 extensions::DictionaryBuilder() | 99 .Build()) |
98 .Set("name", "Youtube") | 100 .Append(extensions::DictionaryBuilder() |
99 .Set("url", "http://youtube.com/"))) | 101 .Set("name", "Chromium") |
100 .Append(std::move( | 102 .Set("url", "http://chromium.org/") |
101 extensions::DictionaryBuilder() | 103 .Build()) |
102 .Set("name", "Chromium") | 104 .Append( |
103 .Set("url", "http://chromium.org/"))) | 105 extensions::DictionaryBuilder() |
104 .Append(std::move( | 106 .Set("name", "More Stuff") |
105 extensions::DictionaryBuilder() | 107 .Set("children", |
106 .Set("name", "More Stuff") | 108 extensions::ListBuilder() |
107 .Set( | 109 .Append( |
108 "children", | 110 extensions::DictionaryBuilder() |
109 std::move( | 111 .Set("name", "Bugs") |
110 extensions::ListBuilder().Append( | 112 .Set("url", |
111 std::move( | 113 "http://" |
112 extensions:: | 114 "crbug." |
113 DictionaryBuilder() | 115 "com" |
114 .Set("name", | 116 "/") |
115 "Bugs") | 117 .Build()) |
116 .Set( | 118 .Build()) |
117 "url", | 119 .Build()) |
118 "http://" | 120 .Build()) |
119 "crbug." | 121 .Build()) |
120 "com" | |
121 "/"))))))))))) | |
122 .Build()); | 122 .Build()); |
123 EXPECT_TRUE(pref_value->Equals(expected.get())); | 123 EXPECT_TRUE(pref_value->Equals(expected.get())); |
124 } | 124 } |
125 #endif // defined(ENABLE_EXTENSIONS) | 125 #endif // defined(ENABLE_EXTENSIONS) |
126 | 126 |
127 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongPolicyType) { | 127 TEST_F(ManagedBookmarksPolicyHandlerTest, WrongPolicyType) { |
128 PolicyMap policy; | 128 PolicyMap policy; |
129 // The expected type is base::ListValue, but this policy sets it as an | 129 // The expected type is base::ListValue, but this policy sets it as an |
130 // unparsed base::StringValue. Any type other than ListValue should fail. | 130 // unparsed base::StringValue. Any type other than ListValue should fail. |
131 policy.Set(key::kManagedBookmarks, | 131 policy.Set(key::kManagedBookmarks, |
(...skipping 29 matching lines...) Expand all Loading... |
161 .release(), | 161 .release(), |
162 NULL); | 162 NULL); |
163 UpdateProviderPolicy(policy); | 163 UpdateProviderPolicy(policy); |
164 const base::Value* pref_value = NULL; | 164 const base::Value* pref_value = NULL; |
165 EXPECT_TRUE( | 165 EXPECT_TRUE( |
166 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); | 166 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); |
167 ASSERT_TRUE(pref_value); | 167 ASSERT_TRUE(pref_value); |
168 | 168 |
169 scoped_ptr<base::Value> expected( | 169 scoped_ptr<base::Value> expected( |
170 extensions::ListBuilder() | 170 extensions::ListBuilder() |
171 .Append(std::move(extensions::DictionaryBuilder() | 171 .Append(extensions::DictionaryBuilder() |
172 .Set("name", "Google") | 172 .Set("name", "Google") |
173 .Set("url", "http://google.com/"))) | 173 .Set("url", "http://google.com/") |
| 174 .Build()) |
174 .Build()); | 175 .Build()); |
175 EXPECT_TRUE(pref_value->Equals(expected.get())); | 176 EXPECT_TRUE(pref_value->Equals(expected.get())); |
176 } | 177 } |
177 #endif | 178 #endif |
178 | 179 |
179 #if defined(ENABLE_EXTENSIONS) | 180 #if defined(ENABLE_EXTENSIONS) |
180 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) { | 181 TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) { |
181 PolicyMap policy; | 182 PolicyMap policy; |
182 policy.Set(key::kManagedBookmarks, | 183 policy.Set(key::kManagedBookmarks, |
183 POLICY_LEVEL_MANDATORY, | 184 POLICY_LEVEL_MANDATORY, |
(...skipping 20 matching lines...) Expand all Loading... |
204 .release(), | 205 .release(), |
205 NULL); | 206 NULL); |
206 UpdateProviderPolicy(policy); | 207 UpdateProviderPolicy(policy); |
207 const base::Value* pref_value = NULL; | 208 const base::Value* pref_value = NULL; |
208 EXPECT_TRUE( | 209 EXPECT_TRUE( |
209 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); | 210 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); |
210 ASSERT_TRUE(pref_value); | 211 ASSERT_TRUE(pref_value); |
211 | 212 |
212 scoped_ptr<base::Value> expected( | 213 scoped_ptr<base::Value> expected( |
213 extensions::ListBuilder() | 214 extensions::ListBuilder() |
214 .Append(std::move(extensions::DictionaryBuilder() | 215 .Append(extensions::DictionaryBuilder() |
215 .Set("name", "Google") | 216 .Set("name", "Google") |
216 .Set("url", "http://google.com/"))) | 217 .Set("url", "http://google.com/") |
| 218 .Build()) |
217 .Build()); | 219 .Build()); |
218 EXPECT_TRUE(pref_value->Equals(expected.get())); | 220 EXPECT_TRUE(pref_value->Equals(expected.get())); |
219 } | 221 } |
220 #endif | 222 #endif |
221 | 223 |
222 } // namespace policy | 224 } // namespace policy |
OLD | NEW |