OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/memory/ptr_util.h" |
9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 12 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
16 #include "components/policy/core/browser/browser_policy_connector.h" | 17 #include "components/policy/core/browser/browser_policy_connector.h" |
17 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 18 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
18 #include "components/policy/core/common/policy_map.h" | 19 #include "components/policy/core/common/policy_map.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 EXPECT_FALSE(observer.last_seen_value); | 173 EXPECT_FALSE(observer.last_seen_value); |
173 } | 174 } |
174 | 175 |
175 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, | 176 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, |
176 IgnoreLocalChangesToManagedPrefs) { | 177 IgnoreLocalChangesToManagedPrefs) { |
177 TestSyncedPrefObserver observer = {}; | 178 TestSyncedPrefObserver observer = {}; |
178 registrar()->Add(prefs::kShowHomeButton, | 179 registrar()->Add(prefs::kShowHomeButton, |
179 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); | 180 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); |
180 | 181 |
181 policy::PolicyMap policies; | 182 policy::PolicyMap policies; |
182 policies.Set(policy::key::kShowHomeButton, | 183 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, |
183 policy::POLICY_LEVEL_MANDATORY, | 184 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
184 policy::POLICY_SCOPE_USER, | 185 base::WrapUnique(new base::FundamentalValue(true)), nullptr); |
185 policy::POLICY_SOURCE_CLOUD, | |
186 new base::FundamentalValue(true), | |
187 NULL); | |
188 UpdateChromePolicy(policies); | 186 UpdateChromePolicy(policies); |
189 | 187 |
190 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); | 188 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); |
191 | 189 |
192 SetBooleanPrefValueFromLocal(prefs::kShowHomeButton, false); | 190 SetBooleanPrefValueFromLocal(prefs::kShowHomeButton, false); |
193 EXPECT_FALSE(observer.has_been_notified); | 191 EXPECT_FALSE(observer.has_been_notified); |
194 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); | 192 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); |
195 } | 193 } |
196 | 194 |
197 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, | 195 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, |
198 IgnoreSyncChangesToManagedPrefs) { | 196 IgnoreSyncChangesToManagedPrefs) { |
199 TestSyncedPrefObserver observer = {}; | 197 TestSyncedPrefObserver observer = {}; |
200 registrar()->Add(prefs::kShowHomeButton, | 198 registrar()->Add(prefs::kShowHomeButton, |
201 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); | 199 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); |
202 | 200 |
203 policy::PolicyMap policies; | 201 policy::PolicyMap policies; |
204 policies.Set(policy::key::kShowHomeButton, | 202 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, |
205 policy::POLICY_LEVEL_MANDATORY, | 203 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
206 policy::POLICY_SCOPE_USER, | 204 base::WrapUnique(new base::FundamentalValue(true)), nullptr); |
207 policy::POLICY_SOURCE_CLOUD, | |
208 new base::FundamentalValue(true), | |
209 NULL); | |
210 UpdateChromePolicy(policies); | 205 UpdateChromePolicy(policies); |
211 | 206 |
212 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); | 207 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); |
213 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); | 208 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); |
214 EXPECT_FALSE(observer.has_been_notified); | 209 EXPECT_FALSE(observer.has_been_notified); |
215 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); | 210 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); |
216 } | 211 } |
OLD | NEW |