Chromium Code Reviews| Index: chrome/browser/policy/managed_bookmarks_policy_handler_unittest.cc |
| diff --git a/chrome/browser/policy/managed_bookmarks_policy_handler_unittest.cc b/chrome/browser/policy/managed_bookmarks_policy_handler_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cbddd5c71567f1481d87b92538f8a90ca2a3100d |
| --- /dev/null |
| +++ b/chrome/browser/policy/managed_bookmarks_policy_handler_unittest.cc |
| @@ -0,0 +1,188 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/json/json_reader.h" |
| +#include "chrome/browser/policy/managed_bookmarks_policy_handler.h" |
| +#include "components/bookmarks/common/bookmark_pref_names.h" |
| +#include "components/policy/core/browser/configuration_policy_pref_store.h" |
| +#include "components/policy/core/browser/configuration_policy_pref_store_test.h" |
| +#include "components/policy/core/common/policy_map.h" |
| +#include "components/policy/core/common/schema.h" |
| +#include "extensions/common/value_builder.h" |
| +#include "policy/policy_constants.h" |
| + |
| +namespace policy { |
| + |
| +class ManagedBookmarksPolicyHandlerTest |
| + : public ConfigurationPolicyPrefStoreTest { |
| + virtual void SetUp() OVERRIDE { |
| + Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); |
| + handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>( |
| + new ManagedBookmarksPolicyHandler(chrome_schema))); |
| + } |
| +}; |
| + |
| +TEST_F(ManagedBookmarksPolicyHandlerTest, ApplyPolicySettings) { |
| + EXPECT_FALSE(store_->GetValue(prefs::kManagedBookmarks, NULL)); |
| + |
| + PolicyMap policy; |
| + policy.Set(key::kManagedBookmarks, |
| + POLICY_LEVEL_MANDATORY, |
| + POLICY_SCOPE_USER, |
| + base::JSONReader::Read( |
| + "[" |
| + " {" |
| + " \"name\": \"Google\"," |
| + " \"url\": \"google.com\"" |
| + " }," |
| + " {" |
| + " \"name\": \"Empty Folder\"," |
| + " \"children\": []" |
| + " }," |
| + " {" |
| + " \"name\": \"Big Folder\"," |
| + " \"children\": [" |
| + " {" |
| + " \"name\": \"Youtube\"," |
| + " \"url\": \"youtube.com\"" |
| + " }," |
| + " {" |
| + " \"name\": \"Chromium\"," |
| + " \"url\": \"chromium.org\"" |
| + " }," |
| + " {" |
| + " \"name\": \"More Stuff\"," |
| + " \"children\": [" |
| + " {" |
| + " \"name\": \"Bugs\"," |
| + " \"url\": \"crbug.com\"" |
| + " }" |
| + " ]" |
| + " }" |
| + " ]" |
| + " }" |
| + "]"), |
| + NULL); |
| + UpdateProviderPolicy(policy); |
| + const base::Value* pref_value = NULL; |
| + EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); |
| + ASSERT_TRUE(pref_value); |
| + |
| + scoped_ptr<base::Value> expected( |
| + extensions::ListBuilder() |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Google") |
| + .Set("url", "http://google.com/")) |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Empty Folder") |
| + .Set("children", extensions::ListBuilder().Pass())) |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Big Folder") |
| + .Set("children", extensions::ListBuilder() |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Youtube") |
| + .Set("url", "http://youtube.com/")) |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Chromium") |
| + .Set("url", "http://chromium.org/")) |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "More Stuff") |
| + .Set("children", extensions::ListBuilder() |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Bugs") |
| + .Set("url", "http://crbug.com/") |
| + .Pass()) |
| + .Pass()) |
| + .Pass()) |
| + .Pass()) |
| + .Pass()) |
| + .Build()); |
| + EXPECT_TRUE(pref_value->Equals(expected.get())); |
| +} |
| + |
| +TEST_F(ManagedBookmarksPolicyHandlerTest, WrongType) { |
|
pastarmovj
2014/05/30 14:07:13
Please change this to WrongPolicyType
Joao da Silva
2014/05/30 20:54:35
Done.
|
| + PolicyMap policy; |
| + policy.Set(key::kManagedBookmarks, |
| + POLICY_LEVEL_MANDATORY, |
| + POLICY_SCOPE_USER, |
| + new base::StringValue( |
| + "[" |
| + " {" |
| + " \"name\": \"Google\"," |
| + " \"url\": \"google.com\"" |
| + " }," |
| + "]"), |
| + NULL); |
| + UpdateProviderPolicy(policy); |
| + EXPECT_FALSE(store_->GetValue(prefs::kManagedBookmarks, NULL)); |
| +} |
| + |
| +TEST_F(ManagedBookmarksPolicyHandlerTest, UnknownKeys) { |
| + PolicyMap policy; |
| + policy.Set(key::kManagedBookmarks, |
| + POLICY_LEVEL_MANDATORY, |
| + POLICY_SCOPE_USER, |
| + base::JSONReader::Read( |
| + "[" |
| + " {" |
| + " \"name\": \"Google\"," |
| + " \"unknown\": \"should be ignored\"," |
| + " \"url\": \"google.com\"" |
| + " }" |
| + "]"), |
| + NULL); |
| + UpdateProviderPolicy(policy); |
| + const base::Value* pref_value = NULL; |
| + EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); |
| + ASSERT_TRUE(pref_value); |
| + |
| + scoped_ptr<base::Value> expected( |
| + extensions::ListBuilder() |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Google") |
| + .Set("url", "http://google.com/")) |
| + .Build()); |
| + EXPECT_TRUE(pref_value->Equals(expected.get())); |
| +} |
| + |
| +TEST_F(ManagedBookmarksPolicyHandlerTest, BadBookmark) { |
| + PolicyMap policy; |
| + policy.Set(key::kManagedBookmarks, |
| + POLICY_LEVEL_MANDATORY, |
| + POLICY_SCOPE_USER, |
| + base::JSONReader::Read( |
| + "[" |
| + " {" |
| + " \"name\": \"Empty\"," |
| + " \"url\": \"\"" |
| + " }," |
| + " {" |
| + " \"name\": \"Invalid type\"," |
| + " \"url\": 4" |
| + " }," |
| + " {" |
| + " \"name\": \"Invalid URL\"," |
| + " \"url\": \"?\"" |
| + " }," |
| + " {" |
| + " \"name\": \"Google\"," |
| + " \"url\": \"google.com\"" |
| + " }" |
| + "]"), |
| + NULL); |
| + UpdateProviderPolicy(policy); |
| + const base::Value* pref_value = NULL; |
| + EXPECT_TRUE(store_->GetValue(prefs::kManagedBookmarks, &pref_value)); |
| + ASSERT_TRUE(pref_value); |
| + |
| + scoped_ptr<base::Value> expected( |
| + extensions::ListBuilder() |
| + .Append(extensions::DictionaryBuilder() |
| + .Set("name", "Google") |
| + .Set("url", "http://google.com/")) |
| + .Build()); |
| + EXPECT_TRUE(pref_value->Equals(expected.get())); |
| +} |
| + |
| +} // namespace policy |