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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/prefs/pref_value_map.h" | 6 #include "base/prefs/pref_value_map.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/policy/core/browser/policy_error_map.h" | 8 #include "components/policy/core/browser/policy_error_map.h" |
9 #include "components/policy/core/browser/url_blacklist_policy_handler.h" | 9 #include "components/policy/core/browser/url_blacklist_policy_handler.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_pref_names.h" | 11 #include "components/policy/core/common/policy_pref_names.h" |
12 #include "components/policy/core/common/policy_types.h" | |
13 #include "policy/policy_constants.h" | 12 #include "policy/policy_constants.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 | 14 |
16 // Note: this file should move to components/policy/core/browser, but the | 15 // Note: this file should move to components/policy/core/browser, but the |
17 // components_unittests runner does not load the ResourceBundle as | 16 // components_unittests runner does not load the ResourceBundle as |
18 // ChromeTestSuite::Initialize does, which leads to failures using | 17 // ChromeTestSuite::Initialize does, which leads to failures using |
19 // PolicyErrorMap. | 18 // PolicyErrorMap. |
20 | 19 |
21 namespace policy { | 20 namespace policy { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 const char kTestDisabledScheme[] = "kTestDisabledScheme"; | 24 const char kTestDisabledScheme[] = "kTestDisabledScheme"; |
26 const char kTestBlacklistValue[] = "kTestBlacklistValue"; | 25 const char kTestBlacklistValue[] = "kTestBlacklistValue"; |
27 | 26 |
28 } // namespace | 27 } // namespace |
29 | 28 |
30 class URLBlacklistPolicyHandlerTest : public testing::Test { | 29 class URLBlacklistPolicyHandlerTest : public testing::Test { |
31 protected: | 30 protected: |
32 void SetPolicy(const std::string& key, base::Value* value) { | 31 void SetPolicy(const std::string& key, base::Value* value) { |
33 policies_.Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 32 policies_.Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value, NULL); |
34 POLICY_SOURCE_CLOUD, value, nullptr); | |
35 } | 33 } |
36 bool CheckPolicy(const std::string& key, base::Value* value) { | 34 bool CheckPolicy(const std::string& key, base::Value* value) { |
37 SetPolicy(key, value); | 35 SetPolicy(key, value); |
38 return handler_.CheckPolicySettings(policies_, &errors_); | 36 return handler_.CheckPolicySettings(policies_, &errors_); |
39 } | 37 } |
40 void ApplyPolicies() { | 38 void ApplyPolicies() { |
41 handler_.ApplyPolicySettings(policies_, &prefs_); | 39 handler_.ApplyPolicySettings(policies_, &prefs_); |
42 } | 40 } |
43 | 41 |
44 URLBlacklistPolicyHandler handler_; | 42 URLBlacklistPolicyHandler handler_; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 std::string out1; | 210 std::string out1; |
213 EXPECT_TRUE(out_list->GetString(0U, &out1)); | 211 EXPECT_TRUE(out_list->GetString(0U, &out1)); |
214 EXPECT_EQ(kTestDisabledScheme + std::string("://*"), out1); | 212 EXPECT_EQ(kTestDisabledScheme + std::string("://*"), out1); |
215 | 213 |
216 std::string out2; | 214 std::string out2; |
217 EXPECT_TRUE(out_list->GetString(1U, &out2)); | 215 EXPECT_TRUE(out_list->GetString(1U, &out2)); |
218 EXPECT_EQ(kTestBlacklistValue, out2); | 216 EXPECT_EQ(kTestBlacklistValue, out2); |
219 } | 217 } |
220 | 218 |
221 } // namespace policy | 219 } // namespace policy |
OLD | NEW |