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

Side by Side Diff: components/policy/core/common/config_dir_policy_loader_unittest.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
13 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
14 #include "base/values.h" 12 #include "base/values.h"
15 #include "components/policy/core/common/async_policy_provider.h" 13 #include "components/policy/core/common/async_policy_provider.h"
16 #include "components/policy/core/common/config_dir_policy_loader.h" 14 #include "components/policy/core/common/config_dir_policy_loader.h"
17 #include "components/policy/core/common/configuration_policy_provider_test.h" 15 #include "components/policy/core/common/configuration_policy_provider_test.h"
18 #include "components/policy/core/common/policy_bundle.h" 16 #include "components/policy/core/common/policy_bundle.h"
19 #include "components/policy/core/common/policy_map.h" 17 #include "components/policy/core/common/policy_map.h"
20 18
21 namespace policy { 19 namespace policy {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 PolicyTestBase::SetUp(); 175 PolicyTestBase::SetUp();
178 harness_.SetUp(); 176 harness_.SetUp();
179 } 177 }
180 178
181 TestHarness harness_; 179 TestHarness harness_;
182 }; 180 };
183 181
184 // The preferences dictionary is expected to be empty when there are no files to 182 // The preferences dictionary is expected to be empty when there are no files to
185 // load. 183 // load.
186 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) { 184 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) {
187 ConfigDirPolicyLoader loader( 185 ConfigDirPolicyLoader loader(loop_.task_runner(), harness_.test_dir(),
188 loop_.message_loop_proxy(), harness_.test_dir(), POLICY_SCOPE_MACHINE); 186 POLICY_SCOPE_MACHINE);
189 scoped_ptr<PolicyBundle> bundle(loader.Load()); 187 scoped_ptr<PolicyBundle> bundle(loader.Load());
190 ASSERT_TRUE(bundle.get()); 188 ASSERT_TRUE(bundle.get());
191 const PolicyBundle kEmptyBundle; 189 const PolicyBundle kEmptyBundle;
192 EXPECT_TRUE(bundle->Equals(kEmptyBundle)); 190 EXPECT_TRUE(bundle->Equals(kEmptyBundle));
193 } 191 }
194 192
195 // Reading from a non-existent directory should result in an empty preferences 193 // Reading from a non-existent directory should result in an empty preferences
196 // dictionary. 194 // dictionary.
197 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) { 195 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) {
198 base::FilePath non_existent_dir( 196 base::FilePath non_existent_dir(
199 harness_.test_dir().Append(FILE_PATH_LITERAL("not_there"))); 197 harness_.test_dir().Append(FILE_PATH_LITERAL("not_there")));
200 ConfigDirPolicyLoader loader( 198 ConfigDirPolicyLoader loader(loop_.task_runner(), non_existent_dir,
201 loop_.message_loop_proxy(), non_existent_dir, POLICY_SCOPE_MACHINE); 199 POLICY_SCOPE_MACHINE);
202 scoped_ptr<PolicyBundle> bundle(loader.Load()); 200 scoped_ptr<PolicyBundle> bundle(loader.Load());
203 ASSERT_TRUE(bundle.get()); 201 ASSERT_TRUE(bundle.get());
204 const PolicyBundle kEmptyBundle; 202 const PolicyBundle kEmptyBundle;
205 EXPECT_TRUE(bundle->Equals(kEmptyBundle)); 203 EXPECT_TRUE(bundle->Equals(kEmptyBundle));
206 } 204 }
207 205
208 // Test merging values from different files. 206 // Test merging values from different files.
209 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { 207 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
210 // Write a bunch of data files in order to increase the chance to detect the 208 // Write a bunch of data files in order to increase the chance to detect the
211 // provider not respecting lexicographic ordering when reading them. Since the 209 // provider not respecting lexicographic ordering when reading them. Since the
212 // filesystem may return files in arbitrary order, there is no way to be sure, 210 // filesystem may return files in arbitrary order, there is no way to be sure,
213 // but this is better than nothing. 211 // but this is better than nothing.
214 base::DictionaryValue test_dict_bar; 212 base::DictionaryValue test_dict_bar;
215 test_dict_bar.SetString("HomepageLocation", "http://bar.com"); 213 test_dict_bar.SetString("HomepageLocation", "http://bar.com");
216 for (unsigned int i = 1; i <= 4; ++i) 214 for (unsigned int i = 1; i <= 4; ++i)
217 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i)); 215 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
218 base::DictionaryValue test_dict_foo; 216 base::DictionaryValue test_dict_foo;
219 test_dict_foo.SetString("HomepageLocation", "http://foo.com"); 217 test_dict_foo.SetString("HomepageLocation", "http://foo.com");
220 harness_.WriteConfigFile(test_dict_foo, "9"); 218 harness_.WriteConfigFile(test_dict_foo, "9");
221 for (unsigned int i = 5; i <= 8; ++i) 219 for (unsigned int i = 5; i <= 8; ++i)
222 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i)); 220 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
223 221
224 ConfigDirPolicyLoader loader( 222 ConfigDirPolicyLoader loader(loop_.task_runner(), harness_.test_dir(),
225 loop_.message_loop_proxy(), harness_.test_dir(), POLICY_SCOPE_USER); 223 POLICY_SCOPE_USER);
226 scoped_ptr<PolicyBundle> bundle(loader.Load()); 224 scoped_ptr<PolicyBundle> bundle(loader.Load());
227 ASSERT_TRUE(bundle.get()); 225 ASSERT_TRUE(bundle.get());
228 PolicyBundle expected_bundle; 226 PolicyBundle expected_bundle;
229 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 227 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
230 .LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); 228 .LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
231 EXPECT_TRUE(bundle->Equals(expected_bundle)); 229 EXPECT_TRUE(bundle->Equals(expected_bundle));
232 } 230 }
233 231
234 } // namespace policy 232 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698