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

Side by Side Diff: chrome/browser/policy/configuration_policy_provider_test.cc

Issue 8467011: Include only policy definitions that apply to the platfrom in the policy definition list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust all policy provider tests to use shared testing code. Net-negative line counts! Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/configuration_policy_provider_test.h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "chrome/browser/policy/asynchronous_policy_loader.h"
10 #include "chrome/browser/policy/asynchronous_policy_provider.h"
11 #include "chrome/browser/policy/configuration_policy_provider.h"
12 #include "chrome/browser/policy/policy_map.h"
13 #include "policy/policy_constants.h"
14
15 namespace policy {
16
17 namespace test_policy_definitions {
18
19 const char kKeyString[] = "StringPolicy";
20 const char kKeyBoolean[] = "BooleanPolicy";
21 const char kKeyInteger[] = "IntegerPolicy";
22 const char kKeyStringList[] = "StringListPolicy";
23
24 // In order to have correct enum values, we alias these to some actual policies.
25 extern const ConfigurationPolicyType kPolicyString =
Joao da Silva 2011/11/09 15:37:47 Nit: remove extern here and on the 3 next too
Mattias Nissler (ping if slow) 2011/11/09 17:04:11 Done.
26 kPolicyHomepageLocation;
27 extern const ConfigurationPolicyType kPolicyBoolean =
28 kPolicyHomepageIsNewTabPage;
29 extern const ConfigurationPolicyType kPolicyInteger =
30 kPolicyRestoreOnStartup;
31 extern const ConfigurationPolicyType kPolicyStringList =
32 kPolicyRestoreOnStartupURLs;
33
34 static const PolicyDefinitionList::Entry kEntries[] = {
Joao da Silva 2011/11/09 15:37:47 Nit: not sure if we prefer an anonymous namespace
Mattias Nissler (ping if slow) 2011/11/09 17:04:11 I think the additional noise generated by the anon
35 { kPolicyString, base::Value::TYPE_STRING, kKeyString },
36 { kPolicyBoolean, base::Value::TYPE_BOOLEAN, kKeyBoolean },
37 { kPolicyInteger, base::Value::TYPE_INTEGER, kKeyInteger },
38 { kPolicyStringList, base::Value::TYPE_LIST, kKeyStringList },
39 };
40
41 const PolicyDefinitionList kList = {
42 kEntries, kEntries + arraysize(kEntries)
43 };
44
45 } // namespace test_policy_definitions
46
47 PolicyProviderTestHarness::PolicyProviderTestHarness() {}
48
49 PolicyProviderTestHarness::~PolicyProviderTestHarness() {}
50
51 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest()
52 : ui_thread_(content::BrowserThread::UI, &loop_),
53 file_thread_(content::BrowserThread::FILE, &loop_) {}
54
55 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {}
56
57 void ConfigurationPolicyProviderTest::SetUp() {
58 test_harness_.reset((*GetParam())());
59 test_harness_->SetUp();
60
61 provider_.reset(
62 test_harness_->CreateProvider(&test_policy_definitions::kList));
63
64 PolicyMap policy_map;
65 EXPECT_TRUE(provider_->Provide(&policy_map));
66 EXPECT_TRUE(policy_map.empty());
67 }
68
69 void ConfigurationPolicyProviderTest::TearDown() {
70 // Give providers the chance to clean up after themselves on the file thread.
71 provider_.reset();
72 loop_.RunAllPending();
73 }
74
75 void ConfigurationPolicyProviderTest::CheckValue(
76 const char* policy_name,
77 ConfigurationPolicyType policy_type,
78 const base::Value& expected_value,
79 base::Closure install_value) {
80 // Install the value, reload policy and check the provider for the value.
81 install_value.Run();
82 provider_->ForceReload();
83 loop_.RunAllPending();
84 PolicyMap policy_map;
85 EXPECT_TRUE(provider_->Provide(&policy_map));
86 EXPECT_EQ(1U, policy_map.size());
87 EXPECT_TRUE(base::Value::Equals(&expected_value,
88 policy_map.Get(policy_type)));
89 }
90
91 TEST_P(ConfigurationPolicyProviderTest, Empty) {
92 provider_->ForceReload();
93 loop_.RunAllPending();
94 PolicyMap policy_map;
95 EXPECT_TRUE(provider_->Provide(&policy_map));
96 EXPECT_TRUE(policy_map.empty());
97 }
98
99 TEST_P(ConfigurationPolicyProviderTest, StringValue) {
100 const char kTestString[] = "string_value";
101 StringValue expected_value(kTestString);
102 CheckValue(test_policy_definitions::kKeyString,
103 test_policy_definitions::kPolicyString,
104 expected_value,
105 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy,
106 base::Unretained(test_harness_.get()),
107 test_policy_definitions::kKeyString,
108 kTestString));
109 }
110
111 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) {
112 base::FundamentalValue expected_value(true);
113 CheckValue(test_policy_definitions::kKeyBoolean,
114 test_policy_definitions::kPolicyBoolean,
115 expected_value,
116 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy,
117 base::Unretained(test_harness_.get()),
118 test_policy_definitions::kKeyBoolean,
119 true));
120 }
121
122 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) {
123 base::FundamentalValue expected_value(42);
124 CheckValue(test_policy_definitions::kKeyInteger,
125 test_policy_definitions::kPolicyInteger,
126 expected_value,
127 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy,
128 base::Unretained(test_harness_.get()),
129 test_policy_definitions::kKeyInteger,
130 42));
131 }
132
133 TEST_P(ConfigurationPolicyProviderTest, StringListValue) {
134 base::ListValue expected_value;
135 expected_value.Set(0U, base::Value::CreateStringValue("first"));
136 expected_value.Set(1U, base::Value::CreateStringValue("second"));
137 CheckValue(test_policy_definitions::kKeyStringList,
138 test_policy_definitions::kPolicyStringList,
139 expected_value,
140 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy,
141 base::Unretained(test_harness_.get()),
142 test_policy_definitions::kKeyStringList,
143 &expected_value));
144 }
145
146 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698