| 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 "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 "extensions/common/value_builder.h" |
| 13 #include "policy/policy_constants.h" | 13 #include "policy/policy_constants.h" |
| 14 | 14 |
| 15 namespace policy { | 15 namespace policy { |
| 16 | 16 |
| 17 class ManagedBookmarksPolicyHandlerTest | 17 class ManagedBookmarksPolicyHandlerTest |
| 18 : public ConfigurationPolicyPrefStoreTest { | 18 : public ConfigurationPolicyPrefStoreTest { |
| 19 virtual void SetUp() OVERRIDE { | 19 virtual void SetUp() OVERRIDE { |
| 20 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); | 20 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); |
| 21 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( | 21 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( |
| 22 new ManagedBookmarksPolicyHandler(chrome_schema))); | 22 new ManagedBookmarksPolicyHandler(chrome_schema))); |
| 23 } | 23 } |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) { | 26 TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) { |
| 27 EXPECT_FALSE(store_->GetValue(prefs::kManagedBookmarks, NULL)); | 27 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL)); |
| 28 | 28 |
| 29 PolicyMap policy; | 29 PolicyMap policy; |
| 30 policy.Set(key::kManagedBookmarks, | 30 policy.Set(key::kManagedBookmarks, |
| 31 POLICY_LEVEL_MANDATORY, | 31 POLICY_LEVEL_MANDATORY, |
| 32 POLICY_SCOPE_USER, | 32 POLICY_SCOPE_USER, |
| 33 base::JSONReader::Read( | 33 base::JSONReader::Read( |
| 34 "[" | 34 "[" |
| 35 " {" | 35 " {" |
| 36 " \"name\": \"Google\"," | 36 " \"name\": \"Google\"," |
| 37 " \"url\": \"google.com\"" | 37 " \"url\": \"google.com\"" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 59 " \"url\": \"crbug.com\"" | 59 " \"url\": \"crbug.com\"" |
| 60 " }" | 60 " }" |
| 61 " ]" | 61 " ]" |
| 62 " }" | 62 " }" |
| 63 " ]" | 63 " ]" |
| 64 " }" | 64 " }" |
| 65 "]"), | 65 "]"), |
| 66 NULL); | 66 NULL); |
| 67 UpdateProviderPolicy(policy); | 67 UpdateProviderPolicy(policy); |
| 68 const base::Value* pref_value = NULL; | 68 const base::Value* pref_value = NULL; |
| 69 EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); | 69 EXPECT_TRUE( |
| 70 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); |
| 70 ASSERT_TRUE(pref_value); | 71 ASSERT_TRUE(pref_value); |
| 71 | 72 |
| 72 scoped_ptr<base::Value> expected( | 73 scoped_ptr<base::Value> expected( |
| 73 extensions::ListBuilder() | 74 extensions::ListBuilder() |
| 74 .Append(extensions::DictionaryBuilder() | 75 .Append(extensions::DictionaryBuilder() |
| 75 .Set("name", "Google") | 76 .Set("name", "Google") |
| 76 .Set("url", "http://google.com/")) | 77 .Set("url", "http://google.com/")) |
| 77 .Append(extensions::DictionaryBuilder() | 78 .Append(extensions::DictionaryBuilder() |
| 78 .Set("name", "Empty Folder") | 79 .Set("name", "Empty Folder") |
| 79 .Set("children", extensions::ListBuilder().Pass())) | 80 .Set("children", extensions::ListBuilder().Pass())) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 110 POLICY_SCOPE_USER, | 111 POLICY_SCOPE_USER, |
| 111 new base::StringValue( | 112 new base::StringValue( |
| 112 "[" | 113 "[" |
| 113 " {" | 114 " {" |
| 114 " \"name\": \"Google\"," | 115 " \"name\": \"Google\"," |
| 115 " \"url\": \"google.com\"" | 116 " \"url\": \"google.com\"" |
| 116 " }," | 117 " }," |
| 117 "]"), | 118 "]"), |
| 118 NULL); | 119 NULL); |
| 119 UpdateProviderPolicy(policy); | 120 UpdateProviderPolicy(policy); |
| 120 EXPECT_FALSE(store_->GetValue(prefs::kManagedBookmarks, NULL)); | 121 EXPECT_FALSE(store_->GetValue(bookmarks::prefs::kManagedBookmarks, NULL)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) { | 124 TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) { |
| 124 PolicyMap policy; | 125 PolicyMap policy; |
| 125 policy.Set(key::kManagedBookmarks, | 126 policy.Set(key::kManagedBookmarks, |
| 126 POLICY_LEVEL_MANDATORY, | 127 POLICY_LEVEL_MANDATORY, |
| 127 POLICY_SCOPE_USER, | 128 POLICY_SCOPE_USER, |
| 128 base::JSONReader::Read( | 129 base::JSONReader::Read( |
| 129 "[" | 130 "[" |
| 130 " {" | 131 " {" |
| 131 " \"name\": \"Google\"," | 132 " \"name\": \"Google\"," |
| 132 " \"unknown\": \"should be ignored\"," | 133 " \"unknown\": \"should be ignored\"," |
| 133 " \"url\": \"google.com\"" | 134 " \"url\": \"google.com\"" |
| 134 " }" | 135 " }" |
| 135 "]"), | 136 "]"), |
| 136 NULL); | 137 NULL); |
| 137 UpdateProviderPolicy(policy); | 138 UpdateProviderPolicy(policy); |
| 138 const base::Value* pref_value = NULL; | 139 const base::Value* pref_value = NULL; |
| 139 EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); | 140 EXPECT_TRUE( |
| 141 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); |
| 140 ASSERT_TRUE(pref_value); | 142 ASSERT_TRUE(pref_value); |
| 141 | 143 |
| 142 scoped_ptr<base::Value> expected( | 144 scoped_ptr<base::Value> expected( |
| 143 extensions::ListBuilder() | 145 extensions::ListBuilder() |
| 144 .Append(extensions::DictionaryBuilder() | 146 .Append(extensions::DictionaryBuilder() |
| 145 .Set("name", "Google") | 147 .Set("name", "Google") |
| 146 .Set("url", "http://google.com/")) | 148 .Set("url", "http://google.com/")) |
| 147 .Build()); | 149 .Build()); |
| 148 EXPECT_TRUE(pref_value->Equals(expected.get())); | 150 EXPECT_TRUE(pref_value->Equals(expected.get())); |
| 149 } | 151 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 168 " \"url\": \"?\"" | 170 " \"url\": \"?\"" |
| 169 " }," | 171 " }," |
| 170 " {" | 172 " {" |
| 171 " \"name\": \"Google\"," | 173 " \"name\": \"Google\"," |
| 172 " \"url\": \"google.com\"" | 174 " \"url\": \"google.com\"" |
| 173 " }" | 175 " }" |
| 174 "]"), | 176 "]"), |
| 175 NULL); | 177 NULL); |
| 176 UpdateProviderPolicy(policy); | 178 UpdateProviderPolicy(policy); |
| 177 const base::Value* pref_value = NULL; | 179 const base::Value* pref_value = NULL; |
| 178 EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); | 180 EXPECT_TRUE( |
| 181 store_->GetValue(bookmarks::prefs::kManagedBookmarks, &pref_value)); |
| 179 ASSERT_TRUE(pref_value); | 182 ASSERT_TRUE(pref_value); |
| 180 | 183 |
| 181 scoped_ptr<base::Value> expected( | 184 scoped_ptr<base::Value> expected( |
| 182 extensions::ListBuilder() | 185 extensions::ListBuilder() |
| 183 .Append(extensions::DictionaryBuilder() | 186 .Append(extensions::DictionaryBuilder() |
| 184 .Set("name", "Google") | 187 .Set("name", "Google") |
| 185 .Set("url", "http://google.com/")) | 188 .Set("url", "http://google.com/")) |
| 186 .Build()); | 189 .Build()); |
| 187 EXPECT_TRUE(pref_value->Equals(expected.get())); | 190 EXPECT_TRUE(pref_value->Equals(expected.get())); |
| 188 } | 191 } |
| 189 | 192 |
| 190 } // namespace policy | 193 } // namespace policy |
| OLD | NEW |