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

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

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years 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
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 "chrome/browser/policy/configuration_policy_pref_store_unittest.h"
6
7 #include <string> 5 #include <string>
8 6
9 #include "base/callback.h" 7 #include "base/callback.h"
10 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
11 #include "base/prefs/pref_store_observer_mock.h" 9 #include "base/prefs/pref_store_observer_mock.h"
12 #include "base/run_loop.h" 10 #include "base/run_loop.h"
13 #include "chrome/browser/policy/configuration_policy_handler.h" 11 #include "chrome/browser/policy/configuration_policy_pref_store_test.h"
14 #include "chrome/browser/policy/configuration_policy_pref_store.h" 12 #include "components/policy/core/browser/configuration_policy_handler.h"
15 #include "chrome/browser/policy/policy_service_impl.h" 13 #include "components/policy/core/browser/configuration_policy_pref_store.h"
16 #include "components/policy/core/common/external_data_fetcher.h" 14 #include "components/policy/core/common/external_data_fetcher.h"
17 #include "components/policy/core/common/policy_details.h" 15 #include "components/policy/core/common/policy_details.h"
18 #include "components/policy/core/common/policy_map.h" 16 #include "components/policy/core/common/policy_map.h"
19 #include "components/policy/core/common/policy_pref_names.h" 17 #include "components/policy/core/common/policy_pref_names.h"
18 #include "components/policy/core/common/policy_service_impl.h"
20 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
21 20
21 // Note: this file should move to components/policy/core/browser, but the
22 // components_unittests runner does not load the ResourceBundle as
23 // ChromeTestSuite::Initialize does, which leads to failures using
24 // PolicyErrorMap.
25
22 using testing::Mock; 26 using testing::Mock;
23 using testing::Return; 27 using testing::Return;
24 using testing::_; 28 using testing::_;
25 29
26 namespace { 30 namespace {
31
27 const char kTestPolicy[] = "test.policy"; 32 const char kTestPolicy[] = "test.policy";
28 const char kTestPref[] = "test.pref"; 33 const char kTestPref[] = "test.pref";
34
29 } // namespace 35 } // namespace
30 36
31 namespace policy { 37 namespace policy {
32 38
33 // Holds a set of test parameters, consisting of pref name and policy name.
34 class PolicyAndPref {
35 public:
36 PolicyAndPref(const char* policy_name, const char* pref_name)
37 : policy_name_(policy_name),
38 pref_name_(pref_name) {}
39
40 const char* policy_name() const { return policy_name_; }
41 const char* pref_name() const { return pref_name_; }
42
43 private:
44 const char* policy_name_;
45 const char* pref_name_;
46 };
47
48 ConfigurationPolicyPrefStoreTest::ConfigurationPolicyPrefStoreTest()
49 : handler_list_(GetChromePolicyDetailsCallback()) {
50 EXPECT_CALL(provider_, IsInitializationComplete(_))
51 .WillRepeatedly(Return(false));
52 provider_.Init();
53 providers_.push_back(&provider_);
54 policy_service_.reset(new PolicyServiceImpl(
55 providers_, PolicyServiceImpl::PreprocessCallback()));
56 store_ = new ConfigurationPolicyPrefStore(
57 policy_service_.get(), &handler_list_, POLICY_LEVEL_MANDATORY);
58 }
59
60 ConfigurationPolicyPrefStoreTest::~ConfigurationPolicyPrefStoreTest() {}
61
62 void ConfigurationPolicyPrefStoreTest::TearDown() {
63 provider_.Shutdown();
64 }
65
66 void ConfigurationPolicyPrefStoreTest::UpdateProviderPolicy(
67 const PolicyMap& policy) {
68 provider_.UpdateChromePolicy(policy);
69 base::RunLoop loop;
70 loop.RunUntilIdle();
71 }
72
73 // Test cases for list-valued policy settings. 39 // Test cases for list-valued policy settings.
74 class ConfigurationPolicyPrefStoreListTest 40 class ConfigurationPolicyPrefStoreListTest
75 : public ConfigurationPolicyPrefStoreTest { 41 : public ConfigurationPolicyPrefStoreTest {
76 virtual void SetUp() OVERRIDE { 42 virtual void SetUp() OVERRIDE {
77 handler_list_.AddHandler( 43 handler_list_.AddHandler(
78 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( 44 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler(
79 kTestPolicy, kTestPref, base::Value::TYPE_LIST))); 45 kTestPolicy, kTestPref, base::Value::TYPE_LIST)));
80 } 46 }
81 }; 47 };
82 48
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME)) 204 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME))
239 .WillRepeatedly(Return(true)); 205 .WillRepeatedly(Return(true));
240 EXPECT_CALL(observer_, OnInitializationCompleted(true)).Times(1); 206 EXPECT_CALL(observer_, OnInitializationCompleted(true)).Times(1);
241 PolicyMap policy; 207 PolicyMap policy;
242 UpdateProviderPolicy(policy); 208 UpdateProviderPolicy(policy);
243 Mock::VerifyAndClearExpectations(&observer_); 209 Mock::VerifyAndClearExpectations(&observer_);
244 EXPECT_TRUE(store_->IsInitializationComplete()); 210 EXPECT_TRUE(store_->IsInitializationComplete());
245 } 211 }
246 212
247 } // namespace policy 213 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698