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

Side by Side Diff: components/policy/core/browser/configuration_policy_handler_unittest.cc

Issue 309553011: Enable policy support for registering protocol handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Issue_116119_pre
Patch Set: Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/callback.h" 5 #include "base/callback.h"
6 #include "base/json/json_reader.h" 6 #include "base/json/json_reader.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_value_map.h" 8 #include "base/prefs/pref_value_map.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/policy/core/browser/configuration_policy_handler.h" 10 #include "components/policy/core/browser/configuration_policy_handler.h"
11 #include "components/policy/core/browser/policy_error_map.h" 11 #include "components/policy/core/browser/policy_error_map.h"
12 #include "components/policy/core/common/policy_map.h" 12 #include "components/policy/core/common/policy_map.h"
13 #include "components/policy/core/common/schema.h" 13 #include "components/policy/core/common/schema.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace policy { 16 namespace policy {
17 17
18 namespace { 18 namespace {
19 19
20 StringToIntEnumListPolicyHandler::MappingEntry kTestTypeMap[] = { 20 StringToIntEnumListPolicyHandler::MappingEntry kTestTypeMap[] = {
21 { "one", 1 }, 21 { "one", 1 },
22 { "two", 2 }, 22 { "two", 2 },
23 }; 23 };
24 24
25 const char kTestPolicy[] = "unit_test.test_policy"; 25 const char kTestPolicy[] = "unit_test.test_policy";
26 const char kTestPref[] = "unit_test.test_pref"; 26 const char kTestPref[] = "unit_test.test_pref";
27 27
28 class SimpleSchemaValidatingPolicyHandler 28 class TestSchemaValidatingPolicyHandler : public SchemaValidatingPolicyHandler {
29 : public SchemaValidatingPolicyHandler {
30 public: 29 public:
31 SimpleSchemaValidatingPolicyHandler(const Schema& schema, 30 TestSchemaValidatingPolicyHandler(const Schema& schema,
32 SchemaOnErrorStrategy strategy) 31 SchemaOnErrorStrategy strategy)
33 : SchemaValidatingPolicyHandler("PolicyForTesting", schema, strategy) {} 32 : SchemaValidatingPolicyHandler("PolicyForTesting", schema, strategy) {}
34 virtual ~SimpleSchemaValidatingPolicyHandler() {} 33 virtual ~TestSchemaValidatingPolicyHandler() {}
35 34
36 virtual void ApplyPolicySettings(const policy::PolicyMap&, 35 virtual void ApplyPolicySettings(const policy::PolicyMap&,
37 PrefValueMap*) OVERRIDE { 36 PrefValueMap*) OVERRIDE {
38 } 37 }
39 38
40 bool CheckAndGetValueForTest(const PolicyMap& policies, 39 bool CheckAndGetValueForTest(const PolicyMap& policies,
41 scoped_ptr<base::Value>* value) { 40 scoped_ptr<base::Value>* value) {
42 return SchemaValidatingPolicyHandler::CheckAndGetValue( 41 return SchemaValidatingPolicyHandler::CheckAndGetValue(
43 policies, NULL, value); 42 policies, NULL, value);
44 } 43 }
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 kPolicyMapJson, base::JSON_PARSE_RFC, NULL, &error)); 535 kPolicyMapJson, base::JSON_PARSE_RFC, NULL, &error));
537 ASSERT_TRUE(policy_map_value) << error; 536 ASSERT_TRUE(policy_map_value) << error;
538 537
539 const base::DictionaryValue* policy_map_dict = NULL; 538 const base::DictionaryValue* policy_map_dict = NULL;
540 ASSERT_TRUE(policy_map_value->GetAsDictionary(&policy_map_dict)); 539 ASSERT_TRUE(policy_map_value->GetAsDictionary(&policy_map_dict));
541 540
542 PolicyMap policy_map; 541 PolicyMap policy_map;
543 policy_map.LoadFrom( 542 policy_map.LoadFrom(
544 policy_map_dict, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); 543 policy_map_dict, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER);
545 544
546 SimpleSchemaValidatingPolicyHandler handler(schema, SCHEMA_ALLOW_INVALID); 545 TestSchemaValidatingPolicyHandler handler(schema, SCHEMA_ALLOW_INVALID);
547 scoped_ptr<base::Value> output_value; 546 scoped_ptr<base::Value> output_value;
548 ASSERT_TRUE(handler.CheckAndGetValueForTest(policy_map, &output_value)); 547 ASSERT_TRUE(handler.CheckAndGetValueForTest(policy_map, &output_value));
549 ASSERT_TRUE(output_value); 548 ASSERT_TRUE(output_value);
550 549
551 base::DictionaryValue* dict = NULL; 550 base::DictionaryValue* dict = NULL;
552 ASSERT_TRUE(output_value->GetAsDictionary(&dict)); 551 ASSERT_TRUE(output_value->GetAsDictionary(&dict));
553 552
554 // Test that CheckAndGetValue() actually dropped invalid properties. 553 // Test that CheckAndGetValue() actually dropped invalid properties.
555 int int_value = -1; 554 int int_value = -1;
556 EXPECT_TRUE(dict->GetInteger("OneToThree", &int_value)); 555 EXPECT_TRUE(dict->GetInteger("OneToThree", &int_value));
557 EXPECT_EQ(2, int_value); 556 EXPECT_EQ(2, int_value);
558 EXPECT_FALSE(dict->HasKey("Colors")); 557 EXPECT_FALSE(dict->HasKey("Colors"));
559 } 558 }
560 559
561 } // namespace policy 560 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698