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 "chrome/browser/policy/profile_policy_connector.h" | 5 #include "chrome/browser/policy/profile_policy_connector.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/test/base/testing_browser_process.h" | 9 #include "chrome/test/base/testing_browser_process.h" |
10 #include "components/autofill/core/common/autofill_pref_names.h" | 10 #include "components/autofill/core/common/autofill_pref_names.h" |
11 #include "components/policy/core/browser/browser_policy_connector.h" | 11 #include "components/policy/core/browser/browser_policy_connector.h" |
12 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 12 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
13 #include "components/policy/core/common/cloud/cloud_policy_manager.h" | 13 #include "components/policy/core/common/cloud/cloud_policy_manager.h" |
14 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 14 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
15 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 15 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
16 #include "components/policy/core/common/policy_bundle.h" | 16 #include "components/policy/core/common/policy_bundle.h" |
17 #include "components/policy/core/common/policy_map.h" | 17 #include "components/policy/core/common/policy_map.h" |
18 #include "components/policy/core/common/policy_service.h" | 18 #include "components/policy/core/common/policy_service.h" |
19 #include "components/policy/core/common/policy_types.h" | |
20 #include "components/policy/core/common/schema_registry.h" | 19 #include "components/policy/core/common/schema_registry.h" |
21 #include "policy/policy_constants.h" | 20 #include "policy/policy_constants.h" |
22 #include "policy/proto/device_management_backend.pb.h" | 21 #include "policy/proto/device_management_backend.pb.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
25 | 24 |
26 using testing::Return; | 25 using testing::Return; |
27 using testing::_; | 26 using testing::_; |
28 | 27 |
29 namespace policy { | 28 namespace policy { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 EXPECT_FALSE( | 90 EXPECT_FALSE( |
92 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled)); | 91 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled)); |
93 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string()); | 92 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string()); |
94 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue( | 93 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue( |
95 key::kAutoFillEnabled)); | 94 key::kAutoFillEnabled)); |
96 | 95 |
97 // Set the policy at the cloud provider. | 96 // Set the policy at the cloud provider. |
98 cloud_policy_store_.policy_map_.Set(key::kAutoFillEnabled, | 97 cloud_policy_store_.policy_map_.Set(key::kAutoFillEnabled, |
99 POLICY_LEVEL_MANDATORY, | 98 POLICY_LEVEL_MANDATORY, |
100 POLICY_SCOPE_USER, | 99 POLICY_SCOPE_USER, |
101 POLICY_SOURCE_CLOUD, | |
102 new base::FundamentalValue(false), | 100 new base::FundamentalValue(false), |
103 nullptr); | 101 nullptr); |
104 cloud_policy_store_.NotifyStoreLoaded(); | 102 cloud_policy_store_.NotifyStoreLoaded(); |
105 base::RunLoop().RunUntilIdle(); | 103 base::RunLoop().RunUntilIdle(); |
106 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); | 104 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); |
107 const base::Value* value = | 105 const base::Value* value = |
108 connector.policy_service()->GetPolicies(chrome_ns).GetValue( | 106 connector.policy_service()->GetPolicies(chrome_ns).GetValue( |
109 key::kAutoFillEnabled); | 107 key::kAutoFillEnabled); |
110 ASSERT_TRUE(value); | 108 ASSERT_TRUE(value); |
111 EXPECT_TRUE(base::FundamentalValue(false).Equals(value)); | 109 EXPECT_TRUE(base::FundamentalValue(false).Equals(value)); |
112 | 110 |
113 // Now test with a higher-priority provider also setting the policy. | 111 // Now test with a higher-priority provider also setting the policy. |
114 PolicyMap map; | 112 PolicyMap map; |
115 map.Set(key::kAutoFillEnabled, | 113 map.Set(key::kAutoFillEnabled, |
116 POLICY_LEVEL_MANDATORY, | 114 POLICY_LEVEL_MANDATORY, |
117 POLICY_SCOPE_USER, | 115 POLICY_SCOPE_USER, |
118 POLICY_SOURCE_CLOUD, | |
119 new base::FundamentalValue(true), | 116 new base::FundamentalValue(true), |
120 nullptr); | 117 nullptr); |
121 mock_provider_.UpdateChromePolicy(map); | 118 mock_provider_.UpdateChromePolicy(map); |
122 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); | 119 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); |
123 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue( | 120 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue( |
124 key::kAutoFillEnabled); | 121 key::kAutoFillEnabled); |
125 ASSERT_TRUE(value); | 122 ASSERT_TRUE(value); |
126 EXPECT_TRUE(base::FundamentalValue(true).Equals(value)); | 123 EXPECT_TRUE(base::FundamentalValue(true).Equals(value)); |
127 | 124 |
128 // Cleanup. | 125 // Cleanup. |
129 connector.Shutdown(); | 126 connector.Shutdown(); |
130 } | 127 } |
131 | 128 |
132 } // namespace policy | 129 } // namespace policy |
OLD | NEW |